3 * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
4 * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include <pj/assert.h>
23 #include <pj/string.h>
24 #include <pj/compat/socket.h>
25 #include <pj/addr_resolv.h>
27 #include <pj/unicode.h>
30 * Address families conversion.
31 * The values here are indexed based on pj_addr_family.
33 const pj_uint16_t PJ_AF_UNSPEC = AF_UNSPEC;
34 const pj_uint16_t PJ_AF_UNIX = AF_UNIX;
35 const pj_uint16_t PJ_AF_INET = AF_INET;
36 const pj_uint16_t PJ_AF_INET6 = AF_INET6;
38 const pj_uint16_t PJ_AF_PACKET = AF_PACKET;
40 const pj_uint16_t PJ_AF_PACKET = 0xFFFF;
43 const pj_uint16_t PJ_AF_IRDA = AF_IRDA;
45 const pj_uint16_t PJ_AF_IRDA = 0xFFFF;
49 * Socket types conversion.
50 * The values here are indexed based on pj_sock_type
52 const pj_uint16_t PJ_SOCK_STREAM= SOCK_STREAM;
53 const pj_uint16_t PJ_SOCK_DGRAM = SOCK_DGRAM;
54 const pj_uint16_t PJ_SOCK_RAW = SOCK_RAW;
55 const pj_uint16_t PJ_SOCK_RDM = SOCK_RDM;
58 * Socket level values.
60 const pj_uint16_t PJ_SOL_SOCKET = SOL_SOCKET;
62 const pj_uint16_t PJ_SOL_IP = SOL_IP;
63 #elif defined(PJ_WIN32) && PJ_WIN32
64 const pj_uint16_t PJ_SOL_IP = IPPROTO_IP;
66 const pj_uint16_t PJ_SOL_IP = 0;
70 const pj_uint16_t PJ_SOL_TCP = SOL_TCP;
71 #elif defined(IPPROTO_TCP)
72 const pj_uint16_t PJ_SOL_TCP = IPPROTO_TCP;
73 #elif defined(PJ_WIN32) && PJ_WIN32
74 const pj_uint16_t PJ_SOL_TCP = IPPROTO_TCP;
76 const pj_uint16_t PJ_SOL_TCP = 6;
80 const pj_uint16_t PJ_SOL_UDP = SOL_UDP;
81 #elif defined(IPPROTO_UDP)
82 const pj_uint16_t PJ_SOL_UDP = IPPROTO_UDP;
83 #elif defined(PJ_WIN32) && PJ_WIN32
84 const pj_uint16_t PJ_SOL_UDP = IPPROTO_UDP;
86 const pj_uint16_t PJ_SOL_UDP = 17;
90 const pj_uint16_t PJ_SOL_IPV6 = SOL_IPV6;
91 #elif defined(PJ_WIN32) && PJ_WIN32
92 # if defined(IPPROTO_IPV6) || (_WIN32_WINNT >= 0x0501)
93 const pj_uint16_t PJ_SOL_IPV6 = IPPROTO_IPV6;
95 const pj_uint16_t PJ_SOL_IPV6 = 41;
98 const pj_uint16_t PJ_SOL_IPV6 = 41;
103 const pj_uint16_t PJ_IP_TOS = IP_TOS;
105 const pj_uint16_t PJ_IP_TOS = 1;
109 /* TOS settings (declared in netinet/ip.h) */
110 #ifdef IPTOS_LOWDELAY
111 const pj_uint16_t PJ_IPTOS_LOWDELAY = IPTOS_LOWDELAY;
113 const pj_uint16_t PJ_IPTOS_LOWDELAY = 0x10;
115 #ifdef IPTOS_THROUGHPUT
116 const pj_uint16_t PJ_IPTOS_THROUGHPUT = IPTOS_THROUGHPUT;
118 const pj_uint16_t PJ_IPTOS_THROUGHPUT = 0x08;
120 #ifdef IPTOS_RELIABILITY
121 const pj_uint16_t PJ_IPTOS_RELIABILITY = IPTOS_RELIABILITY;
123 const pj_uint16_t PJ_IPTOS_RELIABILITY = 0x04;
126 const pj_uint16_t PJ_IPTOS_MINCOST = IPTOS_MINCOST;
128 const pj_uint16_t PJ_IPTOS_MINCOST = 0x02;
132 /* optname values. */
133 const pj_uint16_t PJ_SO_TYPE = SO_TYPE;
134 const pj_uint16_t PJ_SO_RCVBUF = SO_RCVBUF;
135 const pj_uint16_t PJ_SO_SNDBUF = SO_SNDBUF;
136 const pj_uint16_t PJ_TCP_NODELAY= TCP_NODELAY;
137 const pj_uint16_t PJ_SO_REUSEADDR= SO_REUSEADDR;
139 const pj_uint16_t PJ_SO_NOSIGPIPE = SO_NOSIGPIPE;
141 const pj_uint16_t PJ_SO_NOSIGPIPE = 0xFFFF;
143 #if defined(SO_PRIORITY)
144 const pj_uint16_t PJ_SO_PRIORITY = SO_PRIORITY;
146 /* This is from Linux, YMMV */
147 const pj_uint16_t PJ_SO_PRIORITY = 12;
150 /* Multicasting is not supported e.g. in PocketPC 2003 SDK */
151 #ifdef IP_MULTICAST_IF
152 const pj_uint16_t PJ_IP_MULTICAST_IF = IP_MULTICAST_IF;
153 const pj_uint16_t PJ_IP_MULTICAST_TTL = IP_MULTICAST_TTL;
154 const pj_uint16_t PJ_IP_MULTICAST_LOOP = IP_MULTICAST_LOOP;
155 const pj_uint16_t PJ_IP_ADD_MEMBERSHIP = IP_ADD_MEMBERSHIP;
156 const pj_uint16_t PJ_IP_DROP_MEMBERSHIP = IP_DROP_MEMBERSHIP;
158 const pj_uint16_t PJ_IP_MULTICAST_IF = 0xFFFF;
159 const pj_uint16_t PJ_IP_MULTICAST_TTL = 0xFFFF;
160 const pj_uint16_t PJ_IP_MULTICAST_LOOP = 0xFFFF;
161 const pj_uint16_t PJ_IP_ADD_MEMBERSHIP = 0xFFFF;
162 const pj_uint16_t PJ_IP_DROP_MEMBERSHIP = 0xFFFF;
165 /* recv() and send() flags */
166 const int PJ_MSG_OOB = MSG_OOB;
167 const int PJ_MSG_PEEK = MSG_PEEK;
168 const int PJ_MSG_DONTROUTE = MSG_DONTROUTE;
172 static void CHECK_ADDR_LEN(const pj_sockaddr *addr, int len)
174 pj_sockaddr *a = (pj_sockaddr*)addr;
175 pj_assert((a->addr.sa_family==PJ_AF_INET && len==sizeof(pj_sockaddr_in)) ||
176 (a->addr.sa_family==PJ_AF_INET6 && len==sizeof(pj_sockaddr_in6)));
180 #define CHECK_ADDR_LEN(addr,len)
184 * Convert 16-bit value from network byte order to host byte order.
186 PJ_DEF(pj_uint16_t) pj_ntohs(pj_uint16_t netshort)
188 return ntohs(netshort);
192 * Convert 16-bit value from host byte order to network byte order.
194 PJ_DEF(pj_uint16_t) pj_htons(pj_uint16_t hostshort)
196 return htons(hostshort);
200 * Convert 32-bit value from network byte order to host byte order.
202 PJ_DEF(pj_uint32_t) pj_ntohl(pj_uint32_t netlong)
204 return ntohl(netlong);
208 * Convert 32-bit value from host byte order to network byte order.
210 PJ_DEF(pj_uint32_t) pj_htonl(pj_uint32_t hostlong)
212 return htonl(hostlong);
216 * Convert an Internet host address given in network byte order
217 * to string in standard numbers and dots notation.
219 PJ_DEF(char*) pj_inet_ntoa(pj_in_addr inaddr)
221 #if !defined(PJ_LINUX) && !defined(PJ_LINUX_KERNEL)
222 return inet_ntoa(*(struct in_addr*)&inaddr);
225 addr.s_addr = inaddr.s_addr;
226 return inet_ntoa(addr);
231 * This function converts the Internet host address cp from the standard
232 * numbers-and-dots notation into binary data and stores it in the structure
233 * that inp points to.
235 PJ_DEF(int) pj_inet_aton(const pj_str_t *cp, struct pj_in_addr *inp)
237 char tempaddr[PJ_INET_ADDRSTRLEN];
239 /* Initialize output with PJ_INADDR_NONE.
240 * Some apps relies on this instead of the return value
241 * (and anyway the return value is quite confusing!)
243 inp->s_addr = PJ_INADDR_NONE;
246 * this function might be called with cp->slen >= 16
247 * (i.e. when called with hostname to check if it's an IP addr).
249 PJ_ASSERT_RETURN(cp && cp->slen && inp, 0);
250 if (cp->slen >= PJ_INET_ADDRSTRLEN) {
254 pj_memcpy(tempaddr, cp->ptr, cp->slen);
255 tempaddr[cp->slen] = '\0';
257 #if defined(PJ_SOCK_HAS_INET_ATON) && PJ_SOCK_HAS_INET_ATON != 0
258 return inet_aton(tempaddr, (struct in_addr*)inp);
260 inp->s_addr = inet_addr(tempaddr);
261 return inp->s_addr == PJ_INADDR_NONE ? 0 : 1;
266 * Convert text to IPv4/IPv6 address.
268 PJ_DEF(pj_status_t) pj_inet_pton(int af, const pj_str_t *src, void *dst)
270 char tempaddr[PJ_INET6_ADDRSTRLEN];
272 PJ_ASSERT_RETURN(af==PJ_AF_INET || af==PJ_AF_INET6, PJ_EAFNOTSUP);
273 PJ_ASSERT_RETURN(src && src->slen && dst, PJ_EINVAL);
275 /* Initialize output with PJ_IN_ADDR_NONE for IPv4 (to be
276 * compatible with pj_inet_aton()
278 if (af==PJ_AF_INET) {
279 ((pj_in_addr*)dst)->s_addr = PJ_INADDR_NONE;
283 * this function might be called with cp->slen >= 46
284 * (i.e. when called with hostname to check if it's an IP addr).
286 if (src->slen >= PJ_INET6_ADDRSTRLEN) {
287 return PJ_ENAMETOOLONG;
290 pj_memcpy(tempaddr, src->ptr, src->slen);
291 tempaddr[src->slen] = '\0';
293 #if defined(PJ_SOCK_HAS_INET_PTON) && PJ_SOCK_HAS_INET_PTON != 0
295 * Implementation using inet_pton()
297 if (inet_pton(af, tempaddr, dst) != 1) {
298 pj_status_t status = pj_get_netos_error();
299 if (status == PJ_SUCCESS)
300 status = PJ_EUNKNOWN;
307 #elif defined(PJ_WIN32) || defined(PJ_WIN32_WINCE)
309 * Implementation on Windows, using WSAStringToAddress().
310 * Should also work on Unicode systems.
313 PJ_DECL_UNICODE_TEMP_BUF(wtempaddr,PJ_INET6_ADDRSTRLEN)
314 pj_sockaddr sock_addr;
315 int addr_len = sizeof(sock_addr);
318 sock_addr.addr.sa_family = (pj_uint16_t)af;
319 rc = WSAStringToAddress(
320 PJ_STRING_TO_NATIVE(tempaddr,wtempaddr,sizeof(wtempaddr)),
321 af, NULL, (LPSOCKADDR)&sock_addr, &addr_len);
323 /* If you get rc 130022 Invalid argument (WSAEINVAL) with IPv6,
324 * check that you have IPv6 enabled (install it in the network
327 pj_status_t status = pj_get_netos_error();
328 if (status == PJ_SUCCESS)
329 status = PJ_EUNKNOWN;
334 if (sock_addr.addr.sa_family == PJ_AF_INET) {
335 pj_memcpy(dst, &sock_addr.ipv4.sin_addr, 4);
337 } else if (sock_addr.addr.sa_family == PJ_AF_INET6) {
338 pj_memcpy(dst, &sock_addr.ipv6.sin6_addr, 16);
341 pj_assert(!"Shouldn't happen");
345 #elif !defined(PJ_HAS_IPV6) || PJ_HAS_IPV6==0
346 /* IPv6 support is disabled, just return error without raising assertion */
347 return PJ_EIPV6NOTSUP;
349 pj_assert(!"Not supported");
350 return PJ_EIPV6NOTSUP;
355 * Convert IPv4/IPv6 address to text.
357 PJ_DEF(pj_status_t) pj_inet_ntop(int af, const void *src,
361 PJ_ASSERT_RETURN(src && dst && size, PJ_EINVAL);
365 PJ_ASSERT_RETURN(af==PJ_AF_INET || af==PJ_AF_INET6, PJ_EAFNOTSUP);
367 #if defined(PJ_SOCK_HAS_INET_NTOP) && PJ_SOCK_HAS_INET_NTOP != 0
369 * Implementation using inet_ntop()
371 if (inet_ntop(af, src, dst, size) == NULL) {
372 pj_status_t status = pj_get_netos_error();
373 if (status == PJ_SUCCESS)
374 status = PJ_EUNKNOWN;
381 #elif defined(PJ_WIN32) || defined(PJ_WIN32_WINCE)
383 * Implementation on Windows, using WSAAddressToString().
384 * Should also work on Unicode systems.
387 PJ_DECL_UNICODE_TEMP_BUF(wtempaddr,PJ_INET6_ADDRSTRLEN)
388 pj_sockaddr sock_addr;
389 DWORD addr_len, addr_str_len;
392 pj_bzero(&sock_addr, sizeof(sock_addr));
393 sock_addr.addr.sa_family = (pj_uint16_t)af;
394 if (af == PJ_AF_INET) {
395 if (size < PJ_INET_ADDRSTRLEN)
397 pj_memcpy(&sock_addr.ipv4.sin_addr, src, 4);
398 addr_len = sizeof(pj_sockaddr_in);
399 addr_str_len = PJ_INET_ADDRSTRLEN;
400 } else if (af == PJ_AF_INET6) {
401 if (size < PJ_INET6_ADDRSTRLEN)
403 pj_memcpy(&sock_addr.ipv6.sin6_addr, src, 16);
404 addr_len = sizeof(pj_sockaddr_in6);
405 addr_str_len = PJ_INET6_ADDRSTRLEN;
407 pj_assert(!"Unsupported address family");
411 #if PJ_NATIVE_STRING_IS_UNICODE
412 rc = WSAAddressToString((LPSOCKADDR)&sock_addr, addr_len,
413 NULL, wtempaddr, &addr_str_len);
415 pj_unicode_to_ansi(wtempaddr, wcslen(wtempaddr), dst, size);
418 rc = WSAAddressToString((LPSOCKADDR)&sock_addr, addr_len,
419 NULL, dst, &addr_str_len);
423 pj_status_t status = pj_get_netos_error();
424 if (status == PJ_SUCCESS)
425 status = PJ_EUNKNOWN;
433 #elif !defined(PJ_HAS_IPV6) || PJ_HAS_IPV6==0
434 /* IPv6 support is disabled, just return error without raising assertion */
435 return PJ_EIPV6NOTSUP;
437 pj_assert(!"Not supported");
438 return PJ_EIPV6NOTSUP;
445 PJ_DEF(const pj_str_t*) pj_gethostname(void)
447 static char buf[PJ_MAX_HOSTNAME];
448 static pj_str_t hostname;
452 if (hostname.ptr == NULL) {
454 if (gethostname(buf, sizeof(buf)) != 0) {
455 hostname.ptr[0] = '\0';
458 hostname.slen = strlen(buf);
464 #if defined(PJ_WIN32)
466 * Create new socket/endpoint for communication and returns a descriptor.
468 PJ_DEF(pj_status_t) pj_sock_socket(int af,
476 PJ_ASSERT_RETURN(sock!=NULL, PJ_EINVAL);
477 PJ_ASSERT_RETURN((unsigned)PJ_INVALID_SOCKET==INVALID_SOCKET,
478 (*sock=PJ_INVALID_SOCKET, PJ_EINVAL));
480 *sock = WSASocket(af, type, proto, NULL, 0, WSA_FLAG_OVERLAPPED);
482 if (*sock == PJ_INVALID_SOCKET)
483 return PJ_RETURN_OS_ERROR(pj_get_native_netos_error());
485 #if PJ_SOCK_DISABLE_WSAECONNRESET && \
486 (!defined(PJ_WIN32_WINCE) || PJ_WIN32_WINCE==0)
488 #ifndef SIO_UDP_CONNRESET
489 #define SIO_UDP_CONNRESET _WSAIOW(IOC_VENDOR,12)
492 /* Disable WSAECONNRESET for UDP.
493 * See https://trac.pjsip.org/repos/ticket/1197
495 if (type==PJ_SOCK_DGRAM) {
496 DWORD dwBytesReturned = 0;
497 BOOL bNewBehavior = FALSE;
500 rc = WSAIoctl(*sock, SIO_UDP_CONNRESET,
501 &bNewBehavior, sizeof(bNewBehavior),
502 NULL, 0, &dwBytesReturned,
505 if (rc==SOCKET_ERROR) {
516 * Create new socket/endpoint for communication and returns a descriptor.
518 PJ_DEF(pj_status_t) pj_sock_socket(int af,
527 PJ_ASSERT_RETURN(sock!=NULL, PJ_EINVAL);
528 PJ_ASSERT_RETURN(PJ_INVALID_SOCKET==-1,
529 (*sock=PJ_INVALID_SOCKET, PJ_EINVAL));
531 *sock = socket(af, type, proto);
532 if (*sock == PJ_INVALID_SOCKET)
533 return PJ_RETURN_OS_ERROR(pj_get_native_netos_error());
536 if (type == pj_SOCK_STREAM()) {
537 pj_sock_setsockopt(*sock, pj_SOL_SOCKET(), pj_SO_NOSIGPIPE(),
540 #if defined(PJ_IPHONE_OS_HAS_MULTITASKING_SUPPORT) && \
541 PJ_IPHONE_OS_HAS_MULTITASKING_SUPPORT!=0
542 if (type == pj_SOCK_DGRAM()) {
543 pj_sock_setsockopt(*sock, pj_SOL_SOCKET(), SO_NOSIGPIPE,
555 PJ_DEF(pj_status_t) pj_sock_bind( pj_sock_t sock,
556 const pj_sockaddr_t *addr,
561 PJ_ASSERT_RETURN(addr && len >= (int)sizeof(struct sockaddr_in), PJ_EINVAL);
563 CHECK_ADDR_LEN(addr, len);
565 if (bind(sock, (struct sockaddr*)addr, len) != 0)
566 return PJ_RETURN_OS_ERROR(pj_get_native_netos_error());
575 PJ_DEF(pj_status_t) pj_sock_bind_in( pj_sock_t sock,
583 PJ_SOCKADDR_SET_LEN(&addr, sizeof(pj_sockaddr_in));
584 addr.sin_family = PJ_AF_INET;
585 pj_bzero(addr.sin_zero, sizeof(addr.sin_zero));
586 addr.sin_addr.s_addr = pj_htonl(addr32);
587 addr.sin_port = pj_htons(port);
589 return pj_sock_bind(sock, &addr, sizeof(pj_sockaddr_in));
596 PJ_DEF(pj_status_t) pj_sock_close(pj_sock_t sock)
601 #if defined(PJ_WIN32) && PJ_WIN32!=0 || \
602 defined(PJ_WIN32_WINCE) && PJ_WIN32_WINCE!=0
603 rc = closesocket(sock);
609 return PJ_RETURN_OS_ERROR(pj_get_native_netos_error());
617 PJ_DEF(pj_status_t) pj_sock_getpeername( pj_sock_t sock,
622 if (getpeername(sock, (struct sockaddr*)addr, (socklen_t*)namelen) != 0)
623 return PJ_RETURN_OS_ERROR(pj_get_native_netos_error());
625 PJ_SOCKADDR_RESET_LEN(addr);
633 PJ_DEF(pj_status_t) pj_sock_getsockname( pj_sock_t sock,
638 if (getsockname(sock, (struct sockaddr*)addr, (socklen_t*)namelen) != 0)
639 return PJ_RETURN_OS_ERROR(pj_get_native_netos_error());
641 PJ_SOCKADDR_RESET_LEN(addr);
649 PJ_DEF(pj_status_t) pj_sock_send(pj_sock_t sock,
655 PJ_ASSERT_RETURN(len, PJ_EINVAL);
657 *len = send(sock, (const char*)buf, *len, flags);
660 return PJ_RETURN_OS_ERROR(pj_get_native_netos_error());
669 PJ_DEF(pj_status_t) pj_sock_sendto(pj_sock_t sock,
673 const pj_sockaddr_t *to,
677 PJ_ASSERT_RETURN(len, PJ_EINVAL);
679 CHECK_ADDR_LEN(to, tolen);
681 *len = sendto(sock, (const char*)buf, *len, flags,
682 (const struct sockaddr*)to, tolen);
685 return PJ_RETURN_OS_ERROR(pj_get_native_netos_error());
693 PJ_DEF(pj_status_t) pj_sock_recv(pj_sock_t sock,
699 PJ_ASSERT_RETURN(buf && len, PJ_EINVAL);
701 *len = recv(sock, (char*)buf, *len, flags);
704 return PJ_RETURN_OS_ERROR(pj_get_native_netos_error());
712 PJ_DEF(pj_status_t) pj_sock_recvfrom(pj_sock_t sock,
720 PJ_ASSERT_RETURN(buf && len, PJ_EINVAL);
721 PJ_ASSERT_RETURN(from && fromlen, (*len=-1, PJ_EINVAL));
723 *len = recvfrom(sock, (char*)buf, *len, flags,
724 (struct sockaddr*)from, (socklen_t*)fromlen);
727 return PJ_RETURN_OS_ERROR(pj_get_native_netos_error());
729 PJ_SOCKADDR_RESET_LEN(from);
737 PJ_DEF(pj_status_t) pj_sock_getsockopt( pj_sock_t sock,
744 PJ_ASSERT_RETURN(optval && optlen, PJ_EINVAL);
746 if (getsockopt(sock, level, optname, (char*)optval, (socklen_t*)optlen)!=0)
747 return PJ_RETURN_OS_ERROR(pj_get_native_netos_error());
755 PJ_DEF(pj_status_t) pj_sock_setsockopt( pj_sock_t sock,
762 if (setsockopt(sock, level, optname, (const char*)optval, optlen) != 0)
763 return PJ_RETURN_OS_ERROR(pj_get_native_netos_error());
771 PJ_DEF(pj_status_t) pj_sock_connect( pj_sock_t sock,
772 const pj_sockaddr_t *addr,
776 if (connect(sock, (struct sockaddr*)addr, namelen) != 0)
777 return PJ_RETURN_OS_ERROR(pj_get_native_netos_error());
787 PJ_DEF(pj_status_t) pj_sock_shutdown( pj_sock_t sock,
791 if (shutdown(sock, how) != 0)
792 return PJ_RETURN_OS_ERROR(pj_get_native_netos_error());
798 * Start listening to incoming connections.
800 PJ_DEF(pj_status_t) pj_sock_listen( pj_sock_t sock,
804 if (listen(sock, backlog) != 0)
805 return PJ_RETURN_OS_ERROR(pj_get_native_netos_error());
811 * Accept incoming connections
813 PJ_DEF(pj_status_t) pj_sock_accept( pj_sock_t serverfd,
819 PJ_ASSERT_RETURN(newsock != NULL, PJ_EINVAL);
821 #if defined(PJ_SOCKADDR_HAS_LEN) && PJ_SOCKADDR_HAS_LEN!=0
823 PJ_SOCKADDR_SET_LEN(addr, *addrlen);
827 *newsock = accept(serverfd, (struct sockaddr*)addr, (socklen_t*)addrlen);
828 if (*newsock==PJ_INVALID_SOCKET)
829 return PJ_RETURN_OS_ERROR(pj_get_native_netos_error());
832 #if defined(PJ_SOCKADDR_HAS_LEN) && PJ_SOCKADDR_HAS_LEN!=0
834 PJ_SOCKADDR_RESET_LEN(addr);
841 #endif /* PJ_HAS_TCP */