diff options
Diffstat (limited to 'pjlib')
-rw-r--r-- | pjlib/include/pj/compat/socket.h | 1 | ||||
-rw-r--r-- | pjlib/include/pj/sock.h | 35 | ||||
-rw-r--r-- | pjlib/src/pj/addr_resolv_sock.c | 18 | ||||
-rw-r--r-- | pjlib/src/pj/addr_resolv_symbian.cpp | 2 | ||||
-rw-r--r-- | pjlib/src/pj/ioqueue_symbian.cpp | 4 | ||||
-rw-r--r-- | pjlib/src/pj/ip_helper_symbian.cpp | 7 | ||||
-rw-r--r-- | pjlib/src/pj/os_symbian.h | 8 | ||||
-rw-r--r-- | pjlib/src/pj/sock_common.c | 27 | ||||
-rw-r--r-- | pjlib/src/pj/sock_symbian.cpp | 4 |
9 files changed, 81 insertions, 25 deletions
diff --git a/pjlib/include/pj/compat/socket.h b/pjlib/include/pj/compat/socket.h index 989cda5d..b56b7885 100644 --- a/pjlib/include/pj/compat/socket.h +++ b/pjlib/include/pj/compat/socket.h @@ -68,6 +68,7 @@ # endif # undef s_addr +# define PJ_SOCK_HAS_GETADDRINFO 1 #endif /* _MSC_VER */ diff --git a/pjlib/include/pj/sock.h b/pjlib/include/pj/sock.h index 1d3b035c..4adfbd65 100644 --- a/pjlib/include/pj/sock.h +++ b/pjlib/include/pj/sock.h @@ -608,12 +608,32 @@ PJ_DECL(pj_status_t) pj_inet_pton(int af, const pj_str_t *src, void *dst); * enough to hold the text string (PJ_INET_ADDRSTRLEN characters * for IPv4, PJ_INET6_ADDRSTRLEN characters for IPv6). * - * @return PJ_SUCCESS if conversion was successful.. + * @return PJ_SUCCESS if conversion was successful. */ PJ_DECL(pj_status_t) pj_inet_ntop(int af, const void *src, char *dst, int size); /** + * Converts numeric address into its text string representation. + * + * @param af Specify the family of the address. This can be PJ_AF_INET + * or PJ_AF_INET6. + * @param src Points to a buffer holding an IPv4 address if the af argument + * is PJ_AF_INET, or an IPv6 address if the af argument is + * PJ_AF_INET6; the address must be in network byte order. + * @param dst Points to a buffer where the function stores the resulting + * text string; it shall not be NULL. + * @param size Specifies the size of this buffer, which shall be large + * enough to hold the text string (PJ_INET_ADDRSTRLEN characters + * for IPv4, PJ_INET6_ADDRSTRLEN characters for IPv6). + * + * @return The address string or NULL if failed. + */ +PJ_DECL(char*) pj_inet_ntop2(int af, const void *src, + char *dst, int size); + + +/** * Convert address string with numbers and dots to binary IP address. * * @param cp The IP address in numbers and dots notation. @@ -707,11 +727,22 @@ PJ_DECL(pj_bool_t) pj_sockaddr_has_addr(const pj_sockaddr_t *addr); * * @param addr Socket address. * - * @return Port number, in host byte order. + * @return Length in bytes. */ PJ_DECL(unsigned) pj_sockaddr_get_addr_len(const pj_sockaddr_t *addr); /** + * Get the socket address length, based on its address + * family. For PJ_AF_INET, the length will be sizeof(pj_sockaddr_in), and + * for PJ_AF_INET6, the length will be sizeof(pj_sockaddr_in6). + * + * @param addr Socket address. + * + * @return Length in bytes. + */ +PJ_DECL(unsigned) pj_sockaddr_get_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. * diff --git a/pjlib/src/pj/addr_resolv_sock.c b/pjlib/src/pj/addr_resolv_sock.c index aeb61951..997b7bd4 100644 --- a/pjlib/src/pj/addr_resolv_sock.c +++ b/pjlib/src/pj/addr_resolv_sock.c @@ -61,7 +61,7 @@ PJ_DEF(pj_status_t) pj_getaddrinfo(int af, const pj_str_t *nodename, { #if defined(PJ_SOCK_HAS_GETADDRINFO) && PJ_SOCK_HAS_GETADDRINFO!=0 char nodecopy[PJ_MAX_HOSTNAME]; - struct addrinfo hint, *res; + struct addrinfo hint, *res, *orig_res; unsigned i; int rc; @@ -84,18 +84,22 @@ PJ_DEF(pj_status_t) pj_getaddrinfo(int af, const pj_str_t *nodename, if (rc != 0) return PJ_ERESOLVE; + orig_res = res; + /* Enumerate each item in the result */ for (i=0; i<*count && res; res=res->ai_next) { - int len; - /* Ignore unwanted address families */ if (af!=PJ_AF_UNSPEC && res->ai_family != af) continue; /* Store canonical name (possibly truncating the name) */ - pj_ansi_strncpy(ai[i].ai_canonname, res->ai_canonname, - sizeof(ai[i].ai_canonname)); - ai[i].ai_canonname[sizeof(ai[i].ai_canonname)-1] = '\0'; + if (res->ai_canonname) { + pj_ansi_strncpy(ai[i].ai_canonname, res->ai_canonname, + sizeof(ai[i].ai_canonname)); + ai[i].ai_canonname[sizeof(ai[i].ai_canonname)-1] = '\0'; + } else { + pj_ansi_strcpy(ai[i].ai_canonname, nodecopy); + } /* Store address */ PJ_ASSERT_ON_FAIL(res->ai_addrlen <= sizeof(pj_sockaddr), continue); @@ -107,6 +111,8 @@ PJ_DEF(pj_status_t) pj_getaddrinfo(int af, const pj_str_t *nodename, *count = i; + freeaddrinfo(orig_res); + /* Done */ return PJ_SUCCESS; diff --git a/pjlib/src/pj/addr_resolv_symbian.cpp b/pjlib/src/pj/addr_resolv_symbian.cpp index d2bc6366..d3698b51 100644 --- a/pjlib/src/pj/addr_resolv_symbian.cpp +++ b/pjlib/src/pj/addr_resolv_symbian.cpp @@ -91,7 +91,7 @@ static pj_status_t getaddrinfo_by_af(int af, const pj_str_t *name, int addrlen; // Ignore if this is not the same address family - if (inetAddr.Family() != af) { + if (inetAddr.Family() != (unsigned)af) { resv.Next(nameEntry, reqStatus); User::WaitForRequest(reqStatus); continue; diff --git a/pjlib/src/pj/ioqueue_symbian.cpp b/pjlib/src/pj/ioqueue_symbian.cpp index d7aa9d6a..71d7de7f 100644 --- a/pjlib/src/pj/ioqueue_symbian.cpp +++ b/pjlib/src/pj/ioqueue_symbian.cpp @@ -701,9 +701,9 @@ PJ_DEF(pj_status_t) pj_ioqueue_recvfrom( pj_ioqueue_key_t *key, if (addr || addrlen) { PJ_ASSERT_RETURN(addr && addrlen && *addrlen, PJ_EINVAL); if (sock->GetAf() == PJ_AF_INET) { - PJ_ASSERT_RETURN(*addrlen >= sizeof(pj_sockaddr_in), PJ_EINVAL); + PJ_ASSERT_RETURN(*addrlen>=(int)sizeof(pj_sockaddr_in), PJ_EINVAL); } else if (sock->GetAf() == PJ_AF_INET6) { - PJ_ASSERT_RETURN(*addrlen >= sizeof(pj_sockaddr_in6), PJ_EINVAL); + PJ_ASSERT_RETURN(*addrlen>=(int)sizeof(pj_sockaddr_in6), PJ_EINVAL); } } diff --git a/pjlib/src/pj/ip_helper_symbian.cpp b/pjlib/src/pj/ip_helper_symbian.cpp index 3cd2ebfd..44b8012c 100644 --- a/pjlib/src/pj/ip_helper_symbian.cpp +++ b/pjlib/src/pj/ip_helper_symbian.cpp @@ -59,7 +59,7 @@ static pj_status_t rsock_enum_interface(int af, TInetAddr &iAddress = info().iAddress; int namelen; - if (iAddress.Family() != af) { + if (iAddress.Family() != (unsigned)af) { continue; } @@ -76,11 +76,6 @@ static pj_status_t rsock_enum_interface(int af, *p_cnt = i; return PJ_SUCCESS; - -on_error: - rSock.Close(); - *p_cnt = 0; - return PJ_RETURN_OS_ERROR(rc); } /* diff --git a/pjlib/src/pj/os_symbian.h b/pjlib/src/pj/os_symbian.h index f564075f..8fe4783d 100644 --- a/pjlib/src/pj/os_symbian.h +++ b/pjlib/src/pj/os_symbian.h @@ -244,12 +244,12 @@ public: pj_bzero(&pj_addr, sizeof(pj_sockaddr)); pj_addr.addr.sa_family = (pj_uint16_t)sym_addr.Family(); if (pj_addr.addr.sa_family == PJ_AF_INET) { - PJ_ASSERT_RETURN(*addr_len >= sizeof(pj_sockaddr_in), PJ_ETOOSMALL); + PJ_ASSERT_RETURN(*addr_len>=(int)sizeof(pj_sockaddr_in), PJ_ETOOSMALL); pj_addr.ipv4.sin_addr.s_addr = pj_htonl(sym_addr.Address()); pj_addr.ipv4.sin_port = pj_htons((pj_uint16_t) sym_addr.Port()); *addr_len = sizeof(pj_sockaddr_in); } else if (pj_addr.addr.sa_family == PJ_AF_INET6) { - PJ_ASSERT_RETURN(*addr_len >= sizeof(pj_sockaddr_in6), PJ_ETOOSMALL); + PJ_ASSERT_RETURN(*addr_len>=(int)sizeof(pj_sockaddr_in6), PJ_ETOOSMALL); const TIp6Addr & ip6 = sym_addr.Ip6Address(); pj_memcpy(&pj_addr.ipv6.sin6_addr, ip6.u.iAddr8, 16); pj_addr.ipv6.sin6_port = pj_htons((pj_uint16_t) sym_addr.Port()); @@ -271,14 +271,14 @@ public: TInetAddr & sym_addr) { if (pj_addr.addr.sa_family == PJ_AF_INET) { - PJ_ASSERT_RETURN(addrlen >= sizeof(pj_sockaddr_in), PJ_EINVAL); + PJ_ASSERT_RETURN(addrlen >= (int)sizeof(pj_sockaddr_in), PJ_EINVAL); sym_addr.Init(KAfInet); sym_addr.SetAddress((TUint32)pj_ntohl(pj_addr.ipv4.sin_addr.s_addr)); sym_addr.SetPort(pj_ntohs(pj_addr.ipv4.sin_port)); } else if (pj_addr.addr.sa_family == PJ_AF_INET6) { TIp6Addr ip6; - PJ_ASSERT_RETURN(addrlen >= sizeof(pj_sockaddr_in6), PJ_EINVAL); + PJ_ASSERT_RETURN(addrlen>=(int)sizeof(pj_sockaddr_in6), PJ_EINVAL); pj_memcpy(ip6.u.iAddr8, &pj_addr.ipv6.sin6_addr, 16); sym_addr.Init(KAfInet6); sym_addr.SetAddress(ip6); diff --git a/pjlib/src/pj/sock_common.c b/pjlib/src/pj/sock_common.c index 06aa9411..1c108336 100644 --- a/pjlib/src/pj/sock_common.c +++ b/pjlib/src/pj/sock_common.c @@ -47,6 +47,18 @@ PJ_DEF(pj_in_addr) pj_inet_addr2(const char *cp) } /* + * Get text representation. + */ +PJ_DEF(char*) pj_inet_ntop2( int af, const void *src, + char *dst, int size) +{ + pj_status_t status; + + status = pj_inet_ntop(af, src, dst, size); + return (status==PJ_SUCCESS)? dst : NULL; +} + +/* * Set the IP address of an IP socket address from string address, * with resolving the host if necessary. The string address may be in a * standard numbers and dots notation or may be a hostname. If hostname @@ -253,6 +265,18 @@ PJ_DEF(unsigned) pj_sockaddr_get_addr_len(const pj_sockaddr_t *addr) } /* + * Get socket address length. + */ +PJ_DEF(unsigned) pj_sockaddr_get_len(const pj_sockaddr_t *addr) +{ + const pj_sockaddr *a = (const pj_sockaddr*) addr; + PJ_ASSERT_RETURN(a->addr.sa_family == PJ_AF_INET || + a->addr.sa_family == PJ_AF_INET6, PJ_EAFNOTSUP); + return a->addr.sa_family == PJ_AF_INET6 ? + sizeof(pj_sockaddr_in6) : sizeof(pj_sockaddr_in); +} + +/* * Set port number of pj_sockaddr_in */ PJ_DEF(void) pj_sockaddr_in_set_port(pj_sockaddr_in *addr, @@ -269,8 +293,7 @@ PJ_DEF(pj_status_t) pj_sockaddr_set_port(pj_sockaddr *addr, { int af = addr->addr.sa_family; - PJ_ASSERT_ON_FAIL(af == PJ_AF_INET || af == PJ_AF_INET6, - PJ_EINVAL); + PJ_ASSERT_RETURN(af==PJ_AF_INET || af==PJ_AF_INET6, PJ_EINVAL); if (af == PJ_AF_INET6) addr->ipv6.sin6_port = pj_htons(hostport); diff --git a/pjlib/src/pj/sock_symbian.cpp b/pjlib/src/pj/sock_symbian.cpp index 90044a35..f53f657e 100644 --- a/pjlib/src/pj/sock_symbian.cpp +++ b/pjlib/src/pj/sock_symbian.cpp @@ -524,7 +524,7 @@ PJ_DEF(pj_status_t) pj_sock_bind( pj_sock_t sock, PJ_CHECK_STACK(); PJ_ASSERT_RETURN(sock != 0, PJ_EINVAL); - PJ_ASSERT_RETURN(addr && len >= sizeof(pj_sockaddr_in), PJ_EINVAL); + PJ_ASSERT_RETURN(addr && len>=(int)sizeof(pj_sockaddr_in), PJ_EINVAL); // Convert PJLIB's pj_sockaddr into Symbian's TInetAddr TInetAddr inetAddr; @@ -675,7 +675,7 @@ PJ_DEF(pj_status_t) pj_sock_sendto(pj_sock_t sock, RSocket &rSock = pjSock->Socket(); // Only supports AF_INET for now - PJ_ASSERT_RETURN(tolen >= sizeof(pj_sockaddr_in), PJ_EINVAL); + PJ_ASSERT_RETURN(tolen>=(int)sizeof(pj_sockaddr_in), PJ_EINVAL); TInetAddr inetAddr; status = PjSymbianOS::pj2Addr(*(pj_sockaddr*)to, tolen, inetAddr); |