]> git.sesse.net Git - vlc/blob - src/network/getaddrinfo.c
Remove dead code:
[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-2004 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_SYSTEM,     "System error" },
81     { 0,              NULL }
82 };
83
84 static const char *__gai_unknownerr = "Unrecognized error number";
85
86 /****************************************************************************
87  * Converts an EAI_* error code into human readable english text.
88  ****************************************************************************/
89 const char *vlc_gai_strerror( int errnum )
90 {
91     int i;
92
93     for (i = 0; __gai_errlist[i].msg != NULL; i++)
94         if (errnum == __gai_errlist[i].code)
95             return __gai_errlist[i].msg;
96
97     return __gai_unknownerr;
98 }
99 # undef _EAI_POSITIVE_MAX
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             int solved = 0;
167
168             /* host name resolution */
169             if (!(flags & NI_NUMERICHOST))
170             {
171                 struct hostent *hent;
172
173                 hent = gethostbyaddr ((const void*)&addr->sin_addr,
174                                       4, AF_INET);
175
176                 if (hent != NULL)
177                 {
178                     strlcpy (host, hent->h_name, hostlen);
179
180                     /*
181                      * only keep first part of hostname
182                      * if user don't want fully qualified
183                      * domain name
184                      */
185                     if (flags & NI_NOFQDN)
186                     {
187                         char *ptr;
188
189                         ptr = strchr (host, '.');
190                         if (ptr != NULL)
191                             *ptr = 0;
192                     }
193
194                     solved = 1;
195                 }
196                 else if (flags & NI_NAMEREQD)
197                     return gai_error_from_herrno ();
198             }
199
200             if (!solved)
201                 /* inet_ntoa() can't fail */
202                 strlcpy (host, inet_ntoa (addr->sin_addr), hostlen);
203         }
204
205         if (serv != NULL)
206         {
207             snprintf (serv, servlen, "%u",
208                       (unsigned int)ntohs (addr->sin_port));
209             serv[servlen - 1] = '\0';
210         }
211     }
212     return 0;
213 }
214
215 #endif /* if !HAVE_GETNAMEINFO */
216
217 #if defined( WIN32 ) && !defined( UNDER_CE )
218     /*
219      * Here is the kind of kludge you need to keep binary compatibility among
220      * varying OS versions...
221      */
222 typedef int (CALLBACK * GETNAMEINFO) ( const struct sockaddr*, socklen_t,
223                                            char*, DWORD, char*, DWORD, int );
224 typedef int (CALLBACK * GETADDRINFO) (const char *, const char *,
225                                           const struct addrinfo *,
226                                           struct addrinfo **);
227
228 typedef void (CALLBACK * FREEADDRINFO) ( struct addrinfo * );
229
230
231 static WINAPI int _ws2_getnameinfo_bind( const struct sockaddr *sa, socklen_t salen,
232                char *host, DWORD hostlen, char *serv, DWORD servlen, int flags );
233
234 static WINAPI int _ws2_getaddrinfo_bind(const char *node, const char *service,
235                const struct addrinfo *hints, struct addrinfo **res);
236
237 static WINAPI void _ws2_freeaddrinfo_bind( struct addrinfo *infos );
238
239 static GETNAMEINFO ws2_getnameinfo = _ws2_getnameinfo_bind;
240 static GETADDRINFO ws2_getaddrinfo = _ws2_getaddrinfo_bind;
241 static FREEADDRINFO ws2_freeaddrinfo = _ws2_freeaddrinfo_bind;
242
243 static int _ws2_find_ipv6_api(void)
244 {
245     /* For Windows XP and above, IPv6 stack is in WS2_32.DLL */
246     HINSTANCE module = LoadLibrary( "ws2_32.dll" );
247     if( module != NULL )
248     {
249         ws2_getnameinfo = (GETNAMEINFO)GetProcAddress( module, "getnameinfo" );
250         ws2_getaddrinfo = (GETADDRINFO)GetProcAddress( module, "getaddrinfo" );
251         ws2_freeaddrinfo = (FREEADDRINFO)GetProcAddress( module, "freeaddrinfo" );
252         if( ws2_getnameinfo && ws2_getaddrinfo && ws2_freeaddrinfo )
253         {
254             /* got them */
255             return 1;
256         }
257         FreeLibrary( module );
258
259         /* For Windows 2000 and below, try IPv6 stack in in WSHIP6.DLL */
260         module = LoadLibrary( "wship6.dll" );
261         if( module != NULL )
262         {
263             ws2_getnameinfo = (GETNAMEINFO)GetProcAddress( module, "getnameinfo" );
264             ws2_getaddrinfo = (GETADDRINFO)GetProcAddress( module, "getaddrinfo" );
265             ws2_freeaddrinfo = (FREEADDRINFO)GetProcAddress( module, "freeaddrinfo" );
266             if( ws2_getnameinfo && ws2_getaddrinfo && ws2_freeaddrinfo )
267             {
268                 /* got them */
269                 return 1;
270             }
271             FreeLibrary( module );
272         }
273     }
274     /* no API */
275     return 0;
276 }
277
278 static WINAPI int _ws2_getnameinfo_bind( const struct sockaddr *sa, socklen_t salen,
279                char *host, DWORD hostlen, char *serv, DWORD servlen, int flags )
280 {
281     if( _ws2_find_ipv6_api() )
282     {
283         return ws2_getnameinfo(sa, salen, host, hostlen, serv, servlen, flags);
284     }
285     /* return a possible error if API is not found */
286     WSASetLastError(WSAHOST_NOT_FOUND);
287     return WSAHOST_NOT_FOUND;
288 }
289
290 static WINAPI int _ws2_getaddrinfo_bind(const char *node, const char *service,
291                const struct addrinfo *hints, struct addrinfo **res)
292 {
293     if( _ws2_find_ipv6_api() )
294     {
295         return ws2_getaddrinfo(node, service, hints, res);
296     }
297     /* return a possible error if API is not found */
298     WSASetLastError(WSAHOST_NOT_FOUND);
299     return WSAHOST_NOT_FOUND;
300 }
301
302 static WINAPI void _ws2_freeaddrinfo_bind( struct addrinfo *infos )
303 {
304     if( _ws2_find_ipv6_api() )
305     {
306         ws2_freeaddrinfo(infos);
307     }
308 }
309
310 #endif
311
312 #ifndef HAVE_GETADDRINFO
313 /*
314  * This functions must be used to free the memory allocated by getaddrinfo().
315  */
316 static void
317 __freeaddrinfo (struct addrinfo *res)
318 {
319     if (res != NULL)
320     {
321         if (res->ai_canonname != NULL)
322             free (res->ai_canonname);
323         if (res->ai_addr != NULL)
324             free (res->ai_addr);
325         if (res->ai_next != NULL)
326             free (res->ai_next);
327         free (res);
328     }
329 }
330
331
332 /*
333  * Internal function that builds an addrinfo struct.
334  */
335 static struct addrinfo *
336 makeaddrinfo (int af, int type, int proto,
337               const struct sockaddr *addr, size_t addrlen,
338               const char *canonname)
339 {
340     struct addrinfo *res;
341
342     res = (struct addrinfo *)malloc (sizeof (struct addrinfo));
343     if (res != NULL)
344     {
345         res->ai_flags = 0;
346         res->ai_family = af;
347         res->ai_socktype = type;
348         res->ai_protocol = proto;
349         res->ai_addrlen = addrlen;
350         res->ai_addr = malloc (addrlen);
351         res->ai_canonname = NULL;
352         res->ai_next = NULL;
353
354         if (res->ai_addr != NULL)
355         {
356             memcpy (res->ai_addr, addr, addrlen);
357
358             if (canonname != NULL)
359             {
360                 res->ai_canonname = strdup (canonname);
361                 if (res->ai_canonname != NULL)
362                     return res; /* success ! */
363             }
364             else
365                 return res;
366         }
367     }
368     /* failsafe */
369     vlc_freeaddrinfo (res);
370     return NULL;
371 }
372
373
374 static struct addrinfo *
375 makeipv4info (int type, int proto, u_long ip, u_short port, const char *name)
376 {
377     struct sockaddr_in addr;
378
379     memset (&addr, 0, sizeof (addr));
380     addr.sin_family = AF_INET;
381 # ifdef HAVE_SA_LEN
382     addr.sin_len = sizeof (addr);
383 # endif
384     addr.sin_port = port;
385     addr.sin_addr.s_addr = ip;
386
387     return makeaddrinfo (AF_INET, type, proto,
388                          (struct sockaddr*)&addr, sizeof (addr), name);
389 }
390
391
392 /*
393  * getaddrinfo() non-thread-safe IPv4-only implementation
394  * Address-family-independant hostname to address resolution.
395  *
396  * This is meant for IPv6-unaware systems that do probably not provide
397  * getaddrinfo(), but still have old function gethostbyname().
398  *
399  * Only UDP and TCP over IPv4 are supported here.
400  */
401 static int
402 __getaddrinfo (const char *node, const char *service,
403                const struct addrinfo *hints, struct addrinfo **res)
404 {
405     struct addrinfo *info;
406     u_long ip;
407     u_short port;
408     int protocol = 0, flags = 0;
409     const char *name = NULL;
410
411 #ifdef WIN32
412     /*
413      * Maybe you knew already that Winsock does not handle TCP/RST packets
414      * properly, so that when a TCP connection fails, it will wait until it
415      * times out even if the remote host did return a TCP/RST. However, it
416      * still sees the TCP/RST as the error code is 10061 instead of 10060.
417      * Basically, we have the stupid brainfucked behavior with DNS queries...
418      * When the recursive DNS server returns an error, Winsock waits about
419      * 2 seconds before it returns to the callers, even though it should know
420      * that is pointless. I'd like to know how come this hasn't been fixed
421      * for the past decade, or maybe not.
422      *
423      * Anyway, this is causing a severe delay when the SAP listener tries
424      * to resolve more than ten IPv6 numeric addresses. Modern systems will
425      * eventually realize that it is an IPv6 address, and won't try to resolve
426      * it as a IPv4 address via the Domain Name Service. Old systems
427      * (including Windows XP without the IPv6 stack) will not. It is normally
428      * not an issue as the DNS server usually returns an error very quickly.
429      * But it IS a severe issue on Windows, given the bug explained above.
430      * So here comes one more bug-to-bug Windows compatibility fix.
431      */
432     if ((node != NULL) && (strchr (node, ':') != NULL))
433        return EAI_NONAME;
434 #endif
435
436     if (hints != NULL)
437     {
438         flags = hints->ai_flags;
439
440         if (flags & ~_AI_MASK)
441             return EAI_BADFLAGS;
442         /* only accept AF_INET and AF_UNSPEC */
443         if (hints->ai_family && (hints->ai_family != AF_INET))
444             return EAI_FAMILY;
445
446         /* protocol sanity check */
447         switch (hints->ai_socktype)
448         {
449             case SOCK_STREAM:
450                 protocol = IPPROTO_TCP;
451                 break;
452
453             case SOCK_DGRAM:
454                 protocol = IPPROTO_UDP;
455                 break;
456
457 #ifndef SOCK_RAW
458             case SOCK_RAW:
459 #endif
460             case 0:
461                 break;
462
463             default:
464                 return EAI_SOCKTYPE;
465         }
466         if (hints->ai_protocol && protocol
467          && (protocol != hints->ai_protocol))
468             return EAI_SERVICE;
469     }
470
471     *res = NULL;
472
473     /* default values */
474     if (node == NULL)
475     {
476         if (flags & AI_PASSIVE)
477             ip = htonl (INADDR_ANY);
478         else
479             ip = htonl (INADDR_LOOPBACK);
480     }
481     else
482     if ((ip = inet_addr (node)) == INADDR_NONE)
483     {
484         struct hostent *entry = NULL;
485
486         /* hostname resolution */
487         if (!(flags & AI_NUMERICHOST))
488             entry = gethostbyname (node);
489
490         if (entry == NULL)
491             return EAI_NONAME;
492
493         if ((entry->h_length != 4) || (entry->h_addrtype != AF_INET))
494             return EAI_FAMILY;
495
496         ip = *((u_long *) entry->h_addr);
497         if (flags & AI_CANONNAME)
498             name = entry->h_name;
499     }
500
501     if ((flags & AI_CANONNAME) && (name == NULL))
502         name = node;
503
504     /* service resolution */
505     if (service == NULL)
506         port = 0;
507     else
508     {
509         long d;
510         char *end;
511
512         d = strtoul (service, &end, 0);
513         if (end[0] /* service is not a number */
514          || (d > 65535))
515         {
516             struct servent *entry;
517             const char *protoname;
518
519             switch (protocol)
520             {
521                 case IPPROTO_TCP:
522                     protoname = "tcp";
523                     break;
524
525                 case IPPROTO_UDP:
526                     protoname = "udp";
527                     break;
528
529                 default:
530                     protoname = NULL;
531             }
532
533             entry = getservbyname (service, protoname);
534             if (entry == NULL)
535                 return EAI_SERVICE;
536
537             port = entry->s_port;
538         }
539         else
540             port = htons ((u_short)d);
541     }
542
543     /* building results... */
544     if ((!protocol) || (protocol == IPPROTO_UDP))
545     {
546         info = makeipv4info (SOCK_DGRAM, IPPROTO_UDP, ip, port, name);
547         if (info == NULL)
548         {
549             errno = ENOMEM;
550             return EAI_SYSTEM;
551         }
552         if (flags & AI_PASSIVE)
553             info->ai_flags |= AI_PASSIVE;
554         *res = info;
555     }
556     if ((!protocol) || (protocol == IPPROTO_TCP))
557     {
558         info = makeipv4info (SOCK_STREAM, IPPROTO_TCP, ip, port, name);
559         if (info == NULL)
560         {
561             errno = ENOMEM;
562             return EAI_SYSTEM;
563         }
564         info->ai_next = *res;
565         if (flags & AI_PASSIVE)
566             info->ai_flags |= AI_PASSIVE;
567         *res = info;
568     }
569
570     return 0;
571 }
572 #endif /* if !HAVE_GETADDRINFO */
573
574
575 int vlc_getnameinfo( const struct sockaddr *sa, int salen,
576                      char *host, int hostlen, int *portnum, int flags )
577 {
578     char psz_servbuf[6], *psz_serv;
579     int i_servlen, i_val;
580
581     flags |= NI_NUMERICSERV;
582     if( portnum != NULL )
583     {
584         psz_serv = psz_servbuf;
585         i_servlen = sizeof( psz_servbuf );
586     }
587     else
588     {
589         psz_serv = NULL;
590         i_servlen = 0;
591     }
592 #if defined( WIN32 ) && !defined( UNDER_CE )
593     i_val = ws2_getnameinfo( sa, salen, host, hostlen, psz_serv,
594                                  i_servlen, flags );
595 #endif
596 #if defined( HAVE_GETNAMEINFO ) || defined( UNDER_CE )
597     i_val = getnameinfo(sa, salen, host, hostlen, psz_serv, i_servlen, flags);
598 #else
599     {
600 # ifdef HAVE_USABLE_MUTEX_THAT_DONT_NEED_LIBVLC_POINTER
601         static vlc_value_t lock;
602
603         /* my getnameinfo implementation is not thread-safe as it uses
604          * gethostbyaddr and the likes */
605         vlc_mutex_lock( lock.p_address );
606 #else
607 # warning FIXME : This is not thread-safe!
608 #endif
609         i_val = __getnameinfo( sa, salen, host, hostlen, psz_serv, i_servlen,
610                                flags );
611 # ifdef HAVE_USABLE_MUTEX_THAT_DONT_NEED_LIBVLC_POINTER
612         vlc_mutex_unlock( lock.p_address );
613 # endif
614     }
615 #endif
616
617     if( portnum != NULL )
618         *portnum = atoi( psz_serv );
619
620     return i_val;
621 }
622
623
624 /* TODO: support for setting sin6_scope_id */
625 int vlc_getaddrinfo( vlc_object_t *p_this, const char *node,
626                      int i_port, const struct addrinfo *p_hints,
627                      struct addrinfo **res )
628 {
629     struct addrinfo hints;
630     char psz_buf[NI_MAXHOST], *psz_node, psz_service[6];
631
632     /*
633      * In VLC, we always use port number as integer rather than strings
634      * for historical reasons (and portability).
635      */
636     if( ( i_port > 65535 ) || ( i_port < 0 ) )
637     {
638         msg_Err( p_this, "invalid port number %d specified", i_port );
639         return EAI_SERVICE;
640     }
641
642     /* cannot overflow */
643     snprintf( psz_service, 6, "%d", i_port );
644
645     /* Check if we have to force ipv4 or ipv6 */
646     if( p_hints == NULL )
647         memset( &hints, 0, sizeof( hints ) );
648     else
649         memcpy( &hints, p_hints, sizeof( hints ) );
650
651     if( hints.ai_family == AF_UNSPEC )
652     {
653         vlc_value_t val;
654
655         var_Create( p_this, "ipv4", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
656         var_Get( p_this, "ipv4", &val );
657         if( val.b_bool )
658             hints.ai_family = AF_INET;
659
660 #ifdef AF_INET6
661         var_Create( p_this, "ipv6", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
662         var_Get( p_this, "ipv6", &val );
663         if( val.b_bool )
664             hints.ai_family = AF_INET6;
665 #endif
666     }
667
668     /*
669      * VLC extensions :
670      * - accept "" as NULL
671      * - ignore square brackets
672      */
673     if( ( node == NULL ) || (node[0] == '\0' ) )
674     {
675         psz_node = NULL;
676     }
677     else
678     {
679         strlcpy( psz_buf, node, NI_MAXHOST );
680
681         psz_node = psz_buf;
682
683         if( psz_buf[0] == '[' )
684         {
685             char *ptr;
686
687             ptr = strrchr( psz_buf, ']' );
688             if( ( ptr != NULL ) && (ptr[1] == '\0' ) )
689             {
690                 *ptr = '\0';
691                 psz_node++;
692             }
693         }
694     }
695
696 #if defined( WIN32 ) && !defined( UNDER_CE )
697     /*
698      * Winsock tries to resolve numerical IPv4 addresses as AAAA
699      * and IPv6 addresses as A... There comes the work around.
700      */
701     if ((hints.ai_flags & AI_NUMERICHOST) == 0)
702     {
703         hints.ai_flags |= AI_NUMERICHOST;
704
705         if (ws2_getaddrinfo (psz_node, psz_service, &hints, res) == 0)
706             return 0;
707
708         hints.ai_flags &= ~AI_NUMERICHOST;
709     }
710
711     return ws2_getaddrinfo (psz_node, psz_service, &hints, res);
712 #endif
713 #if defined( HAVE_GETADDRINFO ) || defined( UNDER_CE )
714 # ifdef AI_IDN
715     /* Run-time I18n Domain Names support */
716     {
717         static vlc_bool_t i_idn = VLC_TRUE; /* beware of thread-safety */
718
719         if( i_idn )
720         {
721             int i_ret;
722
723             hints.ai_flags |= AI_IDN;
724             i_ret = getaddrinfo( psz_node, psz_service, &hints, res );
725
726             if( i_ret != EAI_BADFLAGS )
727                 return i_ret;
728
729             /* libidn not available: disable and retry without it */
730
731             /* NOTE: Using i_idn here would not be thread-safe */
732             hints.ai_flags &= ~AI_IDN;
733             i_idn = VLC_FALSE;
734             msg_Dbg( p_this, "International Domain Names not supported - " \
735                 "disabled" );
736         }
737     }
738 # endif
739     return getaddrinfo( psz_node, psz_service, &hints, res );
740 #else
741 {
742     int i_ret;
743
744     vlc_value_t lock;
745
746     var_Create( p_this->p_libvlc, "getaddrinfo_mutex", VLC_VAR_MUTEX );
747     var_Get( p_this->p_libvlc, "getaddrinfo_mutex", &lock );
748     vlc_mutex_lock( lock.p_address );
749
750     i_ret = __getaddrinfo( psz_node, psz_service, &hints, res );
751     vlc_mutex_unlock( lock.p_address );
752     return i_ret;
753 }
754 #endif
755 }
756
757
758 void vlc_freeaddrinfo( struct addrinfo *infos )
759 {
760 #if defined( WIN32 ) && !defined( UNDER_CE )
761     ws2_freeaddrinfo( infos );
762 #endif
763 #if defined( HAVE_GETADDRINFO ) || defined( UNDER_CE )
764     freeaddrinfo( infos );
765 #else
766     __freeaddrinfo( infos );
767 #endif
768 }