New upstream version 2.3.4
This commit is contained in:
parent
e7bdd1c6c6
commit
de72f6f588
556 changed files with 90432 additions and 53391 deletions
180
gl/getaddrinfo.c
180
gl/getaddrinfo.c
|
@ -1,19 +1,19 @@
|
|||
/* Get address information (partial implementation).
|
||||
Copyright (C) 1997, 2001-2002, 2004-2013 Free Software Foundation, Inc.
|
||||
Copyright (C) 1997, 2001-2002, 2004-2023 Free Software Foundation, Inc.
|
||||
Contributed by Simon Josefsson <simon@josefsson.org>.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 3, or (at your option)
|
||||
any later version.
|
||||
This file is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as
|
||||
published by the Free Software Foundation; either version 2.1 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
This file is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
GNU Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, see <http://www.gnu.org/licenses/>. */
|
||||
You should have received a copy of the GNU Lesser General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||
|
||||
/* Don't use __attribute__ __nonnull__ in this compilation unit. Otherwise gcc
|
||||
optimizes away the sa == NULL test below. */
|
||||
|
@ -39,8 +39,6 @@
|
|||
/* Get snprintf. */
|
||||
#include <stdio.h>
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "gettext.h"
|
||||
#define _(String) gettext (String)
|
||||
#define N_(String) String
|
||||
|
@ -54,14 +52,48 @@
|
|||
# define PF_UNSPEC 0
|
||||
#endif
|
||||
|
||||
#if defined _WIN32 || defined __WIN32__
|
||||
# define WINDOWS_NATIVE
|
||||
#endif
|
||||
#if HAVE_GETADDRINFO
|
||||
|
||||
/* Override with cdecl calling convention. */
|
||||
|
||||
int
|
||||
getaddrinfo (const char *restrict nodename,
|
||||
const char *restrict servname,
|
||||
const struct addrinfo *restrict hints,
|
||||
struct addrinfo **restrict res)
|
||||
# undef getaddrinfo
|
||||
{
|
||||
return getaddrinfo (nodename, servname, hints, res);
|
||||
}
|
||||
|
||||
void
|
||||
freeaddrinfo (struct addrinfo *ai)
|
||||
# undef freeaddrinfo
|
||||
{
|
||||
freeaddrinfo (ai);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
# if defined _WIN32 && !defined __CYGWIN__
|
||||
# define WINDOWS_NATIVE
|
||||
# endif
|
||||
|
||||
/* gl_sockets_startup */
|
||||
#include "sockets.h"
|
||||
# include "sockets.h"
|
||||
|
||||
# ifdef WINDOWS_NATIVE
|
||||
|
||||
/* Don't assume that UNICODE is not defined. */
|
||||
# undef GetModuleHandle
|
||||
# define GetModuleHandle GetModuleHandleA
|
||||
|
||||
# if !(_WIN32_WINNT >= _WIN32_WINNT_WINXP)
|
||||
|
||||
/* Avoid warnings from gcc -Wcast-function-type. */
|
||||
# define GetProcAddress \
|
||||
(void *) GetProcAddress
|
||||
|
||||
#ifdef WINDOWS_NATIVE
|
||||
typedef int (WSAAPI *getaddrinfo_func) (const char*, const char*,
|
||||
const struct addrinfo*,
|
||||
struct addrinfo**);
|
||||
|
@ -107,20 +139,43 @@ use_win32_p (void)
|
|||
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
# else
|
||||
|
||||
static int
|
||||
use_win32_p (void)
|
||||
{
|
||||
static int done = 0;
|
||||
|
||||
if (!done)
|
||||
{
|
||||
done = 1;
|
||||
|
||||
gl_sockets_startup (SOCKETS_1_1);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
# define getaddrinfo_ptr getaddrinfo
|
||||
# define freeaddrinfo_ptr freeaddrinfo
|
||||
# define getnameinfo_ptr getnameinfo
|
||||
|
||||
# endif
|
||||
# endif
|
||||
|
||||
static bool
|
||||
validate_family (int family)
|
||||
{
|
||||
/* FIXME: Support more families. */
|
||||
#if HAVE_IPV4
|
||||
# if HAVE_IPV4
|
||||
if (family == PF_INET)
|
||||
return true;
|
||||
#endif
|
||||
#if HAVE_IPV6
|
||||
# endif
|
||||
# if HAVE_IPV6
|
||||
if (family == PF_INET6)
|
||||
return true;
|
||||
#endif
|
||||
# endif
|
||||
if (family == PF_UNSPEC)
|
||||
return true;
|
||||
return false;
|
||||
|
@ -133,29 +188,30 @@ getaddrinfo (const char *restrict nodename,
|
|||
const char *restrict servname,
|
||||
const struct addrinfo *restrict hints,
|
||||
struct addrinfo **restrict res)
|
||||
#undef getaddrinfo
|
||||
{
|
||||
struct addrinfo *tmp;
|
||||
int port = 0;
|
||||
struct hostent *he;
|
||||
void *storage;
|
||||
size_t size;
|
||||
#if HAVE_IPV6
|
||||
# if HAVE_IPV6
|
||||
struct v6_pair {
|
||||
struct addrinfo addrinfo;
|
||||
struct sockaddr_in6 sockaddr_in6;
|
||||
};
|
||||
#endif
|
||||
#if HAVE_IPV4
|
||||
# endif
|
||||
# if HAVE_IPV4
|
||||
struct v4_pair {
|
||||
struct addrinfo addrinfo;
|
||||
struct sockaddr_in sockaddr_in;
|
||||
};
|
||||
#endif
|
||||
# endif
|
||||
|
||||
#ifdef WINDOWS_NATIVE
|
||||
# ifdef WINDOWS_NATIVE
|
||||
if (use_win32_p ())
|
||||
return getaddrinfo_ptr (nodename, servname, hints, res);
|
||||
#endif
|
||||
# endif
|
||||
|
||||
if (hints && (hints->ai_flags & ~(AI_CANONNAME|AI_PASSIVE)))
|
||||
/* FIXME: Support more flags. */
|
||||
|
@ -174,11 +230,11 @@ getaddrinfo (const char *restrict nodename,
|
|||
if (!(hints->ai_flags & AI_PASSIVE))
|
||||
return EAI_NONAME;
|
||||
|
||||
#ifdef HAVE_IPV6
|
||||
# ifdef HAVE_IPV6
|
||||
nodename = (hints->ai_family == AF_INET6) ? "::" : "0.0.0.0";
|
||||
#else
|
||||
# else
|
||||
nodename = "0.0.0.0";
|
||||
#endif
|
||||
# endif
|
||||
}
|
||||
|
||||
if (servname)
|
||||
|
@ -212,17 +268,17 @@ getaddrinfo (const char *restrict nodename,
|
|||
|
||||
switch (he->h_addrtype)
|
||||
{
|
||||
#if HAVE_IPV6
|
||||
# if HAVE_IPV6
|
||||
case PF_INET6:
|
||||
size = sizeof (struct v6_pair);
|
||||
break;
|
||||
#endif
|
||||
# endif
|
||||
|
||||
#if HAVE_IPV4
|
||||
# if HAVE_IPV4
|
||||
case PF_INET:
|
||||
size = sizeof (struct v4_pair);
|
||||
break;
|
||||
#endif
|
||||
# endif
|
||||
|
||||
default:
|
||||
return EAI_NODATA;
|
||||
|
@ -234,7 +290,7 @@ getaddrinfo (const char *restrict nodename,
|
|||
|
||||
switch (he->h_addrtype)
|
||||
{
|
||||
#if HAVE_IPV6
|
||||
# if HAVE_IPV6
|
||||
case PF_INET6:
|
||||
{
|
||||
struct v6_pair *p = storage;
|
||||
|
@ -256,9 +312,9 @@ getaddrinfo (const char *restrict nodename,
|
|||
tmp->ai_addrlen = sizeof *sinp;
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
# endif
|
||||
|
||||
#if HAVE_IPV4
|
||||
# if HAVE_IPV4
|
||||
case PF_INET:
|
||||
{
|
||||
struct v4_pair *p = storage;
|
||||
|
@ -280,7 +336,7 @@ getaddrinfo (const char *restrict nodename,
|
|||
tmp->ai_addrlen = sizeof *sinp;
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
# endif
|
||||
|
||||
default:
|
||||
free (storage);
|
||||
|
@ -308,21 +364,21 @@ getaddrinfo (const char *restrict nodename,
|
|||
tmp->ai_addr->sa_family = he->h_addrtype;
|
||||
tmp->ai_family = he->h_addrtype;
|
||||
|
||||
#ifdef HAVE_STRUCT_SOCKADDR_SA_LEN
|
||||
# ifdef HAVE_STRUCT_SOCKADDR_SA_LEN
|
||||
switch (he->h_addrtype)
|
||||
{
|
||||
#if HAVE_IPV4
|
||||
# if HAVE_IPV4
|
||||
case AF_INET:
|
||||
tmp->ai_addr->sa_len = sizeof (struct sockaddr_in);
|
||||
break;
|
||||
#endif
|
||||
#if HAVE_IPV6
|
||||
# endif
|
||||
# if HAVE_IPV6
|
||||
case AF_INET6:
|
||||
tmp->ai_addr->sa_len = sizeof (struct sockaddr_in6);
|
||||
break;
|
||||
#endif
|
||||
# endif
|
||||
}
|
||||
#endif
|
||||
# endif
|
||||
|
||||
/* FIXME: If more than one address, create linked list of addrinfo's. */
|
||||
|
||||
|
@ -334,14 +390,15 @@ getaddrinfo (const char *restrict nodename,
|
|||
/* Free 'addrinfo' structure AI including associated storage. */
|
||||
void
|
||||
freeaddrinfo (struct addrinfo *ai)
|
||||
#undef freeaddrinfo
|
||||
{
|
||||
#ifdef WINDOWS_NATIVE
|
||||
# ifdef WINDOWS_NATIVE
|
||||
if (use_win32_p ())
|
||||
{
|
||||
freeaddrinfo_ptr (ai);
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
# endif
|
||||
|
||||
while (ai)
|
||||
{
|
||||
|
@ -360,12 +417,13 @@ getnameinfo (const struct sockaddr *restrict sa, socklen_t salen,
|
|||
char *restrict node, socklen_t nodelen,
|
||||
char *restrict service, socklen_t servicelen,
|
||||
int flags)
|
||||
#undef getnameinfo
|
||||
{
|
||||
#ifdef WINDOWS_NATIVE
|
||||
# ifdef WINDOWS_NATIVE
|
||||
if (use_win32_p ())
|
||||
return getnameinfo_ptr (sa, salen, node, nodelen,
|
||||
service, servicelen, flags);
|
||||
#endif
|
||||
# endif
|
||||
|
||||
/* FIXME: Support other flags. */
|
||||
if ((node && nodelen > 0 && !(flags & NI_NUMERICHOST)) ||
|
||||
|
@ -378,18 +436,18 @@ getnameinfo (const struct sockaddr *restrict sa, socklen_t salen,
|
|||
|
||||
switch (sa->sa_family)
|
||||
{
|
||||
#if HAVE_IPV4
|
||||
# if HAVE_IPV4
|
||||
case AF_INET:
|
||||
if (salen < sizeof (struct sockaddr_in))
|
||||
return EAI_FAMILY;
|
||||
break;
|
||||
#endif
|
||||
#if HAVE_IPV6
|
||||
# endif
|
||||
# if HAVE_IPV6
|
||||
case AF_INET6:
|
||||
if (salen < sizeof (struct sockaddr_in6))
|
||||
return EAI_FAMILY;
|
||||
break;
|
||||
#endif
|
||||
# endif
|
||||
default:
|
||||
return EAI_FAMILY;
|
||||
}
|
||||
|
@ -398,23 +456,23 @@ getnameinfo (const struct sockaddr *restrict sa, socklen_t salen,
|
|||
{
|
||||
switch (sa->sa_family)
|
||||
{
|
||||
#if HAVE_IPV4
|
||||
# if HAVE_IPV4
|
||||
case AF_INET:
|
||||
if (!inet_ntop (AF_INET,
|
||||
&(((const struct sockaddr_in *) sa)->sin_addr),
|
||||
node, nodelen))
|
||||
return EAI_SYSTEM;
|
||||
break;
|
||||
#endif
|
||||
# endif
|
||||
|
||||
#if HAVE_IPV6
|
||||
# if HAVE_IPV6
|
||||
case AF_INET6:
|
||||
if (!inet_ntop (AF_INET6,
|
||||
&(((const struct sockaddr_in6 *) sa)->sin6_addr),
|
||||
node, nodelen))
|
||||
return EAI_SYSTEM;
|
||||
break;
|
||||
#endif
|
||||
# endif
|
||||
|
||||
default:
|
||||
return EAI_FAMILY;
|
||||
|
@ -424,12 +482,12 @@ getnameinfo (const struct sockaddr *restrict sa, socklen_t salen,
|
|||
if (service && servicelen > 0 && flags & NI_NUMERICSERV)
|
||||
switch (sa->sa_family)
|
||||
{
|
||||
#if HAVE_IPV4
|
||||
# if HAVE_IPV4
|
||||
case AF_INET:
|
||||
#endif
|
||||
#if HAVE_IPV6
|
||||
# endif
|
||||
# if HAVE_IPV6
|
||||
case AF_INET6:
|
||||
#endif
|
||||
# endif
|
||||
{
|
||||
unsigned short int port
|
||||
= ntohs (((const struct sockaddr_in *) sa)->sin_port);
|
||||
|
@ -441,3 +499,5 @@ getnameinfo (const struct sockaddr *restrict sa, socklen_t salen,
|
|||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue