From 2e6a62f43b622320d69971cfc07a68ab59e29f1b Mon Sep 17 00:00:00 2001 From: Benny Prijono Date: Sat, 1 Dec 2007 08:52:57 +0000 Subject: More ticket #415: more IPv6 and some reorganization of the source codes git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@1601 74dad513-b988-da41-8d7b-12977e46ad98 --- pjlib/include/pj/addr_resolv.h | 37 ++-- pjlib/include/pj/compat/socket.h | 22 +++ pjlib/include/pj/errno.h | 5 + pjlib/include/pj/ip_helper.h | 16 +- pjlib/include/pj/os.h | 7 + pjlib/include/pj/sock.h | 354 ++++++++++++++++++++++++++++----------- 6 files changed, 333 insertions(+), 108 deletions(-) (limited to 'pjlib/include/pj') diff --git a/pjlib/include/pj/addr_resolv.h b/pjlib/include/pj/addr_resolv.h index b066bc95..cad82730 100644 --- a/pjlib/include/pj/addr_resolv.h +++ b/pjlib/include/pj/addr_resolv.h @@ -85,9 +85,14 @@ typedef struct pj_addrinfo /** * This function fills the structure of type pj_hostent for a given host name. + * For host resolution function that also works with IPv6, please see + * #pj_getaddrinfo(). * - * @param name Host name, or IPv4 or IPv6 address in standard dot notation. - * @param he The pj_hostent structure to be filled. + * @param name Host name, or IPv4 address in standard dot notation. + * @param he The pj_hostent structure to be filled. Note that + * the pointers in this structure points to temporary + * variables which value will be reset upon subsequent + * invocation. * * @return PJ_SUCCESS, or the appropriate error codes. */ @@ -97,24 +102,33 @@ PJ_DECL(pj_status_t) pj_gethostbyname(const pj_str_t *name, pj_hostent *he); /** * Resolve the primary IP address of local host. * - * @param ip_addr On successful resolution, this will be filled up with - * the host IP address, in network byte order. + * @param af The desired address family to query. Valid values + * are pj_AF_INET() or pj_AF_INET6(). + * @param addr On successful resolution, the address family and address + * part of this socket address will be filled up with the host + * IP address, in network byte order. Other parts of the socket + * address are untouched. * * @return PJ_SUCCESS on success, or the appropriate error code. */ -PJ_DECL(pj_status_t) pj_gethostip(pj_in_addr *ip_addr); +PJ_DECL(pj_status_t) pj_gethostip(int af, pj_sockaddr *addr); /** * Get the IP address of the default interface. Default interface is the * interface of the default route. * - * @param ip_addr On successful resolution, this will be filled up with - * the IP address, in network byte order. + * @param af The desired address family to query. Valid values + * are pj_AF_INET() or pj_AF_INET6(). + * @param addr On successful resolution, the address family and address + * part of this socket address will be filled up with the host + * IP address, in network byte order. Other parts of the socket + * address are untouched. * * @return PJ_SUCCESS on success, or the appropriate error code. */ -PJ_DECL(pj_status_t) pj_getdefaultipinterface(pj_in_addr *ip_addr); +PJ_DECL(pj_status_t) pj_getdefaultipinterface(int af, + pj_sockaddr *addr); /** @@ -123,17 +137,20 @@ PJ_DECL(pj_status_t) pj_getdefaultipinterface(pj_in_addr *ip_addr); * to be used in creating a socket with which to address the specified * service. * + * @param af The desired address family to query. Valid values + * are pj_AF_INET(), pj_AF_INET6(), or pj_AF_UNSPEC(). * @param name Descriptive name or an address string, such as host * name. - * @param af The desired address family to query. * @param count On input, it specifies the number of elements in * \a ai array. On output, this will be set with the * number of address informations found for the * specified name. + * @param ai Array of address info to be filled with the information + * about the host. * * @return PJ_SUCCESS on success, or the appropriate error code. */ -PJ_DECL(pj_status_t) pj_getaddrinfo(const pj_str_t *nodename, int af, +PJ_DECL(pj_status_t) pj_getaddrinfo(int af, const pj_str_t *name, unsigned *count, pj_addrinfo ai[]); diff --git a/pjlib/include/pj/compat/socket.h b/pjlib/include/pj/compat/socket.h index f44a623c..989cda5d 100644 --- a/pjlib/include/pj/compat/socket.h +++ b/pjlib/include/pj/compat/socket.h @@ -185,6 +185,28 @@ typedef int socklen_t; #endif +/* Regarding sin_len member of sockaddr_in: + * BSD systems (including MacOS X requires that the sin_len member of + * sockaddr_in be set to sizeof(sockaddr_in), while other systems (Windows + * and Linux included) do not. + * + * To maintain compatibility between systems, PJLIB will automatically + * set this field before invoking native OS socket API, and it will + * always reset the field to zero before returning pj_sockaddr_in to + * application (such as in pj_getsockname() and pj_recvfrom()). + * + * Application MUST always set this field to zero. + * + * This way we can avoid hard to find problem such as when the socket + * address is used as hash table key. + */ +#if defined(PJ_SOCKADDR_HAS_LEN) && PJ_SOCKADDR_HAS_LEN!=0 +# define PJ_SOCKADDR_SET_LEN(addr,len) (((pj_addr_hdr*)(addr))->sa_zero_len=(len)) +# define PJ_SOCKADDR_RESET_LEN(addr) (((pj_addr_hdr*)(addr))->sa_zero_len=0) +#else +# define PJ_SOCKADDR_SET_LEN(addr,len) +# define PJ_SOCKADDR_RESET_LEN(addr) +#endif #endif /* __PJ_COMPAT_SOCKET_H__ */ diff --git a/pjlib/include/pj/errno.h b/pjlib/include/pj/errno.h index 507bd7b8..b838f069 100644 --- a/pjlib/include/pj/errno.h +++ b/pjlib/include/pj/errno.h @@ -314,6 +314,11 @@ PJ_DECL(pj_status_t) pj_register_strerror(pj_status_t start_code, * IPv6 is not supported */ #define PJ_EIPV6NOTSUP (PJ_ERRNO_START_STATUS + 21)/* 70021 */ +/** + * @hideinitializer + * Unsupported address family + */ +#define PJ_EAFNOTSUP (PJ_ERRNO_START_STATUS + 22)/* 70022 */ /** @} */ /* pj_errnum */ diff --git a/pjlib/include/pj/ip_helper.h b/pjlib/include/pj/ip_helper.h index 9515d978..266a785a 100644 --- a/pjlib/include/pj/ip_helper.h +++ b/pjlib/include/pj/ip_helper.h @@ -53,16 +53,24 @@ typedef union pj_ip_route_entry /** - * Enumerate the local IP interface currently active in the host. + * Enumerate the local IP interfaces currently active in the host. * + * @param af Family of the address to be retrieved. Application + * may specify pj_AF_UNSPEC() to retrieve all addresses, + * or pj_AF_INET() or pj_AF_INET6() to retrieve interfaces + * with specific address family. * @param count On input, specify the number of entries. On output, * it will be filled with the actual number of entries. - * @param ifs Array of IP addresses. + * @param ifs Array of socket addresses, which address part will + * be filled with the interface address. The address + * family part will be initialized with the address + * family of the IP address. * * @return PJ_SUCCESS on success, or the appropriate error code. */ -PJ_DECL(pj_status_t) pj_enum_ip_interface(unsigned *count, - pj_in_addr ifs[]); +PJ_DECL(pj_status_t) pj_enum_ip_interface(int af, + unsigned *count, + pj_sockaddr ifs[]); /** diff --git a/pjlib/include/pj/os.h b/pjlib/include/pj/os.h index f640df21..a5c10df8 100644 --- a/pjlib/include/pj/os.h +++ b/pjlib/include/pj/os.h @@ -334,6 +334,13 @@ typedef struct pj_symbianos_params */ void *rhostresolver; + /** + * Optional RHostResolver for IPv6 instance to be used by PJLIB. + * If this value is NULL, a new RHostResolver instance will be created + * when pj_init() is called. + */ + void *rhostresolver6; + } pj_symbianos_params; /** diff --git a/pjlib/include/pj/sock.h b/pjlib/include/pj/sock.h index d90c91e8..1d3b035c 100644 --- a/pjlib/include/pj/sock.h +++ b/pjlib/include/pj/sock.h @@ -87,18 +87,36 @@ extern const pj_uint16_t PJ_AF_IRDA; * global variables from a DLL. */ -/** Get #PJ_AF_UNSPEC value */ -PJ_DECL(pj_uint16_t) pj_AF_UNSPEC(void); -/** Get #PJ_AF_UNIX value. */ -PJ_DECL(pj_uint16_t) pj_AF_UNIX(void); -/** Get #PJ_AF_INET value. */ -PJ_DECL(pj_uint16_t) pj_AF_INET(void); -/** Get #PJ_AF_INET6 value. */ -PJ_DECL(pj_uint16_t) pj_AF_INET6(void); -/** Get #PJ_AF_PACKET value. */ -PJ_DECL(pj_uint16_t) pj_AF_PACKET(void); -/** Get #PJ_AF_IRDA value. */ -PJ_DECL(pj_uint16_t) pj_AF_IRDA(void); +#if defined(PJ_DLL) + /** Get #PJ_AF_UNSPEC value */ + PJ_DECL(pj_uint16_t) pj_AF_UNSPEC(void); + /** Get #PJ_AF_UNIX value. */ + PJ_DECL(pj_uint16_t) pj_AF_UNIX(void); + /** Get #PJ_AF_INET value. */ + PJ_DECL(pj_uint16_t) pj_AF_INET(void); + /** Get #PJ_AF_INET6 value. */ + PJ_DECL(pj_uint16_t) pj_AF_INET6(void); + /** Get #PJ_AF_PACKET value. */ + PJ_DECL(pj_uint16_t) pj_AF_PACKET(void); + /** Get #PJ_AF_IRDA value. */ + PJ_DECL(pj_uint16_t) pj_AF_IRDA(void); +#else + /* When pjlib is not built as DLL, these accessor functions are + * simply a macro to get their constants + */ + /** Get #PJ_AF_UNSPEC value */ +# define pj_AF_UNSPEC() PJ_AF_UNSPEC + /** Get #PJ_AF_UNIX value. */ +# define pj_AF_UNIX() PJ_AF_UNIX + /** Get #PJ_AF_INET value. */ +# define pj_AF_INET() PJ_AF_INET + /** Get #PJ_AF_INET6 value. */ +# define pj_AF_INET6() PJ_AF_INET6 + /** Get #PJ_AF_PACKET value. */ +# define pj_AF_PACKET() PJ_AF_PACKET + /** Get #PJ_AF_IRDA value. */ +# define pj_AF_IRDA() PJ_AF_IRDA +#endif /** @@ -127,14 +145,25 @@ extern const pj_uint16_t PJ_SOCK_RDM; * because Symbian doesn't allow exporting global variables from a DLL. */ -/** Get #PJ_SOCK_STREAM constant */ -PJ_DECL(int) pj_SOCK_STREAM(void); -/** Get #PJ_SOCK_DGRAM constant */ -PJ_DECL(int) pj_SOCK_DGRAM(void); -/** Get #PJ_SOCK_RAW constant */ -PJ_DECL(int) pj_SOCK_RAW(void); -/** Get #PJ_SOCK_RDM constant */ -PJ_DECL(int) pj_SOCK_RDM(void); +#if defined(PJ_DLL) + /** Get #PJ_SOCK_STREAM constant */ + PJ_DECL(int) pj_SOCK_STREAM(void); + /** Get #PJ_SOCK_DGRAM constant */ + PJ_DECL(int) pj_SOCK_DGRAM(void); + /** Get #PJ_SOCK_RAW constant */ + PJ_DECL(int) pj_SOCK_RAW(void); + /** Get #PJ_SOCK_RDM constant */ + PJ_DECL(int) pj_SOCK_RDM(void); +#else + /** Get #PJ_SOCK_STREAM constant */ +# define pj_SOCK_STREAM() PJ_SOCK_STREAM + /** Get #PJ_SOCK_DGRAM constant */ +# define pj_SOCK_DGRAM() PJ_SOCK_DGRAM + /** Get #PJ_SOCK_RAW constant */ +# define pj_SOCK_RAW() PJ_SOCK_RAW + /** Get #PJ_SOCK_RDM constant */ +# define pj_SOCK_RDM() PJ_SOCK_RDM +#endif /** @@ -158,16 +187,29 @@ extern const pj_uint16_t PJ_SOL_IPV6; * because Symbian doesn't allow exporting global variables from a DLL. */ -/** Get #PJ_SOL_SOCKET constant */ -PJ_DECL(pj_uint16_t) pj_SOL_SOCKET(void); -/** Get #PJ_SOL_IP constant */ -PJ_DECL(pj_uint16_t) pj_SOL_IP(void); -/** Get #PJ_SOL_TCP constant */ -PJ_DECL(pj_uint16_t) pj_SOL_TCP(void); -/** Get #PJ_SOL_UDP constant */ -PJ_DECL(pj_uint16_t) pj_SOL_UDP(void); -/** Get #PJ_SOL_IPV6 constant */ -PJ_DECL(pj_uint16_t) pj_SOL_IPV6(void); +#if defined(PJ_DLL) + /** Get #PJ_SOL_SOCKET constant */ + PJ_DECL(pj_uint16_t) pj_SOL_SOCKET(void); + /** Get #PJ_SOL_IP constant */ + PJ_DECL(pj_uint16_t) pj_SOL_IP(void); + /** Get #PJ_SOL_TCP constant */ + PJ_DECL(pj_uint16_t) pj_SOL_TCP(void); + /** Get #PJ_SOL_UDP constant */ + PJ_DECL(pj_uint16_t) pj_SOL_UDP(void); + /** Get #PJ_SOL_IPV6 constant */ + PJ_DECL(pj_uint16_t) pj_SOL_IPV6(void); +#else + /** Get #PJ_SOL_SOCKET constant */ +# define pj_SOL_SOCKET() PJ_SOL_SOCKET + /** Get #PJ_SOL_IP constant */ +# define pj_SOL_IP() PJ_SOL_IP + /** Get #PJ_SOL_TCP constant */ +# define pj_SOL_TCP() PJ_SOL_TCP + /** Get #PJ_SOL_UDP constant */ +# define pj_SOL_UDP() PJ_SOL_UDP + /** Get #PJ_SOL_IPV6 constant */ +# define pj_SOL_IPV6() PJ_SOL_IPV6 +#endif /* IP_TOS @@ -179,9 +221,6 @@ PJ_DECL(pj_uint16_t) pj_SOL_IPV6(void); /** IP_TOS optname in setsockopt(). @see pj_IP_TOS() */ extern const pj_uint16_t PJ_IP_TOS; -/** Get #PJ_IP_TOS constant */ -PJ_DECL(int) pj_IP_TOS(void); - /* * IP TOS related constats. * @@ -203,17 +242,37 @@ extern const pj_uint16_t PJ_IPTOS_RELIABILITY; extern const pj_uint16_t PJ_IPTOS_MINCOST; -/** Get #PJ_IPTOS_LOWDELAY constant */ -PJ_DECL(int) pj_IPTOS_LOWDELAY(void); +#if defined(PJ_DLL) + /** Get #PJ_IP_TOS constant */ + PJ_DECL(int) pj_IP_TOS(void); -/** Get #PJ_IPTOS_THROUGHPUT constant */ -PJ_DECL(int) pj_IPTOS_THROUGHPUT(void); + /** Get #PJ_IPTOS_LOWDELAY constant */ + PJ_DECL(int) pj_IPTOS_LOWDELAY(void); -/** Get #PJ_IPTOS_RELIABILITY constant */ -PJ_DECL(int) pj_IPTOS_RELIABILITY(void); + /** Get #PJ_IPTOS_THROUGHPUT constant */ + PJ_DECL(int) pj_IPTOS_THROUGHPUT(void); -/** Get #PJ_IPTOS_MINCOST constant */ -PJ_DECL(int) pj_IPTOS_MINCOST(void); + /** Get #PJ_IPTOS_RELIABILITY constant */ + PJ_DECL(int) pj_IPTOS_RELIABILITY(void); + + /** Get #PJ_IPTOS_MINCOST constant */ + PJ_DECL(int) pj_IPTOS_MINCOST(void); +#else + /** Get #PJ_IP_TOS constant */ +# define pj_IP_TOS() PJ_IP_TOS + + /** Get #PJ_IPTOS_LOWDELAY constant */ +# define pj_IPTOS_LOWDELAY() PJ_IP_TOS_LOWDELAY + + /** Get #PJ_IPTOS_THROUGHPUT constant */ +# define pj_IPTOS_THROUGHPUT() PJ_IP_TOS_THROUGHPUT + + /** Get #PJ_IPTOS_RELIABILITY constant */ +# define pj_IPTOS_RELIABILITY() PJ_IP_TOS_RELIABILITY + + /** Get #PJ_IPTOS_MINCOST constant */ +# define pj_IPTOS_MINCOST() PJ_IP_TOS_MINCOST +#endif /** @@ -231,14 +290,25 @@ extern const pj_uint16_t PJ_SO_RCVBUF; extern const pj_uint16_t PJ_SO_SNDBUF; -/** Get #PJ_SO_TYPE constant */ -PJ_DECL(pj_uint16_t) pj_SO_TYPE(void); +#if defined(PJ_DLL) + /** Get #PJ_SO_TYPE constant */ + PJ_DECL(pj_uint16_t) pj_SO_TYPE(void); -/** Get #PJ_SO_RCVBUF constant */ -PJ_DECL(pj_uint16_t) pj_SO_RCVBUF(void); + /** Get #PJ_SO_RCVBUF constant */ + PJ_DECL(pj_uint16_t) pj_SO_RCVBUF(void); -/** Get #PJ_SO_SNDBUF constant */ -PJ_DECL(pj_uint16_t) pj_SO_SNDBUF(void); + /** Get #PJ_SO_SNDBUF constant */ + PJ_DECL(pj_uint16_t) pj_SO_SNDBUF(void); +#else + /** Get #PJ_SO_TYPE constant */ +# define pj_SO_TYPE() PJ_SO_TYPE + + /** Get #PJ_SO_RCVBUF constant */ +# define pj_SO_RCVBUF() PJ_SO_RCVBUF + + /** Get #PJ_SO_SNDBUF constant */ +# define pj_SO_SNDBUF() PJ_SO_SNDBUF +#endif /* @@ -255,14 +325,25 @@ extern const int PJ_MSG_PEEK; extern const int PJ_MSG_DONTROUTE; -/** Get #PJ_MSG_OOB constant */ -PJ_DECL(int) pj_MSG_OOB(void); +#if defined(PJ_DLL) + /** Get #PJ_MSG_OOB constant */ + PJ_DECL(int) pj_MSG_OOB(void); -/** Get #PJ_MSG_PEEK constant */ -PJ_DECL(int) pj_MSG_PEEK(void); + /** Get #PJ_MSG_PEEK constant */ + PJ_DECL(int) pj_MSG_PEEK(void); -/** Get #PJ_MSG_DONTROUTE constant */ -PJ_DECL(int) pj_MSG_DONTROUTE(void); + /** Get #PJ_MSG_DONTROUTE constant */ + PJ_DECL(int) pj_MSG_DONTROUTE(void); +#else + /** Get #PJ_MSG_OOB constant */ +# define pj_MSG_OOB() PJ_MSG_OOB + + /** Get #PJ_MSG_PEEK constant */ +# define pj_MSG_PEEK() PJ_MSG_PEEK + + /** Get #PJ_MSG_DONTROUTE constant */ +# define pj_MSG_DONTROUTE() PJ_MSG_DONTROUTE +#endif /** @@ -306,6 +387,7 @@ typedef enum pj_socket_sd_type */ #define PJ_INVALID_SOCKET (-1) +/* Must undefine s_addr because of pj_in_addr below */ #undef s_addr /** @@ -362,7 +444,12 @@ typedef union pj_in6_addr /* While these are used for proper alignment */ pj_uint32_t u6_addr32[4]; -#if defined(PJ_HAS_INT64) && PJ_HAS_INT64!=0 + + /* Do not use this with Winsock2, as this will align pj_sockaddr_in6 + * to 64-bit boundary and Winsock2 doesn't like it! + */ +#if defined(PJ_HAS_INT64) && PJ_HAS_INT64!=0 && \ + (!defined(PJ_WIN32) || PJ_WIN32==0) pj_int64_t u6_addr64[2]; #endif @@ -555,54 +642,92 @@ PJ_DECL(pj_in_addr) pj_inet_addr(const pj_str_t *cp); PJ_DECL(pj_in_addr) pj_inet_addr2(const char *cp); /** - * Get the transport layer port number of an Internet socket address. - * The port is returned in host byte order. + * Initialize IPv4 socket address based on the address and port info. + * The string address may be in a standard numbers and dots notation or + * may be a hostname. If hostname is specified, then the function will + * resolve the host into the IP address. * - * @param addr The IP socket address. - * @return Port number, in host byte order. + * @see pj_sockaddr_init() + * + * @param addr The IP socket address to be set. + * @param cp The address string, which can be in a standard + * dotted numbers or a hostname to be resolved. + * @param port The port number, in host byte order. + * + * @return Zero on success. */ -PJ_INLINE(pj_uint16_t) pj_sockaddr_in_get_port(const pj_sockaddr_in *addr) -{ - return pj_ntohs(addr->sin_port); -} +PJ_DECL(pj_status_t) pj_sockaddr_in_init( pj_sockaddr_in *addr, + const pj_str_t *cp, + pj_uint16_t port); /** - * Set the port number of an Internet socket address. + * Initialize IP socket address based on the address and port info. + * The string address may be in a standard numbers and dots notation or + * may be a hostname. If hostname is specified, then the function will + * resolve the host into the IP address. * - * @param addr The IP socket address. - * @param hostport The port number, in host byte order. + * @see pj_sockaddr_in_init() + * + * @param af Internet address family. + * @param addr The IP socket address to be set. + * @param cp The address string, which can be in a standard + * dotted numbers or a hostname to be resolved. + * @param port The port number, in host byte order. + * + * @return Zero on success. */ -PJ_INLINE(void) pj_sockaddr_in_set_port(pj_sockaddr_in *addr, - pj_uint16_t hostport) -{ - addr->sin_port = pj_htons(hostport); -} +PJ_DECL(pj_status_t) pj_sockaddr_init(int af, + pj_sockaddr *addr, + const pj_str_t *cp, + pj_uint16_t port); /** - * Get the IP address of an Internet socket address. + * Get pointer to the address part of a socket address. + * + * @param addr Socket address. + * + * @return Pointer to address part (sin_addr or sin6_addr, + * depending on address family) + */ +PJ_DECL(void*) pj_sockaddr_get_addr(const pj_sockaddr_t *addr); + +/** + * Check that a socket address contains a non-zero address part. + * + * @param addr Socket address. + * + * @return Non-zero if address is set to non-zero. + */ +PJ_DECL(pj_bool_t) pj_sockaddr_has_addr(const pj_sockaddr_t *addr); + +/** + * Get the address part length of a socket address, based on its address + * family. For PJ_AF_INET, the length will be sizeof(pj_in_addr), and + * for PJ_AF_INET6, the length will be sizeof(pj_in6_addr). + * + * @param addr Socket address. + * + * @return Port number, in host byte order. + */ +PJ_DECL(unsigned) pj_sockaddr_get_addr_len(const pj_sockaddr_t *addr); + +/** + * Get the IP address of an IPv4 socket address. * The address is returned as 32bit value in host byte order. * * @param addr The IP socket address. * @return 32bit address, in host byte order. */ -PJ_INLINE(pj_in_addr) pj_sockaddr_in_get_addr(const pj_sockaddr_in *addr) -{ - pj_in_addr in_addr; - in_addr.s_addr = pj_ntohl(addr->sin_addr.s_addr); - return in_addr; -} +PJ_DECL(pj_in_addr) pj_sockaddr_in_get_addr(const pj_sockaddr_in *addr); /** - * Set the IP address of an Internet socket address. + * Set the IP address of an IPv4 socket address. * * @param addr The IP socket address. * @param hostaddr The host address, in host byte order. */ -PJ_INLINE(void) pj_sockaddr_in_set_addr(pj_sockaddr_in *addr, - pj_uint32_t hostaddr) -{ - addr->sin_addr.s_addr = pj_htonl(hostaddr); -} +PJ_DECL(void) pj_sockaddr_in_set_addr(pj_sockaddr_in *addr, + pj_uint32_t hostaddr); /** * Set the IP address of an IP socket address from string address, @@ -611,32 +736,73 @@ PJ_INLINE(void) pj_sockaddr_in_set_addr(pj_sockaddr_in *addr, * is specified, then the function will resolve the host into the IP * address. * + * @see pj_sockaddr_set_str_addr() + * * @param addr The IP socket address to be set. * @param cp The address string, which can be in a standard * dotted numbers or a hostname to be resolved. * - * @return Zero on success. + * @return PJ_SUCCESS on success. */ PJ_DECL(pj_status_t) pj_sockaddr_in_set_str_addr( pj_sockaddr_in *addr, const pj_str_t *cp); /** - * Set the IP address and port of an IP socket address. - * The string address may be in a standard numbers and dots notation or - * may be a hostname. If hostname is specified, then the function will - * resolve the host into the IP address. + * Set the IP address of an IPv4 or IPv6 socket address from string address, + * with resolving the host if necessary. The string address may be in a + * standard IPv6 or IPv6 address or may be a hostname. If hostname + * is specified, then the function will resolve the host into the IP + * address according to the address family. * + * @param af Address family. * @param addr The IP socket address to be set. * @param cp The address string, which can be in a standard - * dotted numbers or a hostname to be resolved. - * @param port The port number, in host byte order. + * IP numbers (IPv4 or IPv6) or a hostname to be resolved. * - * @return Zero on success. + * @return PJ_SUCCESS on success. */ -PJ_DECL(pj_status_t) pj_sockaddr_in_init( pj_sockaddr_in *addr, - const pj_str_t *cp, - pj_uint16_t port); +PJ_DECL(pj_status_t) pj_sockaddr_set_str_addr(int af, + pj_sockaddr *addr, + const pj_str_t *cp); + +/** + * Get the port number of a socket address, in host byte order. + * This function can be used for both IPv4 and IPv6 socket address. + * + * @param addr Socket address. + * + * @return Port number, in host byte order. + */ +PJ_DECL(pj_uint16_t) pj_sockaddr_get_port(const pj_sockaddr_t *addr); + +/** + * Get the transport layer port number of an Internet socket address. + * The port is returned in host byte order. + * + * @param addr The IP socket address. + * @return Port number, in host byte order. + */ +PJ_DECL(pj_uint16_t) pj_sockaddr_in_get_port(const pj_sockaddr_in *addr); + +/** + * Set the port number of an Internet socket address. + * + * @param addr The socket address. + * @param hostport The port number, in host byte order. + */ +PJ_DECL(pj_status_t) pj_sockaddr_set_port(pj_sockaddr *addr, + pj_uint16_t hostport); +/** + * Set the port number of an IPv4 socket address. + * + * @see pj_sockaddr_set_port() + * + * @param addr The IP socket address. + * @param hostport The port number, in host byte order. + */ +PJ_DECL(void) pj_sockaddr_in_set_port(pj_sockaddr_in *addr, + pj_uint16_t hostport); /***************************************************************************** * -- cgit v1.2.3