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