# include "config.h"
#endif
-#include <vlc/vlc.h>
+#include <vlc_common.h>
#include <stddef.h> /* size_t */
#include <string.h> /* strlen(), memcpy(), memset(), strchr() */
#ifndef HAVE_GAI_STRERROR
-static struct
+static const struct
{
- int code;
- const char *msg;
-} const __gai_errlist[] =
+ int code;
+ const char msg[41];
+} gai_errlist[] =
{
{ 0, "Error 0" },
{ EAI_BADFLAGS, "Invalid flag used" },
{ EAI_MEMORY, "Memory allocation failure" },
{ EAI_OVERFLOW, "Buffer overflow" },
{ EAI_SYSTEM, "System error" },
- { 0, NULL }
+ { 0, "" },
};
-static const char *__gai_unknownerr = "Unrecognized error number";
+static const char gai_unknownerr[] = "Unrecognized error number";
/****************************************************************************
* Converts an EAI_* error code into human readable english text.
****************************************************************************/
const char *vlc_gai_strerror (int errnum)
{
- for (unsigned i = 0; __gai_errlist[i].msg != NULL; i++)
- if (errnum == __gai_errlist[i].code)
- return __gai_errlist[i].msg;
+ for (unsigned i = 0; *gai_errlist[i].msg; i++)
+ if (errnum == gai_errlist[i].code)
+ return gai_errlist[i].msg;
- return __gai_unknownerr;
+ return gai_unknownerr;
}
#else /* ifndef HAVE_GAI_STRERROR */
const char *vlc_gai_strerror (int errnum)
NI_DGRAM)
/*
* getnameinfo() non-thread-safe IPv4-only implementation,
- * Address-family-independant address to hostname translation
+ * Address-family-independent address to hostname translation
* (reverse DNS lookup in case of IPv4).
*
* This is meant for use on old IP-enabled systems that are not IPv6-aware,
/*
* getaddrinfo() non-thread-safe IPv4-only implementation
- * Address-family-independant hostname to address resolution.
+ * Address-family-independent hostname to address resolution.
*
* This is meant for IPv6-unaware systems that do probably not provide
* getaddrinfo(), but still have old function gethostbyname().
AI_PASSIVE |
AI_CANONNAME |
AI_NUMERICHOST |
-#ifdef AI_NUMERICSERV
AI_NUMERICSERV |
-#endif
#ifdef AI_ALL
AI_ALL |
#endif
hints.ai_flags = p_hints->ai_flags & safe_flags;
}
-#ifdef AI_NUMERICSERV
/* We only ever use port *numbers* */
hints.ai_flags |= AI_NUMERICSERV;
-#endif
if( hints.ai_family == AF_UNSPEC )
{
- vlc_value_t val;
-
- var_Create( p_this, "ipv4", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
- var_Get( p_this, "ipv4", &val );
- if( val.b_bool )
- hints.ai_family = AF_INET;
-
#ifdef AF_INET6
- var_Create( p_this, "ipv6", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
- var_Get( p_this, "ipv6", &val );
- if( val.b_bool )
+ if (var_CreateGetBool (p_this, "ipv6"))
hints.ai_family = AF_INET6;
+ else
#endif
+ if (var_CreateGetBool (p_this, "ipv4"))
+ hints.ai_family = AF_INET;
}
/*
hints.ai_flags &= ~AI_NUMERICHOST;
}
#endif
-#if defined (HAVE_GETADDRINFO)
-# ifdef AI_IDN
+#ifdef AI_IDN
/* Run-time I18n Domain Names support */
- static bool b_idn = true; /* beware of thread-safety */
-
- if (b_idn)
- {
- hints.ai_flags |= AI_IDN;
- int ret = getaddrinfo (psz_node, psz_service, &hints, res);
+ hints.ai_flags |= AI_IDN;
+ int ret = getaddrinfo (psz_node, psz_service, &hints, res);
+ if (ret != EAI_BADFLAGS)
+ return ret;
- if (ret != EAI_BADFLAGS)
- return ret;
-
- /* IDN not available: disable and retry without it */
- hints.ai_flags &= ~AI_IDN;
- b_idn = false;
- msg_Info (p_this, "International Domain Names not supported");
- }
-# endif
- return getaddrinfo (psz_node, psz_service, &hints, res);
-#else
- int ret;
- vlc_value_t lock;
-
- var_Create (p_this->p_libvlc, "getaddrinfo_mutex", VLC_VAR_MUTEX);
- var_Get (p_this->p_libvlc, "getaddrinfo_mutex", &lock);
- vlc_mutex_lock (lock.p_address);
-
- ret = getaddrinfo (psz_node, psz_service, &hints, res);
- vlc_mutex_unlock (lock.p_address);
- return ret;
+ /* IDN not available: disable and retry without it */
+ hints.ai_flags &= ~AI_IDN;
#endif
+ return getaddrinfo (psz_node, psz_service, &hints, res);
}