]> git.sesse.net Git - vlc/blob - src/network/getaddrinfo.c
Remove redumdant mutex
[vlc] / src / network / getaddrinfo.c
1 /*****************************************************************************
2  * getaddrinfo.c: getaddrinfo/getnameinfo replacement functions
3  *****************************************************************************
4  * Copyright (C) 2005 the VideoLAN team
5  * Copyright (C) 2002-2007 Rémi Denis-Courmont
6  * $Id$
7  *
8  * Author: Rémi Denis-Courmont <rem # videolan.org>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23  *****************************************************************************/
24
25 #include <vlc/vlc.h>
26
27 #include <stddef.h> /* size_t */
28 #include <string.h> /* strlen(), memcpy(), memset(), strchr() */
29 #include <stdlib.h> /* malloc(), free(), strtoul() */
30 #include <errno.h>
31
32 #ifdef HAVE_SYS_TYPES_H
33 #   include <sys/types.h>
34 #endif
35 #ifdef HAVE_ARPA_INET_H
36 #   include <arpa/inet.h>
37 #endif
38 #ifdef HAVE_NETINET_IN_H
39 #   include <netinet/in.h>
40 #endif
41 #ifdef HAVE_UNISTD_H
42 #   include <unistd.h>
43 #endif
44
45 #include <vlc_network.h>
46
47 #ifndef NO_ADDRESS
48 #   define NO_ADDRESS  NO_DATA
49 #endif
50 #ifndef INADDR_NONE
51 #   define INADDR_NONE 0xFFFFFFFF
52 #endif
53 #ifndef AF_UNSPEC
54 #   define AF_UNSPEC   0
55 #endif
56
57 #define _NI_MASK (NI_NUMERICHOST|NI_NUMERICSERV|NI_NOFQDN|NI_NAMEREQD|\
58                   NI_DGRAM)
59 #define _AI_MASK (AI_PASSIVE|AI_CANONNAME|AI_NUMERICHOST)
60
61
62 #ifndef HAVE_GAI_STRERROR
63 static struct
64 {
65     int code;
66     const char *msg;
67 } const __gai_errlist[] =
68 {
69     { 0,              "Error 0" },
70     { EAI_BADFLAGS,   "Invalid flag used" },
71     { EAI_NONAME,     "Host or service not found" },
72     { EAI_AGAIN,      "Temporary name service failure" },
73     { EAI_FAIL,       "Non-recoverable name service failure" },
74     { EAI_NODATA,     "No data for host name" },
75     { EAI_FAMILY,     "Unsupported address family" },
76     { EAI_SOCKTYPE,   "Unsupported socket type" },
77     { EAI_SERVICE,    "Incompatible service for socket type" },
78     { EAI_ADDRFAMILY, "Unavailable address family for host name" },
79     { EAI_MEMORY,     "Memory allocation failure" },
80     { EAI_OVERFLOW,   "Buffer overflow" },
81     { EAI_SYSTEM,     "System error" },
82     { 0,              NULL }
83 };
84
85 static const char *__gai_unknownerr = "Unrecognized error number";
86
87 /****************************************************************************
88  * Converts an EAI_* error code into human readable english text.
89  ****************************************************************************/
90 const char *vlc_gai_strerror( int errnum )
91 {
92     int i;
93
94     for (i = 0; __gai_errlist[i].msg != NULL; i++)
95         if (errnum == __gai_errlist[i].code)
96             return __gai_errlist[i].msg;
97
98     return __gai_unknownerr;
99 }
100 #else /* ifndef HAVE_GAI_STRERROR */
101 const char *vlc_gai_strerror( int errnum )
102 {
103     return gai_strerror( errnum );
104 }
105 #endif
106
107 #if !(defined (HAVE_GETNAMEINFO) && defined (HAVE_GETADDRINFO))
108 /*
109  * Converts the current herrno error value into an EAI_* error code.
110  * That error code is normally returned by getnameinfo() or getaddrinfo().
111  */
112 static int
113 gai_error_from_herrno( void )
114 {
115     switch(h_errno)
116     {
117         case HOST_NOT_FOUND:
118             return EAI_NONAME;
119
120         case NO_ADDRESS:
121 # if (NO_ADDRESS != NO_DATA)
122         case NO_DATA:
123 # endif
124             return EAI_NODATA;
125
126         case NO_RECOVERY:
127             return EAI_FAIL;
128
129         case TRY_AGAIN:
130             return EAI_AGAIN;
131     }
132     return EAI_SYSTEM;
133 }
134 #endif /* if !(HAVE_GETNAMEINFO && HAVE_GETADDRINFO) */
135
136 #ifndef HAVE_GETNAMEINFO
137 /*
138  * getnameinfo() non-thread-safe IPv4-only implementation,
139  * Address-family-independant address to hostname translation
140  * (reverse DNS lookup in case of IPv4).
141  *
142  * This is meant for use on old IP-enabled systems that are not IPv6-aware,
143  * and probably do not have getnameinfo(), but have the old gethostbyaddr()
144  * function.
145  *
146  * GNU C library 2.0.x is known to lack this function, even though it defines
147  * getaddrinfo().
148  */
149 static int
150 __getnameinfo( const struct sockaddr *sa, socklen_t salen,
151                char *host, int hostlen, char *serv, int servlen, int flags )
152 {
153     if (((unsigned)salen < sizeof (struct sockaddr_in))
154      || (sa->sa_family != AF_INET))
155         return EAI_FAMILY;
156     else if (flags & (~_NI_MASK))
157         return EAI_BADFLAGS;
158     else
159     {
160         const struct sockaddr_in *addr;
161
162         addr = (const struct sockaddr_in *)sa;
163
164         if (host != NULL)
165         {
166             /* host name resolution */
167             if (!(flags & NI_NUMERICHOST))
168             {
169                 if (flags & NI_NAMEREQD)
170                     return EAI_NONAME;
171             }
172
173             /* inet_ntoa() is not thread-safe, do not use it */
174             uint32_t ipv4 = ntohl (addr->sin_addr.s_addr);
175
176             if (snprintf (host, hostlen, "%u.%u.%u.%u", ipv4 >> 24,
177                           (ipv4 >> 16) & 0xff, (ipv4 >> 8) & 0xff,
178                           ipv4 & 0xff) >= hostlen)
179                 return EAI_OVERFLOW;
180         }
181
182         if (serv != NULL)
183         {
184             if (snprintf (serv, servlen, "%u",
185                           (unsigned int)ntohs (addr->sin_port)) >= servlen)
186                 return EAI_OVERFLOW;
187         }
188     }
189     return 0;
190 }
191
192 #endif /* if !HAVE_GETNAMEINFO */
193
194 #if defined( WIN32 ) && !defined( UNDER_CE )
195     /*
196      * Here is the kind of kludge you need to keep binary compatibility among
197      * varying OS versions...
198      */
199 typedef int (CALLBACK * GETNAMEINFO) ( const struct sockaddr*, socklen_t,
200                                            char*, DWORD, char*, DWORD, int );
201 typedef int (CALLBACK * GETADDRINFO) (const char *, const char *,
202                                           const struct addrinfo *,
203                                           struct addrinfo **);
204
205 typedef void (CALLBACK * FREEADDRINFO) ( struct addrinfo * );
206
207
208 static WINAPI int _ws2_getnameinfo_bind( const struct sockaddr *sa, socklen_t salen,
209                char *host, DWORD hostlen, char *serv, DWORD servlen, int flags );
210
211 static WINAPI int _ws2_getaddrinfo_bind(const char *node, const char *service,
212                const struct addrinfo *hints, struct addrinfo **res);
213
214 static WINAPI void _ws2_freeaddrinfo_bind( struct addrinfo *infos );
215
216 static GETNAMEINFO ws2_getnameinfo = _ws2_getnameinfo_bind;
217 static GETADDRINFO ws2_getaddrinfo = _ws2_getaddrinfo_bind;
218 static FREEADDRINFO ws2_freeaddrinfo = _ws2_freeaddrinfo_bind;
219
220 static int _ws2_find_ipv6_api(void)
221 {
222     /* For Windows XP and above, IPv6 stack is in WS2_32.DLL */
223     HINSTANCE module = LoadLibrary( "ws2_32.dll" );
224     if( module != NULL )
225     {
226         ws2_getnameinfo = (GETNAMEINFO)GetProcAddress( module, "getnameinfo" );
227         ws2_getaddrinfo = (GETADDRINFO)GetProcAddress( module, "getaddrinfo" );
228         ws2_freeaddrinfo = (FREEADDRINFO)GetProcAddress( module, "freeaddrinfo" );
229         if( ws2_getnameinfo && ws2_getaddrinfo && ws2_freeaddrinfo )
230         {
231             /* got them */
232             return 1;
233         }
234         FreeLibrary( module );
235
236         /* For Windows 2000 and below, try IPv6 stack in in WSHIP6.DLL */
237         module = LoadLibrary( "wship6.dll" );
238         if( module != NULL )
239         {
240             ws2_getnameinfo = (GETNAMEINFO)GetProcAddress( module, "getnameinfo" );
241             ws2_getaddrinfo = (GETADDRINFO)GetProcAddress( module, "getaddrinfo" );
242             ws2_freeaddrinfo = (FREEADDRINFO)GetProcAddress( module, "freeaddrinfo" );
243             if( ws2_getnameinfo && ws2_getaddrinfo && ws2_freeaddrinfo )
244             {
245                 /* got them */
246                 return 1;
247             }
248             FreeLibrary( module );
249         }
250     }
251     /* no API */
252     return 0;
253 }
254
255 static WINAPI int _ws2_getnameinfo_bind( const struct sockaddr *sa, socklen_t salen,
256                char *host, DWORD hostlen, char *serv, DWORD servlen, int flags )
257 {
258     if( _ws2_find_ipv6_api() )
259     {
260         return ws2_getnameinfo(sa, salen, host, hostlen, serv, servlen, flags);
261     }
262     /* return a possible error if API is not found */
263     WSASetLastError(WSAHOST_NOT_FOUND);
264     return WSAHOST_NOT_FOUND;
265 }
266
267 static WINAPI int _ws2_getaddrinfo_bind(const char *node, const char *service,
268                const struct addrinfo *hints, struct addrinfo **res)
269 {
270     if( _ws2_find_ipv6_api() )
271     {
272         return ws2_getaddrinfo(node, service, hints, res);
273     }
274     /* return a possible error if API is not found */
275     WSASetLastError(WSAHOST_NOT_FOUND);
276     return WSAHOST_NOT_FOUND;
277 }
278
279 static WINAPI void _ws2_freeaddrinfo_bind( struct addrinfo *infos )
280 {
281     if( _ws2_find_ipv6_api() )
282     {
283         ws2_freeaddrinfo(infos);
284     }
285 }
286
287 #endif
288
289 #ifndef HAVE_GETADDRINFO
290 /*
291  * This functions must be used to free the memory allocated by getaddrinfo().
292  */
293 static void
294 __freeaddrinfo (struct addrinfo *res)
295 {
296     if (res != NULL)
297     {
298         if (res->ai_canonname != NULL)
299             free (res->ai_canonname);
300         if (res->ai_addr != NULL)
301             free (res->ai_addr);
302         if (res->ai_next != NULL)
303             free (res->ai_next);
304         free (res);
305     }
306 }
307
308
309 /*
310  * Internal function that builds an addrinfo struct.
311  */
312 static struct addrinfo *
313 makeaddrinfo (int af, int type, int proto,
314               const struct sockaddr *addr, size_t addrlen,
315               const char *canonname)
316 {
317     struct addrinfo *res;
318
319     res = (struct addrinfo *)malloc (sizeof (struct addrinfo));
320     if (res != NULL)
321     {
322         res->ai_flags = 0;
323         res->ai_family = af;
324         res->ai_socktype = type;
325         res->ai_protocol = proto;
326         res->ai_addrlen = addrlen;
327         res->ai_addr = malloc (addrlen);
328         res->ai_canonname = NULL;
329         res->ai_next = NULL;
330
331         if (res->ai_addr != NULL)
332         {
333             memcpy (res->ai_addr, addr, addrlen);
334
335             if (canonname != NULL)
336             {
337                 res->ai_canonname = strdup (canonname);
338                 if (res->ai_canonname != NULL)
339                     return res; /* success ! */
340             }
341             else
342                 return res;
343         }
344     }
345     /* failsafe */
346     vlc_freeaddrinfo (res);
347     return NULL;
348 }
349
350
351 static struct addrinfo *
352 makeipv4info (int type, int proto, u_long ip, u_short port, const char *name)
353 {
354     struct sockaddr_in addr;
355
356     memset (&addr, 0, sizeof (addr));
357     addr.sin_family = AF_INET;
358 # ifdef HAVE_SA_LEN
359     addr.sin_len = sizeof (addr);
360 # endif
361     addr.sin_port = port;
362     addr.sin_addr.s_addr = ip;
363
364     return makeaddrinfo (AF_INET, type, proto,
365                          (struct sockaddr*)&addr, sizeof (addr), name);
366 }
367
368
369 /*
370  * getaddrinfo() non-thread-safe IPv4-only implementation
371  * Address-family-independant hostname to address resolution.
372  *
373  * This is meant for IPv6-unaware systems that do probably not provide
374  * getaddrinfo(), but still have old function gethostbyname().
375  *
376  * Only UDP and TCP over IPv4 are supported here.
377  */
378 static int
379 __getaddrinfo (const char *node, const char *service,
380                const struct addrinfo *hints, struct addrinfo **res)
381 {
382     struct addrinfo *info;
383     u_long ip;
384     u_short port;
385     int protocol = 0, flags = 0;
386     const char *name = NULL;
387
388 #ifdef WIN32
389     /*
390      * Maybe you knew already that Winsock does not handle TCP/RST packets
391      * properly, so that when a TCP connection fails, it will wait until it
392      * times out even if the remote host did return a TCP/RST. However, it
393      * still sees the TCP/RST as the error code is 10061 instead of 10060.
394      * Basically, we have the stupid brainfucked behavior with DNS queries...
395      * When the recursive DNS server returns an error, Winsock waits about
396      * 2 seconds before it returns to the callers, even though it should know
397      * that is pointless. I'd like to know how come this hasn't been fixed
398      * for the past decade, or maybe not.
399      *
400      * Anyway, this is causing a severe delay when the SAP listener tries
401      * to resolve more than ten IPv6 numeric addresses. Modern systems will
402      * eventually realize that it is an IPv6 address, and won't try to resolve
403      * it as a IPv4 address via the Domain Name Service. Old systems
404      * (including Windows XP without the IPv6 stack) will not. It is normally
405      * not an issue as the DNS server usually returns an error very quickly.
406      * But it IS a severe issue on Windows, given the bug explained above.
407      * So here comes one more bug-to-bug Windows compatibility fix.
408      */
409     if ((node != NULL) && (strchr (node, ':') != NULL))
410        return EAI_NONAME;
411 #endif
412
413     if (hints != NULL)
414     {
415         flags = hints->ai_flags;
416
417         if (flags & ~_AI_MASK)
418             return EAI_BADFLAGS;
419         /* only accept AF_INET and AF_UNSPEC */
420         if (hints->ai_family && (hints->ai_family != AF_INET))
421             return EAI_FAMILY;
422
423         /* protocol sanity check */
424         switch (hints->ai_socktype)
425         {
426             case SOCK_STREAM:
427                 protocol = IPPROTO_TCP;
428                 break;
429
430             case SOCK_DGRAM:
431                 protocol = IPPROTO_UDP;
432                 break;
433
434 #ifndef SOCK_RAW
435             case SOCK_RAW:
436 #endif
437             case 0:
438                 break;
439
440             default:
441                 return EAI_SOCKTYPE;
442         }
443         if (hints->ai_protocol && protocol
444          && (protocol != hints->ai_protocol))
445             return EAI_SERVICE;
446     }
447
448     *res = NULL;
449
450     /* default values */
451     if (node == NULL)
452     {
453         if (flags & AI_PASSIVE)
454             ip = htonl (INADDR_ANY);
455         else
456             ip = htonl (INADDR_LOOPBACK);
457     }
458     else
459     if ((ip = inet_addr (node)) == INADDR_NONE)
460     {
461         struct hostent *entry = NULL;
462
463         /* hostname resolution */
464         if (!(flags & AI_NUMERICHOST))
465             entry = gethostbyname (node);
466
467         if (entry == NULL)
468             return EAI_NONAME;
469
470         if ((entry->h_length != 4) || (entry->h_addrtype != AF_INET))
471             return EAI_FAMILY;
472
473         ip = *((u_long *) entry->h_addr);
474         if (flags & AI_CANONNAME)
475             name = entry->h_name;
476     }
477
478     if ((flags & AI_CANONNAME) && (name == NULL))
479         name = node;
480
481     /* service resolution */
482     if (service == NULL)
483         port = 0;
484     else
485     {
486         long d;
487         char *end;
488
489         d = strtoul (service, &end, 0);
490         if (end[0] /* service is not a number */
491          || (d > 65535))
492         {
493             struct servent *entry;
494             const char *protoname;
495
496             switch (protocol)
497             {
498                 case IPPROTO_TCP:
499                     protoname = "tcp";
500                     break;
501
502                 case IPPROTO_UDP:
503                     protoname = "udp";
504                     break;
505
506                 default:
507                     protoname = NULL;
508             }
509
510             entry = getservbyname (service, protoname);
511             if (entry == NULL)
512                 return EAI_SERVICE;
513
514             port = entry->s_port;
515         }
516         else
517             port = htons ((u_short)d);
518     }
519
520     /* building results... */
521     if ((!protocol) || (protocol == IPPROTO_UDP))
522     {
523         info = makeipv4info (SOCK_DGRAM, IPPROTO_UDP, ip, port, name);
524         if (info == NULL)
525         {
526             errno = ENOMEM;
527             return EAI_SYSTEM;
528         }
529         if (flags & AI_PASSIVE)
530             info->ai_flags |= AI_PASSIVE;
531         *res = info;
532     }
533     if ((!protocol) || (protocol == IPPROTO_TCP))
534     {
535         info = makeipv4info (SOCK_STREAM, IPPROTO_TCP, ip, port, name);
536         if (info == NULL)
537         {
538             errno = ENOMEM;
539             return EAI_SYSTEM;
540         }
541         info->ai_next = *res;
542         if (flags & AI_PASSIVE)
543             info->ai_flags |= AI_PASSIVE;
544         *res = info;
545     }
546
547     return 0;
548 }
549 #endif /* if !HAVE_GETADDRINFO */
550
551
552 int vlc_getnameinfo( const struct sockaddr *sa, int salen,
553                      char *host, int hostlen, int *portnum, int flags )
554 {
555     char psz_servbuf[6], *psz_serv;
556     int i_servlen, i_val;
557
558     flags |= NI_NUMERICSERV;
559     if( portnum != NULL )
560     {
561         psz_serv = psz_servbuf;
562         i_servlen = sizeof( psz_servbuf );
563     }
564     else
565     {
566         psz_serv = NULL;
567         i_servlen = 0;
568     }
569 #if defined( WIN32 ) && !defined( UNDER_CE )
570     i_val = ws2_getnameinfo( sa, salen, host, hostlen, psz_serv,
571                                  i_servlen, flags );
572 #endif
573 #if defined( HAVE_GETNAMEINFO ) || defined( UNDER_CE )
574     i_val = getnameinfo(sa, salen, host, hostlen, psz_serv, i_servlen, flags);
575 #else
576     i_val = __getnameinfo (sa, salen, host, hostlen, psz_serv, i_servlen, flags);
577 #endif
578
579     if( portnum != NULL )
580         *portnum = atoi( psz_serv );
581
582     return i_val;
583 }
584
585
586 /* TODO: support for setting sin6_scope_id */
587 int vlc_getaddrinfo( vlc_object_t *p_this, const char *node,
588                      int i_port, const struct addrinfo *p_hints,
589                      struct addrinfo **res )
590 {
591     struct addrinfo hints;
592     char psz_buf[NI_MAXHOST], *psz_node, psz_service[6];
593
594     /*
595      * In VLC, we always use port number as integer rather than strings
596      * for historical reasons (and portability).
597      */
598     if( ( i_port > 65535 ) || ( i_port < 0 ) )
599     {
600         msg_Err( p_this, "invalid port number %d specified", i_port );
601         return EAI_SERVICE;
602     }
603
604     /* cannot overflow */
605     snprintf( psz_service, 6, "%d", i_port );
606
607     /* Check if we have to force ipv4 or ipv6 */
608     if( p_hints == NULL )
609         memset( &hints, 0, sizeof( hints ) );
610     else
611         memcpy( &hints, p_hints, sizeof( hints ) );
612
613     if( hints.ai_family == AF_UNSPEC )
614     {
615         vlc_value_t val;
616
617         var_Create( p_this, "ipv4", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
618         var_Get( p_this, "ipv4", &val );
619         if( val.b_bool )
620             hints.ai_family = AF_INET;
621
622 #ifdef AF_INET6
623         var_Create( p_this, "ipv6", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
624         var_Get( p_this, "ipv6", &val );
625         if( val.b_bool )
626             hints.ai_family = AF_INET6;
627 #endif
628     }
629
630     /*
631      * VLC extensions :
632      * - accept "" as NULL
633      * - ignore square brackets
634      */
635     if( ( node == NULL ) || (node[0] == '\0' ) )
636     {
637         psz_node = NULL;
638     }
639     else
640     {
641         strlcpy( psz_buf, node, NI_MAXHOST );
642
643         psz_node = psz_buf;
644
645         if( psz_buf[0] == '[' )
646         {
647             char *ptr;
648
649             ptr = strrchr( psz_buf, ']' );
650             if( ( ptr != NULL ) && (ptr[1] == '\0' ) )
651             {
652                 *ptr = '\0';
653                 psz_node++;
654             }
655         }
656     }
657
658 #if defined( WIN32 ) && !defined( UNDER_CE )
659     /*
660      * Winsock tries to resolve numerical IPv4 addresses as AAAA
661      * and IPv6 addresses as A... There comes the work around.
662      */
663     if ((hints.ai_flags & AI_NUMERICHOST) == 0)
664     {
665         hints.ai_flags |= AI_NUMERICHOST;
666
667         if (ws2_getaddrinfo (psz_node, psz_service, &hints, res) == 0)
668             return 0;
669
670         hints.ai_flags &= ~AI_NUMERICHOST;
671     }
672
673     return ws2_getaddrinfo (psz_node, psz_service, &hints, res);
674 #endif
675 #if defined( HAVE_GETADDRINFO ) || defined( UNDER_CE )
676 # ifdef AI_IDN
677     /* Run-time I18n Domain Names support */
678     {
679         static vlc_bool_t i_idn = VLC_TRUE; /* beware of thread-safety */
680
681         if( i_idn )
682         {
683             int i_ret;
684
685             hints.ai_flags |= AI_IDN;
686             i_ret = getaddrinfo( psz_node, psz_service, &hints, res );
687
688             if( i_ret != EAI_BADFLAGS )
689                 return i_ret;
690
691             /* libidn not available: disable and retry without it */
692
693             /* NOTE: Using i_idn here would not be thread-safe */
694             hints.ai_flags &= ~AI_IDN;
695             i_idn = VLC_FALSE;
696             msg_Dbg( p_this, "International Domain Names not supported - " \
697                 "disabled" );
698         }
699     }
700 # endif
701     return getaddrinfo( psz_node, psz_service, &hints, res );
702 #else
703 {
704     int i_ret;
705
706     vlc_value_t lock;
707
708     var_Create( p_this->p_libvlc, "getaddrinfo_mutex", VLC_VAR_MUTEX );
709     var_Get( p_this->p_libvlc, "getaddrinfo_mutex", &lock );
710     vlc_mutex_lock( lock.p_address );
711
712     i_ret = __getaddrinfo( psz_node, psz_service, &hints, res );
713     vlc_mutex_unlock( lock.p_address );
714     return i_ret;
715 }
716 #endif
717 }
718
719
720 void vlc_freeaddrinfo( struct addrinfo *infos )
721 {
722 #if defined( WIN32 ) && !defined( UNDER_CE )
723     ws2_freeaddrinfo( infos );
724 #endif
725 #if defined( HAVE_GETADDRINFO ) || defined( UNDER_CE )
726     freeaddrinfo( infos );
727 #else
728     __freeaddrinfo( infos );
729 #endif
730 }