1996-10-21 01:26:31 +00:00
|
|
|
/* The Inner Net License, Version 2.00
|
|
|
|
|
|
|
|
The author(s) grant permission for redistribution and use in source and
|
|
|
|
binary forms, with or without modification, of the software and documentation
|
|
|
|
provided that the following conditions are met:
|
|
|
|
|
|
|
|
0. If you receive a version of the software that is specifically labelled
|
|
|
|
as not being for redistribution (check the version message and/or README),
|
|
|
|
you are not permitted to redistribute that version of the software in any
|
|
|
|
way or form.
|
|
|
|
1. All terms of the all other applicable copyrights and licenses must be
|
|
|
|
followed.
|
|
|
|
2. Redistributions of source code must retain the authors' copyright
|
|
|
|
notice(s), this list of conditions, and the following disclaimer.
|
|
|
|
3. Redistributions in binary form must reproduce the authors' copyright
|
|
|
|
notice(s), this list of conditions, and the following disclaimer in the
|
|
|
|
documentation and/or other materials provided with the distribution.
|
2002-07-06 06:36:39 +00:00
|
|
|
4. [The copyright holder has authorized the removal of this clause.]
|
1996-10-21 01:26:31 +00:00
|
|
|
5. Neither the name(s) of the author(s) nor the names of its contributors
|
|
|
|
may be used to endorse or promote products derived from this software
|
|
|
|
without specific prior written permission.
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY ITS AUTHORS AND CONTRIBUTORS ``AS IS'' AND ANY
|
|
|
|
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY
|
|
|
|
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
|
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
|
|
|
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
If these license terms cause you a real problem, contact the author. */
|
|
|
|
|
|
|
|
/* This software is Copyright 1996 by Craig Metz, All Rights Reserved. */
|
|
|
|
|
2000-03-23 21:34:58 +00:00
|
|
|
#include <assert.h>
|
|
|
|
#include <errno.h>
|
2003-04-24 23:45:17 +00:00
|
|
|
#include <ifaddrs.h>
|
2000-03-23 21:34:58 +00:00
|
|
|
#include <netdb.h>
|
2000-05-27 08:09:40 +00:00
|
|
|
#include <resolv.h>
|
2003-04-25 17:54:19 +00:00
|
|
|
#include <stdbool.h>
|
2000-03-23 21:34:58 +00:00
|
|
|
#include <stdio.h>
|
1996-10-21 01:26:31 +00:00
|
|
|
#include <stdlib.h>
|
2000-03-23 21:34:58 +00:00
|
|
|
#include <string.h>
|
1997-02-19 04:43:53 +00:00
|
|
|
#include <unistd.h>
|
2000-03-23 21:34:58 +00:00
|
|
|
#include <arpa/inet.h>
|
1997-02-19 04:43:53 +00:00
|
|
|
#include <sys/socket.h>
|
1996-10-21 01:26:31 +00:00
|
|
|
#include <netinet/in.h>
|
2000-03-23 21:34:58 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/un.h>
|
|
|
|
#include <sys/utsname.h>
|
Update.
2000-03-24 Andreas Jaeger <aj@suse.de>
* Makefile (postclean): Added soversions.i.
2000-03-24 Scott Bambrough <scottb@netwinder.org>
* sysdeps/arm/fpu/fpu_control.h: Define _FPU_MASK_IM, _FPU_MASK_ZM,
_FPU_MASK_OM, _FPU_MASK_UM, _FPU_MASK_PM, _FPU_MASK_DM, _FPU_DEFAULT,
and _FPU_IEEE. Change _FPU_RESERVED.
2000-03-24 Scott Bambrough <scottb@netwinder.org>
* sysdeps/unix/sysv/linux/arm/sys/ucontext.h: New file.
2000-03-24 Roland McGrath <roland@baalperazim.frob.com>
* sysdeps/posix/getaddrinfo.c: Include <net/if.h> for if_nametoindex.
(gaih_inet): Remove unused duplicate variable.
* inet/getnameinfo.c (getnameinfo): Use IFNAMSIZ, not MAXHOSTNAMELEN.
Don't use __libc_sa_len, which only exists for Linux. Just handle
AF_INET and AF_INET6 directly as well as AF_LOCAL, since those are the
only flavors supported by this function anyway.
2000-03-24 Geoff Clare <gwc@unisoft.com>
* stdlib/strfmon.c: corrected problems with missing signs and
missing or extra spaces; allow for sign strings longer than
one character; add padding to ensure positive and negative
formats are aligned when a left precision is used.
2000-03-26 Ulrich Drepper <drepper@redhat.com>
* stdlib/random_r.c (__setstate_r): Allow RNGs of type 4.
Patch by John Mizel <John.Mizel@msdw.com>.
2000-03-26 18:48:26 +00:00
|
|
|
#include <net/if.h>
|
2002-11-20 19:48:07 +00:00
|
|
|
#include <nsswitch.h>
|
2003-11-18 07:04:13 +00:00
|
|
|
#include <not-cancel.h>
|
1997-02-19 04:43:53 +00:00
|
|
|
|
2004-03-13 06:53:42 +00:00
|
|
|
#ifdef HAVE_LIBIDN
|
2004-03-08 04:10:31 +00:00
|
|
|
extern int __idna_to_ascii_lz (const char *input, char **output, int flags);
|
2004-03-13 06:53:42 +00:00
|
|
|
extern int __idna_to_unicode_lzlz (const char *input, char **output,
|
|
|
|
int flags);
|
|
|
|
# include <libidn/idna.h>
|
|
|
|
#endif
|
2004-03-08 04:10:31 +00:00
|
|
|
|
1996-10-21 01:26:31 +00:00
|
|
|
#define GAIH_OKIFUNSPEC 0x0100
|
|
|
|
#define GAIH_EAI ~(GAIH_OKIFUNSPEC)
|
|
|
|
|
1997-08-20 03:53:21 +00:00
|
|
|
#ifndef UNIX_PATH_MAX
|
|
|
|
#define UNIX_PATH_MAX 108
|
|
|
|
#endif
|
1996-10-21 01:26:31 +00:00
|
|
|
|
1997-08-20 03:53:21 +00:00
|
|
|
struct gaih_service
|
|
|
|
{
|
|
|
|
const char *name;
|
|
|
|
int num;
|
|
|
|
};
|
1996-10-21 01:26:31 +00:00
|
|
|
|
1997-08-20 03:53:21 +00:00
|
|
|
struct gaih_servtuple
|
|
|
|
{
|
|
|
|
struct gaih_servtuple *next;
|
|
|
|
int socktype;
|
|
|
|
int protocol;
|
|
|
|
int port;
|
|
|
|
};
|
1996-10-21 01:26:31 +00:00
|
|
|
|
2001-01-21 19:30:28 +00:00
|
|
|
static const struct gaih_servtuple nullserv;
|
1996-10-21 01:26:31 +00:00
|
|
|
|
1997-08-20 03:53:21 +00:00
|
|
|
struct gaih_addrtuple
|
|
|
|
{
|
|
|
|
struct gaih_addrtuple *next;
|
|
|
|
int family;
|
|
|
|
char addr[16];
|
2000-03-23 21:34:58 +00:00
|
|
|
uint32_t scopeid;
|
1997-08-20 03:53:21 +00:00
|
|
|
};
|
1996-10-21 01:26:31 +00:00
|
|
|
|
1997-08-20 03:53:21 +00:00
|
|
|
struct gaih_typeproto
|
|
|
|
{
|
|
|
|
int socktype;
|
|
|
|
int protocol;
|
2001-01-21 19:30:28 +00:00
|
|
|
char name[4];
|
2000-01-05 21:32:20 +00:00
|
|
|
int protoflag;
|
1997-08-20 03:53:21 +00:00
|
|
|
};
|
1996-10-21 01:26:31 +00:00
|
|
|
|
2000-01-05 21:32:20 +00:00
|
|
|
/* Values for `protoflag'. */
|
|
|
|
#define GAI_PROTO_NOSERVICE 1
|
2000-11-10 04:15:55 +00:00
|
|
|
#define GAI_PROTO_PROTOANY 2
|
2000-01-05 21:32:20 +00:00
|
|
|
|
2001-01-21 19:30:28 +00:00
|
|
|
static const struct gaih_typeproto gaih_inet_typeproto[] =
|
1997-08-20 03:53:21 +00:00
|
|
|
{
|
2001-01-21 19:30:28 +00:00
|
|
|
{ 0, 0, "", 0 },
|
|
|
|
{ SOCK_STREAM, IPPROTO_TCP, "tcp", 0 },
|
|
|
|
{ SOCK_DGRAM, IPPROTO_UDP, "udp", 0 },
|
|
|
|
{ SOCK_RAW, 0, "raw", GAI_PROTO_PROTOANY|GAI_PROTO_NOSERVICE },
|
|
|
|
{ 0, 0, "", 0 }
|
1996-10-21 01:26:31 +00:00
|
|
|
};
|
|
|
|
|
1997-08-20 03:53:21 +00:00
|
|
|
struct gaih
|
|
|
|
{
|
|
|
|
int family;
|
|
|
|
int (*gaih)(const char *name, const struct gaih_service *service,
|
|
|
|
const struct addrinfo *req, struct addrinfo **pai);
|
|
|
|
};
|
|
|
|
|
2001-01-21 19:30:28 +00:00
|
|
|
static const struct addrinfo default_hints =
|
2003-04-24 23:45:17 +00:00
|
|
|
{
|
|
|
|
.ai_flags = AI_DEFAULT,
|
|
|
|
.ai_family = PF_UNSPEC,
|
|
|
|
.ai_socktype = 0,
|
|
|
|
.ai_protocol = 0,
|
|
|
|
.ai_addrlen = 0,
|
|
|
|
.ai_addr = NULL,
|
|
|
|
.ai_canonname = NULL,
|
|
|
|
.ai_next = NULL
|
|
|
|
};
|
1997-08-20 03:53:21 +00:00
|
|
|
|
|
|
|
|
2001-05-23 23:56:31 +00:00
|
|
|
#if 0
|
|
|
|
/* Using Unix sockets this way is a security risk. */
|
1997-08-20 03:53:21 +00:00
|
|
|
static int
|
|
|
|
gaih_local (const char *name, const struct gaih_service *service,
|
|
|
|
const struct addrinfo *req, struct addrinfo **pai)
|
1997-02-19 04:43:53 +00:00
|
|
|
{
|
|
|
|
struct utsname utsname;
|
|
|
|
|
2000-01-18 06:53:09 +00:00
|
|
|
if ((name != NULL) && (req->ai_flags & AI_NUMERICHOST))
|
|
|
|
return GAIH_OKIFUNSPEC | -EAI_NONAME;
|
|
|
|
|
1997-08-20 03:53:21 +00:00
|
|
|
if ((name != NULL) || (req->ai_flags & AI_CANONNAME))
|
2000-08-30 18:28:16 +00:00
|
|
|
if (uname (&utsname) < 0)
|
1997-02-19 04:43:53 +00:00
|
|
|
return -EAI_SYSTEM;
|
|
|
|
|
1997-08-20 03:53:21 +00:00
|
|
|
if (name != NULL)
|
|
|
|
{
|
|
|
|
if (strcmp(name, "localhost") &&
|
|
|
|
strcmp(name, "local") &&
|
|
|
|
strcmp(name, "unix") &&
|
|
|
|
strcmp(name, utsname.nodename))
|
|
|
|
return GAIH_OKIFUNSPEC | -EAI_NONAME;
|
|
|
|
}
|
|
|
|
|
1999-09-12 19:24:42 +00:00
|
|
|
if (req->ai_protocol || req->ai_socktype)
|
|
|
|
{
|
2001-01-21 19:30:28 +00:00
|
|
|
const struct gaih_typeproto *tp = gaih_inet_typeproto + 1;
|
2000-01-05 21:32:20 +00:00
|
|
|
|
2001-02-02 08:24:56 +00:00
|
|
|
while (tp->name[0]
|
2000-01-05 21:32:20 +00:00
|
|
|
&& ((tp->protoflag & GAI_PROTO_NOSERVICE) != 0
|
2000-01-18 09:56:22 +00:00
|
|
|
|| (req->ai_socktype != 0 && req->ai_socktype != tp->socktype)
|
|
|
|
|| (req->ai_protocol != 0
|
2000-11-10 04:15:55 +00:00
|
|
|
&& !(tp->protoflag & GAI_PROTO_PROTOANY)
|
2000-01-18 09:56:22 +00:00
|
|
|
&& req->ai_protocol != tp->protocol)))
|
2000-01-05 21:32:20 +00:00
|
|
|
++tp;
|
1999-09-12 19:24:42 +00:00
|
|
|
|
2001-02-02 08:24:56 +00:00
|
|
|
if (! tp->name[0])
|
1999-09-12 19:24:42 +00:00
|
|
|
{
|
|
|
|
if (req->ai_socktype)
|
|
|
|
return (GAIH_OKIFUNSPEC | -EAI_SOCKTYPE);
|
|
|
|
else
|
|
|
|
return (GAIH_OKIFUNSPEC | -EAI_SERVICE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*pai = malloc (sizeof (struct addrinfo) + sizeof (struct sockaddr_un)
|
1997-08-20 03:53:21 +00:00
|
|
|
+ ((req->ai_flags & AI_CANONNAME)
|
|
|
|
? (strlen(utsname.nodename) + 1): 0));
|
|
|
|
if (*pai == NULL)
|
1997-02-19 04:43:53 +00:00
|
|
|
return -EAI_MEMORY;
|
|
|
|
|
|
|
|
(*pai)->ai_next = NULL;
|
|
|
|
(*pai)->ai_flags = req->ai_flags;
|
|
|
|
(*pai)->ai_family = AF_LOCAL;
|
|
|
|
(*pai)->ai_socktype = req->ai_socktype ? req->ai_socktype : SOCK_STREAM;
|
|
|
|
(*pai)->ai_protocol = req->ai_protocol;
|
1999-09-12 19:24:42 +00:00
|
|
|
(*pai)->ai_addrlen = sizeof (struct sockaddr_un);
|
|
|
|
(*pai)->ai_addr = (void *) (*pai) + sizeof (struct addrinfo);
|
1997-08-20 03:53:21 +00:00
|
|
|
|
1997-02-19 04:43:53 +00:00
|
|
|
#if SALEN
|
1997-08-20 03:53:21 +00:00
|
|
|
((struct sockaddr_un *) (*pai)->ai_addr)->sun_len =
|
|
|
|
sizeof (struct sockaddr_un);
|
1997-02-19 04:43:53 +00:00
|
|
|
#endif /* SALEN */
|
1997-08-20 03:53:21 +00:00
|
|
|
|
1997-02-19 04:43:53 +00:00
|
|
|
((struct sockaddr_un *)(*pai)->ai_addr)->sun_family = AF_LOCAL;
|
|
|
|
memset(((struct sockaddr_un *)(*pai)->ai_addr)->sun_path, 0, UNIX_PATH_MAX);
|
1997-08-20 03:53:21 +00:00
|
|
|
|
|
|
|
if (service)
|
|
|
|
{
|
|
|
|
struct sockaddr_un *sunp = (struct sockaddr_un *) (*pai)->ai_addr;
|
|
|
|
|
|
|
|
if (strchr (service->name, '/') != NULL)
|
|
|
|
{
|
|
|
|
if (strlen (service->name) >= sizeof (sunp->sun_path))
|
|
|
|
return GAIH_OKIFUNSPEC | -EAI_SERVICE;
|
|
|
|
|
|
|
|
strcpy (sunp->sun_path, service->name);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (strlen (P_tmpdir "/") + 1 + strlen (service->name) >=
|
|
|
|
sizeof (sunp->sun_path))
|
|
|
|
return GAIH_OKIFUNSPEC | -EAI_SERVICE;
|
|
|
|
|
|
|
|
__stpcpy (__stpcpy (sunp->sun_path, P_tmpdir "/"), service->name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2000-09-29 02:56:42 +00:00
|
|
|
/* This is a dangerous use of the interface since there is a time
|
|
|
|
window between the test for the file and the actual creation
|
|
|
|
(done by the caller) in which a file with the same name could
|
|
|
|
be created. */
|
|
|
|
char *buf = ((struct sockaddr_un *) (*pai)->ai_addr)->sun_path;
|
|
|
|
|
|
|
|
if (__builtin_expect (__path_search (buf, L_tmpnam, NULL, NULL, 0),
|
|
|
|
0) != 0
|
|
|
|
|| __builtin_expect (__gen_tempname (buf, __GT_NOCREATE), 0) != 0)
|
1997-08-20 03:53:21 +00:00
|
|
|
return -EAI_SYSTEM;
|
|
|
|
}
|
|
|
|
|
1997-02-19 04:43:53 +00:00
|
|
|
if (req->ai_flags & AI_CANONNAME)
|
1999-09-12 19:24:42 +00:00
|
|
|
(*pai)->ai_canonname = strcpy ((char *) *pai + sizeof (struct addrinfo)
|
|
|
|
+ sizeof (struct sockaddr_un),
|
|
|
|
utsname.nodename);
|
1997-02-19 04:43:53 +00:00
|
|
|
else
|
|
|
|
(*pai)->ai_canonname = NULL;
|
|
|
|
return 0;
|
1997-08-20 03:53:21 +00:00
|
|
|
}
|
2001-05-23 23:56:31 +00:00
|
|
|
#endif /* 0 */
|
1996-10-21 01:26:31 +00:00
|
|
|
|
1997-08-20 03:53:21 +00:00
|
|
|
static int
|
2001-01-21 19:30:28 +00:00
|
|
|
gaih_inet_serv (const char *servicename, const struct gaih_typeproto *tp,
|
2000-11-10 04:15:55 +00:00
|
|
|
const struct addrinfo *req, struct gaih_servtuple *st)
|
1996-10-21 01:26:31 +00:00
|
|
|
{
|
|
|
|
struct servent *s;
|
1997-08-20 03:53:21 +00:00
|
|
|
size_t tmpbuflen = 1024;
|
1997-03-29 17:32:35 +00:00
|
|
|
struct servent ts;
|
1997-08-20 03:53:21 +00:00
|
|
|
char *tmpbuf;
|
|
|
|
int r;
|
|
|
|
|
|
|
|
do
|
1997-03-29 17:32:35 +00:00
|
|
|
{
|
1997-08-20 03:53:21 +00:00
|
|
|
tmpbuf = __alloca (tmpbuflen);
|
|
|
|
|
|
|
|
r = __getservbyname_r (servicename, tp->name, &ts, tmpbuf, tmpbuflen,
|
|
|
|
&s);
|
1999-09-12 19:24:42 +00:00
|
|
|
if (r != 0 || s == NULL)
|
1997-03-29 17:32:35 +00:00
|
|
|
{
|
1999-09-12 19:24:42 +00:00
|
|
|
if (r == ERANGE)
|
1997-08-20 03:53:21 +00:00
|
|
|
tmpbuflen *= 2;
|
|
|
|
else
|
|
|
|
return GAIH_OKIFUNSPEC | -EAI_SERVICE;
|
1997-03-29 17:32:35 +00:00
|
|
|
}
|
|
|
|
}
|
1997-08-20 03:53:21 +00:00
|
|
|
while (r);
|
1997-03-29 17:32:35 +00:00
|
|
|
|
1999-05-02 21:03:32 +00:00
|
|
|
st->next = NULL;
|
|
|
|
st->socktype = tp->socktype;
|
2000-11-10 04:15:55 +00:00
|
|
|
st->protocol = ((tp->protoflag & GAI_PROTO_PROTOANY)
|
|
|
|
? req->ai_protocol : tp->protocol);
|
1999-05-02 21:03:32 +00:00
|
|
|
st->port = s->s_port;
|
1996-10-21 01:26:31 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-04-24 23:45:17 +00:00
|
|
|
#define gethosts(_family, _type) \
|
|
|
|
{ \
|
|
|
|
int i, herrno; \
|
|
|
|
size_t tmpbuflen; \
|
|
|
|
struct hostent th; \
|
|
|
|
char *tmpbuf = NULL; \
|
|
|
|
tmpbuflen = 512; \
|
|
|
|
no_data = 0; \
|
|
|
|
do { \
|
|
|
|
tmpbuf = extend_alloca (tmpbuf, tmpbuflen, 2 * tmpbuflen); \
|
|
|
|
rc = __gethostbyname2_r (name, _family, &th, tmpbuf, \
|
|
|
|
tmpbuflen, &h, &herrno); \
|
|
|
|
} while (rc == ERANGE && herrno == NETDB_INTERNAL); \
|
|
|
|
if (rc != 0) \
|
|
|
|
{ \
|
|
|
|
if (herrno == NETDB_INTERNAL) \
|
|
|
|
{ \
|
|
|
|
__set_h_errno (herrno); \
|
|
|
|
return -EAI_SYSTEM; \
|
|
|
|
} \
|
|
|
|
if (herrno == TRY_AGAIN) \
|
|
|
|
no_data = EAI_AGAIN; \
|
|
|
|
else \
|
|
|
|
no_data = herrno == NO_DATA; \
|
|
|
|
} \
|
|
|
|
else if (h != NULL) \
|
|
|
|
{ \
|
|
|
|
for (i = 0; h->h_addr_list[i]; i++) \
|
|
|
|
{ \
|
|
|
|
if (*pat == NULL) { \
|
|
|
|
*pat = __alloca (sizeof (struct gaih_addrtuple)); \
|
|
|
|
(*pat)->scopeid = 0; \
|
|
|
|
} \
|
|
|
|
(*pat)->next = NULL; \
|
|
|
|
(*pat)->family = _family; \
|
|
|
|
memcpy ((*pat)->addr, h->h_addr_list[i], \
|
|
|
|
sizeof(_type)); \
|
|
|
|
pat = &((*pat)->next); \
|
|
|
|
} \
|
|
|
|
if (_family == AF_INET6) \
|
|
|
|
got_ipv6 = true; \
|
|
|
|
} \
|
|
|
|
else if (_family == AF_INET6 && (req->ai_flags & AI_V4MAPPED)) \
|
|
|
|
{ \
|
|
|
|
/* We have to add V4 mapped addresses. Maybe we discard them \
|
|
|
|
later again but we get them anyhow for now. */ \
|
|
|
|
while ((rc = __gethostbyname2_r (name, AF_INET6, &th, tmpbuf, \
|
|
|
|
tmpbuflen, &h, &herrno)) == ERANGE \
|
|
|
|
&& herrno == NETDB_INTERNAL) \
|
|
|
|
tmpbuf = extend_alloca (tmpbuf, tmpbuflen, 2 * tmpbuflen); \
|
|
|
|
\
|
|
|
|
if (rc != 0) \
|
|
|
|
{ \
|
|
|
|
if (herrno == NETDB_INTERNAL) \
|
|
|
|
{ \
|
|
|
|
__set_h_errno (herrno); \
|
|
|
|
return -EAI_SYSTEM; \
|
|
|
|
} \
|
|
|
|
if (herrno == TRY_AGAIN) \
|
|
|
|
no_data = EAI_AGAIN; \
|
|
|
|
else \
|
|
|
|
no_data = herrno == NO_DATA; \
|
|
|
|
} \
|
|
|
|
else if (h != NULL) \
|
|
|
|
{ \
|
|
|
|
for (i = 0; h->h_addr_list[i]; ++i) \
|
|
|
|
{ \
|
|
|
|
if (*pat == NULL) \
|
|
|
|
{ \
|
|
|
|
*pat = __alloca (sizeof (struct gaih_addrtuple)); \
|
|
|
|
(*pat)->scopeid = 0; \
|
|
|
|
} \
|
|
|
|
uint32_t *addr = (uint32_t *) (*pat)->addr; \
|
|
|
|
(*pat)->next = NULL; \
|
|
|
|
(*pat)->family = _family; \
|
|
|
|
addr[3] = *(uint32_t *) h->h_addr_list[i]; \
|
|
|
|
addr[2] = htonl (0xffff); \
|
|
|
|
addr[1] = 0; \
|
|
|
|
addr[0] = 0; \
|
|
|
|
pat = &((*pat)->next); \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
} \
|
1997-08-20 03:53:21 +00:00
|
|
|
}
|
|
|
|
|
2003-04-24 23:45:17 +00:00
|
|
|
|
|
|
|
#define gethosts2(_family, _type) \
|
|
|
|
{ \
|
|
|
|
int i, herrno; \
|
|
|
|
size_t tmpbuflen; \
|
|
|
|
struct hostent th; \
|
|
|
|
char *tmpbuf = NULL; \
|
|
|
|
tmpbuflen = 512; \
|
|
|
|
no_data = 0; \
|
|
|
|
do { \
|
|
|
|
tmpbuf = extend_alloca (tmpbuf, tmpbuflen, 2 * tmpbuflen); \
|
|
|
|
rc = 0; \
|
|
|
|
status = DL_CALL_FCT (fct, (name, _family, &th, tmpbuf, \
|
|
|
|
tmpbuflen, &rc, &herrno)); \
|
|
|
|
} while (rc == ERANGE && herrno == NETDB_INTERNAL); \
|
|
|
|
if (status == NSS_STATUS_SUCCESS && rc == 0) \
|
|
|
|
h = &th; \
|
|
|
|
else \
|
|
|
|
h = NULL; \
|
|
|
|
if (rc != 0) \
|
|
|
|
{ \
|
|
|
|
if (herrno == NETDB_INTERNAL) \
|
|
|
|
{ \
|
|
|
|
__set_h_errno (herrno); \
|
|
|
|
return -EAI_SYSTEM; \
|
|
|
|
} \
|
|
|
|
if (herrno == TRY_AGAIN) \
|
|
|
|
no_data = EAI_AGAIN; \
|
|
|
|
else \
|
|
|
|
no_data = herrno == NO_DATA; \
|
|
|
|
} \
|
|
|
|
else if (h != NULL) \
|
|
|
|
{ \
|
|
|
|
for (i = 0; h->h_addr_list[i]; i++) \
|
|
|
|
{ \
|
|
|
|
if (*pat == NULL) { \
|
|
|
|
*pat = __alloca (sizeof (struct gaih_addrtuple)); \
|
|
|
|
(*pat)->scopeid = 0; \
|
|
|
|
} \
|
|
|
|
(*pat)->next = NULL; \
|
|
|
|
(*pat)->family = _family; \
|
|
|
|
memcpy ((*pat)->addr, h->h_addr_list[i], \
|
|
|
|
sizeof(_type)); \
|
|
|
|
pat = &((*pat)->next); \
|
|
|
|
} \
|
|
|
|
} \
|
2002-11-20 19:48:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
typedef enum nss_status (*nss_gethostbyname2_r)
|
|
|
|
(const char *name, int af, struct hostent *host,
|
|
|
|
char *buffer, size_t buflen, int *errnop,
|
|
|
|
int *h_errnop);
|
|
|
|
extern service_user *__nss_hosts_database attribute_hidden;
|
|
|
|
|
1997-08-20 03:53:21 +00:00
|
|
|
static int
|
|
|
|
gaih_inet (const char *name, const struct gaih_service *service,
|
|
|
|
const struct addrinfo *req, struct addrinfo **pai)
|
1996-10-21 01:26:31 +00:00
|
|
|
{
|
2001-01-21 19:30:28 +00:00
|
|
|
const struct gaih_typeproto *tp = gaih_inet_typeproto;
|
|
|
|
struct gaih_servtuple *st = (struct gaih_servtuple *) &nullserv;
|
1997-02-19 04:43:53 +00:00
|
|
|
struct gaih_addrtuple *at = NULL;
|
1997-08-20 03:53:21 +00:00
|
|
|
int rc;
|
2003-04-24 23:45:17 +00:00
|
|
|
bool got_ipv6 = false;
|
1996-10-21 01:26:31 +00:00
|
|
|
|
1997-08-20 03:53:21 +00:00
|
|
|
if (req->ai_protocol || req->ai_socktype)
|
|
|
|
{
|
2000-01-05 21:32:20 +00:00
|
|
|
++tp;
|
|
|
|
|
2001-02-02 08:24:56 +00:00
|
|
|
while (tp->name[0]
|
2000-01-18 09:56:22 +00:00
|
|
|
&& ((req->ai_socktype != 0 && req->ai_socktype != tp->socktype)
|
|
|
|
|| (req->ai_protocol != 0
|
2000-11-10 04:15:55 +00:00
|
|
|
&& !(tp->protoflag & GAI_PROTO_PROTOANY)
|
2000-01-18 09:56:22 +00:00
|
|
|
&& req->ai_protocol != tp->protocol)))
|
2000-01-05 21:32:20 +00:00
|
|
|
++tp;
|
|
|
|
|
2001-02-02 08:24:56 +00:00
|
|
|
if (! tp->name[0])
|
1998-09-09 11:53:19 +00:00
|
|
|
{
|
|
|
|
if (req->ai_socktype)
|
|
|
|
return (GAIH_OKIFUNSPEC | -EAI_SOCKTYPE);
|
|
|
|
else
|
|
|
|
return (GAIH_OKIFUNSPEC | -EAI_SERVICE);
|
|
|
|
}
|
1997-08-20 03:53:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (service != NULL)
|
|
|
|
{
|
2000-01-05 21:32:20 +00:00
|
|
|
if ((tp->protoflag & GAI_PROTO_NOSERVICE) != 0)
|
|
|
|
return (GAIH_OKIFUNSPEC | -EAI_SERVICE);
|
|
|
|
|
1997-08-20 03:53:21 +00:00
|
|
|
if (service->num < 0)
|
|
|
|
{
|
2001-02-02 08:24:56 +00:00
|
|
|
if (tp->name[0])
|
1997-08-20 03:53:21 +00:00
|
|
|
{
|
1999-05-02 21:03:32 +00:00
|
|
|
st = (struct gaih_servtuple *)
|
|
|
|
__alloca (sizeof (struct gaih_servtuple));
|
|
|
|
|
2000-11-10 04:15:55 +00:00
|
|
|
if ((rc = gaih_inet_serv (service->name, tp, req, st)))
|
1997-08-20 03:53:21 +00:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
struct gaih_servtuple **pst = &st;
|
2001-02-02 08:24:56 +00:00
|
|
|
for (tp++; tp->name[0]; tp++)
|
1997-08-20 03:53:21 +00:00
|
|
|
{
|
2000-01-18 09:56:22 +00:00
|
|
|
struct gaih_servtuple *newp;
|
|
|
|
|
|
|
|
if ((tp->protoflag & GAI_PROTO_NOSERVICE) != 0)
|
|
|
|
continue;
|
|
|
|
|
2000-09-29 05:29:24 +00:00
|
|
|
if (req->ai_socktype != 0
|
|
|
|
&& req->ai_socktype != tp->socktype)
|
|
|
|
continue;
|
2000-11-10 04:15:55 +00:00
|
|
|
if (req->ai_protocol != 0
|
|
|
|
&& !(tp->protoflag & GAI_PROTO_PROTOANY)
|
|
|
|
&& req->ai_protocol != tp->protocol)
|
|
|
|
continue;
|
2000-09-29 05:29:24 +00:00
|
|
|
|
2000-01-18 09:56:22 +00:00
|
|
|
newp = (struct gaih_servtuple *)
|
1999-05-02 21:03:32 +00:00
|
|
|
__alloca (sizeof (struct gaih_servtuple));
|
|
|
|
|
2000-11-10 04:15:55 +00:00
|
|
|
if ((rc = gaih_inet_serv (service->name, tp, req, newp)))
|
1997-08-20 03:53:21 +00:00
|
|
|
{
|
|
|
|
if (rc & GAIH_OKIFUNSPEC)
|
|
|
|
continue;
|
|
|
|
return rc;
|
|
|
|
}
|
1999-05-02 21:03:32 +00:00
|
|
|
|
|
|
|
*pst = newp;
|
|
|
|
pst = &(newp->next);
|
1997-08-20 03:53:21 +00:00
|
|
|
}
|
2001-01-21 19:30:28 +00:00
|
|
|
if (st == (struct gaih_servtuple *) &nullserv)
|
1997-08-20 03:53:21 +00:00
|
|
|
return (GAIH_OKIFUNSPEC | -EAI_SERVICE);
|
|
|
|
}
|
1996-10-21 01:26:31 +00:00
|
|
|
}
|
1997-08-20 03:53:21 +00:00
|
|
|
else
|
|
|
|
{
|
1999-09-12 19:24:42 +00:00
|
|
|
st = __alloca (sizeof (struct gaih_servtuple));
|
1997-08-20 03:53:21 +00:00
|
|
|
st->next = NULL;
|
|
|
|
st->socktype = tp->socktype;
|
2000-11-10 04:15:55 +00:00
|
|
|
st->protocol = ((tp->protoflag & GAI_PROTO_PROTOANY)
|
|
|
|
? req->ai_protocol : tp->protocol);
|
1997-08-20 03:53:21 +00:00
|
|
|
st->port = htons (service->num);
|
1996-10-21 01:26:31 +00:00
|
|
|
}
|
1997-08-20 03:53:21 +00:00
|
|
|
}
|
2000-09-29 05:29:24 +00:00
|
|
|
else if (req->ai_socktype || req->ai_protocol)
|
|
|
|
{
|
|
|
|
st = __alloca (sizeof (struct gaih_servtuple));
|
|
|
|
st->next = NULL;
|
2000-11-10 04:15:55 +00:00
|
|
|
st->socktype = tp->socktype;
|
|
|
|
st->protocol = ((tp->protoflag & GAI_PROTO_PROTOANY)
|
|
|
|
? req->ai_protocol : tp->protocol);
|
2000-09-29 05:29:24 +00:00
|
|
|
st->port = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Neither socket type nor protocol is set. Return all socket types
|
|
|
|
we know about. */
|
|
|
|
struct gaih_servtuple **lastp = &st;
|
2001-02-02 08:24:56 +00:00
|
|
|
for (++tp; tp->name[0]; ++tp)
|
2000-09-29 05:29:24 +00:00
|
|
|
{
|
|
|
|
struct gaih_servtuple *newp;
|
|
|
|
|
|
|
|
newp = __alloca (sizeof (struct gaih_servtuple));
|
|
|
|
newp->next = NULL;
|
|
|
|
newp->socktype = tp->socktype;
|
|
|
|
newp->protocol = tp->protocol;
|
|
|
|
newp->port = 0;
|
|
|
|
|
|
|
|
*lastp = newp;
|
|
|
|
lastp = &newp->next;
|
|
|
|
}
|
|
|
|
}
|
1997-08-20 03:53:21 +00:00
|
|
|
|
|
|
|
if (name != NULL)
|
|
|
|
{
|
1999-09-12 19:24:42 +00:00
|
|
|
at = __alloca (sizeof (struct gaih_addrtuple));
|
1996-10-21 01:26:31 +00:00
|
|
|
|
1999-09-12 19:24:42 +00:00
|
|
|
at->family = AF_UNSPEC;
|
2000-03-23 21:34:58 +00:00
|
|
|
at->scopeid = 0;
|
1997-08-20 03:53:21 +00:00
|
|
|
at->next = NULL;
|
1996-10-21 01:26:31 +00:00
|
|
|
|
2004-03-08 04:10:31 +00:00
|
|
|
#ifdef HAVE_LIBIDN
|
|
|
|
if (req->ai_flags & AI_IDN)
|
|
|
|
{
|
2004-03-17 20:02:19 +00:00
|
|
|
int idn_flags = 0;
|
|
|
|
if (req->ai_flags & AI_IDN_ALLOW_UNASSIGNED)
|
|
|
|
idn_flags |= IDNA_ALLOW_UNASSIGNED;
|
|
|
|
if (req->ai_flags & AI_IDN_USE_STD3_ASCII_RULES)
|
|
|
|
idn_flags |= IDNA_USE_STD3_ASCII_RULES;
|
|
|
|
|
2004-03-08 04:10:31 +00:00
|
|
|
char *p = NULL;
|
2004-03-17 20:02:19 +00:00
|
|
|
rc = __idna_to_ascii_lz (name, &p, idn_flags);
|
2004-03-08 04:10:31 +00:00
|
|
|
if (rc != IDNA_SUCCESS)
|
2004-03-13 06:53:42 +00:00
|
|
|
{
|
|
|
|
if (rc == IDNA_MALLOC_ERROR)
|
|
|
|
return -EAI_MEMORY;
|
|
|
|
if (rc == IDNA_DLOPEN_ERROR)
|
|
|
|
return -EAI_SYSTEM;
|
|
|
|
return -EAI_IDN_ENCODE;
|
|
|
|
}
|
|
|
|
/* In case the output string is the same as the input string
|
|
|
|
no new string has been allocated. */
|
|
|
|
if (p != name)
|
|
|
|
{
|
|
|
|
name = strdupa (p);
|
|
|
|
free (p);
|
|
|
|
}
|
2004-03-08 04:10:31 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1999-09-12 19:24:42 +00:00
|
|
|
if (inet_pton (AF_INET, name, at->addr) > 0)
|
|
|
|
{
|
|
|
|
if (req->ai_family == AF_UNSPEC || req->ai_family == AF_INET)
|
|
|
|
at->family = AF_INET;
|
2003-04-24 23:45:17 +00:00
|
|
|
else if (req->ai_flags & AI_V4MAPPED)
|
|
|
|
{
|
|
|
|
((uint32_t *) at->addr)[3] = *(uint32_t *) at->addr;
|
|
|
|
((uint32_t *) at->addr)[2] = htonl (0xffff);
|
|
|
|
((uint32_t *) at->addr)[1] = 0;
|
|
|
|
((uint32_t *) at->addr)[0] = 0;
|
|
|
|
}
|
1999-09-12 19:24:42 +00:00
|
|
|
else
|
|
|
|
return -EAI_ADDRFAMILY;
|
|
|
|
}
|
1996-10-21 01:26:31 +00:00
|
|
|
|
2000-03-23 21:34:58 +00:00
|
|
|
if (at->family == AF_UNSPEC)
|
1999-09-12 19:24:42 +00:00
|
|
|
{
|
2000-03-23 21:34:58 +00:00
|
|
|
char *namebuf = strdupa (name);
|
|
|
|
char *scope_delim;
|
|
|
|
|
|
|
|
scope_delim = strchr (namebuf, SCOPE_DELIMITER);
|
|
|
|
if (scope_delim != NULL)
|
|
|
|
*scope_delim = '\0';
|
|
|
|
|
|
|
|
if (inet_pton (AF_INET6, namebuf, at->addr) > 0)
|
|
|
|
{
|
|
|
|
if (req->ai_family == AF_UNSPEC || req->ai_family == AF_INET6)
|
|
|
|
at->family = AF_INET6;
|
2003-04-24 23:45:17 +00:00
|
|
|
else if (IN6_IS_ADDR_V4MAPPED (at->addr))
|
|
|
|
*(uint32_t *) at->addr = ((uint32_t *) at->addr)[3];
|
2000-03-23 21:34:58 +00:00
|
|
|
else
|
|
|
|
return -EAI_ADDRFAMILY;
|
|
|
|
|
|
|
|
if (scope_delim != NULL)
|
|
|
|
{
|
|
|
|
int try_numericscope = 0;
|
|
|
|
if (IN6_IS_ADDR_LINKLOCAL (at->addr)
|
|
|
|
|| IN6_IS_ADDR_MC_LINKLOCAL (at->addr))
|
|
|
|
{
|
|
|
|
at->scopeid = if_nametoindex (scope_delim + 1);
|
|
|
|
if (at->scopeid == 0)
|
|
|
|
try_numericscope = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
try_numericscope = 1;
|
|
|
|
|
|
|
|
if (try_numericscope != 0)
|
|
|
|
{
|
|
|
|
char *end;
|
|
|
|
assert (sizeof (uint32_t) <= sizeof (unsigned long));
|
|
|
|
at->scopeid = (uint32_t) strtoul (scope_delim + 1, &end,
|
|
|
|
10);
|
|
|
|
if (*end != '\0')
|
|
|
|
return GAIH_OKIFUNSPEC | -EAI_NONAME;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1999-09-12 19:24:42 +00:00
|
|
|
}
|
1997-08-20 03:53:21 +00:00
|
|
|
|
2000-01-12 11:39:14 +00:00
|
|
|
if (at->family == AF_UNSPEC && (req->ai_flags & AI_NUMERICHOST) == 0)
|
1997-08-20 03:53:21 +00:00
|
|
|
{
|
|
|
|
struct hostent *h;
|
|
|
|
struct gaih_addrtuple **pat = &at;
|
1999-09-12 19:24:42 +00:00
|
|
|
int no_data = 0;
|
2002-11-20 19:48:07 +00:00
|
|
|
int no_inet6_data = 0;
|
2000-05-27 08:09:40 +00:00
|
|
|
/* If we are looking for both IPv4 and IPv6 address we don't
|
|
|
|
want the lookup functions to automatically promote IPv4
|
|
|
|
addresses to IPv6 addresses. Currently this is decided
|
|
|
|
by setting the RES_USE_INET6 bit in _res.options. */
|
|
|
|
if (req->ai_family == AF_UNSPEC)
|
2002-11-20 19:48:07 +00:00
|
|
|
{
|
|
|
|
service_user *nip = NULL;
|
|
|
|
enum nss_status inet6_status, status = NSS_STATUS_UNAVAIL;
|
|
|
|
int no_more;
|
|
|
|
nss_gethostbyname2_r fct;
|
2004-02-23 19:54:06 +00:00
|
|
|
int old_res_options;
|
1997-08-20 03:53:21 +00:00
|
|
|
|
2002-11-20 19:48:07 +00:00
|
|
|
if (__nss_hosts_database != NULL)
|
|
|
|
{
|
|
|
|
no_more = 0;
|
|
|
|
nip = __nss_hosts_database;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
no_more = __nss_database_lookup ("hosts", NULL,
|
|
|
|
"dns [!UNAVAIL=return] files", &nip);
|
1997-08-20 03:53:21 +00:00
|
|
|
|
2004-02-23 19:54:06 +00:00
|
|
|
if ((_res.options & RES_INIT) == 0 && __res_ninit(&_res) == -1)
|
|
|
|
no_more = 1;
|
|
|
|
old_res_options = _res.options;
|
2002-11-20 19:48:07 +00:00
|
|
|
_res.options &= ~RES_USE_INET6;
|
2000-05-27 08:09:40 +00:00
|
|
|
|
2002-11-20 19:48:07 +00:00
|
|
|
while (!no_more)
|
|
|
|
{
|
|
|
|
fct = __nss_lookup_function (nip, "gethostbyname2_r");
|
|
|
|
|
2002-12-17 01:16:31 +00:00
|
|
|
if (fct != NULL)
|
|
|
|
{
|
|
|
|
gethosts2 (AF_INET6, struct in6_addr);
|
|
|
|
no_inet6_data = no_data;
|
|
|
|
inet6_status = status;
|
|
|
|
gethosts2 (AF_INET, struct in_addr);
|
|
|
|
|
|
|
|
/* If we found one address for AF_INET or AF_INET6,
|
|
|
|
don't continue the search. */
|
|
|
|
if (inet6_status == NSS_STATUS_SUCCESS ||
|
|
|
|
status == NSS_STATUS_SUCCESS)
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* We can have different states for AF_INET
|
|
|
|
and AF_INET6. Try to find a usefull one for
|
|
|
|
both. */
|
|
|
|
if (inet6_status == NSS_STATUS_TRYAGAIN)
|
|
|
|
status = NSS_STATUS_TRYAGAIN;
|
|
|
|
else if (status == NSS_STATUS_UNAVAIL &&
|
|
|
|
inet6_status != NSS_STATUS_UNAVAIL)
|
|
|
|
status = inet6_status;
|
|
|
|
}
|
2002-11-20 19:48:07 +00:00
|
|
|
|
|
|
|
if (nss_next_action (nip, status) == NSS_ACTION_RETURN)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (nip->next == NULL)
|
|
|
|
no_more = -1;
|
|
|
|
else
|
|
|
|
nip = nip->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
_res.options = old_res_options;
|
|
|
|
}
|
|
|
|
else if (req->ai_family == AF_INET6)
|
|
|
|
{
|
|
|
|
gethosts (AF_INET6, struct in6_addr);
|
|
|
|
no_inet6_data = no_data;
|
|
|
|
}
|
|
|
|
else if (req->ai_family == AF_INET)
|
2003-06-12 22:31:43 +00:00
|
|
|
{
|
|
|
|
gethosts (AF_INET, struct in_addr);
|
|
|
|
no_inet6_data = no_data;
|
|
|
|
}
|
1999-09-12 19:24:42 +00:00
|
|
|
|
1999-12-08 09:15:00 +00:00
|
|
|
if (no_data != 0 && no_inet6_data != 0)
|
2000-11-18 08:30:20 +00:00
|
|
|
{
|
|
|
|
/* If both requests timed out report this. */
|
|
|
|
if (no_data == EAI_AGAIN && no_inet6_data == EAI_AGAIN)
|
|
|
|
return -EAI_AGAIN;
|
|
|
|
|
|
|
|
/* We made requests but they turned out no data. The name
|
|
|
|
is known, though. */
|
|
|
|
return (GAIH_OKIFUNSPEC | -EAI_NODATA);
|
|
|
|
}
|
1996-10-21 01:26:31 +00:00
|
|
|
}
|
1997-08-20 03:53:21 +00:00
|
|
|
|
|
|
|
if (at->family == AF_UNSPEC)
|
|
|
|
return (GAIH_OKIFUNSPEC | -EAI_NONAME);
|
1996-10-21 01:26:31 +00:00
|
|
|
}
|
1997-08-20 03:53:21 +00:00
|
|
|
else
|
|
|
|
{
|
1999-07-28 03:27:45 +00:00
|
|
|
struct gaih_addrtuple *atr;
|
1999-09-12 19:24:42 +00:00
|
|
|
atr = at = __alloca (sizeof (struct gaih_addrtuple));
|
|
|
|
memset (at, '\0', sizeof (struct gaih_addrtuple));
|
1997-08-20 03:53:21 +00:00
|
|
|
|
1999-07-28 03:27:45 +00:00
|
|
|
if (req->ai_family == 0)
|
|
|
|
{
|
1999-09-12 19:24:42 +00:00
|
|
|
at->next = __alloca (sizeof (struct gaih_addrtuple));
|
|
|
|
memset (at->next, '\0', sizeof (struct gaih_addrtuple));
|
1999-07-28 03:27:45 +00:00
|
|
|
}
|
1997-08-20 03:53:21 +00:00
|
|
|
|
1999-07-28 03:27:45 +00:00
|
|
|
if (req->ai_family == 0 || req->ai_family == AF_INET6)
|
|
|
|
{
|
|
|
|
at->family = AF_INET6;
|
|
|
|
if ((req->ai_flags & AI_PASSIVE) == 0)
|
* sysdeps/posix/system.c (do_system): New function, guts broken out of
__libc_system.
(__libc_system): Call it, putting just the line == NULL test here.
* include/libc-symbols.h (__hidden_proto): Add extern keywords so
variables work right.
* elf/dl-open.c (dl_open_worker): Use _ macro instead of gettext.
* elf/dl-close.c (_dl_close): Likewise.
* include/netinet/in.h: Use libc_hidden_proto for bindresvport,
in6addr_any, in6addr_loopback. Remove decls for
bindresvport_internal, in6addr_any_internal, in6addr_loopback_internal.
* sunrpc/svc_udp.c (svcudp_bufcreate): Nix INTUSE for bindresvport.
* sunrpc/svc_tcp.c (svctcp_create): Likewise.
* sunrpc/clnt_udp.c (clntudp_bufcreate): Likewise.
* sunrpc/bindrsvprt.c: Change INTDEF to libc_hidden_def.
* inet/in6_addr.c: Change INTVARDEF to libc_hidden_def.
* sysdeps/posix/getaddrinfo.c (gaih_inet): Nix INTUSE for
in6addr_loopback.
* inet/gethstbyad_r.c (PREPROCESS): Nix INTUSE for in6addr_any.
* include/netinet/ether.h: Use libc_hidden_proto for ether_ntoa_r,
ether_aton_r.
* inet/ether_aton_r.c: Add libc_hidden_def.
* inet/ether_ntoa_r.c: Likewise.
* include/rpc/auth.h: Use libc_hidden_proto for getnetname,
netname2user, host2netname.
* sunrpc/netname.c: Add libc_hidden_def.
* include/netdb.h: Use libc_hidden_proto for innetgr, rcmd_af,
rexec_af, rresvport_af, ruserok_af.
* inet/rcmd.c: Add libc_hidden_def.
* inet/getnetgrent_r.c: Likewise.
2002-08-06 04:30:03 +00:00
|
|
|
memcpy (at->addr, &in6addr_loopback, sizeof (struct in6_addr));
|
1999-07-28 03:27:45 +00:00
|
|
|
atr = at->next;
|
|
|
|
}
|
1997-08-20 03:53:21 +00:00
|
|
|
|
1999-07-28 03:27:45 +00:00
|
|
|
if (req->ai_family == 0 || req->ai_family == AF_INET)
|
|
|
|
{
|
|
|
|
atr->family = AF_INET;
|
|
|
|
if ((req->ai_flags & AI_PASSIVE) == 0)
|
|
|
|
*(uint32_t *) atr->addr = htonl (INADDR_LOOPBACK);
|
|
|
|
}
|
1996-10-21 01:26:31 +00:00
|
|
|
}
|
1997-02-19 04:43:53 +00:00
|
|
|
|
1997-08-20 03:53:21 +00:00
|
|
|
if (pai == NULL)
|
|
|
|
return 0;
|
1996-10-21 01:26:31 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
const char *c = NULL;
|
|
|
|
struct gaih_servtuple *st2;
|
|
|
|
struct gaih_addrtuple *at2 = at;
|
1997-08-20 03:53:21 +00:00
|
|
|
size_t socklen, namelen;
|
2000-11-10 04:15:55 +00:00
|
|
|
sa_family_t family;
|
1997-08-20 03:53:21 +00:00
|
|
|
|
Update.
1997-07-13 01:18 Ulrich Drepper <drepper@cygnus.com>
* setjmp/setjmp.h: Define _setjmp and _longjmp also if __USE_XOPEN.
* sysdeps/unix/sysv/linux/bits/ipc.h: Fix comment.
* sysdeps/unix/sysv/linux/bits/msq.h: Likewise.
* sysdeps/unix/sysv/linux/bits/sem.h: Likewise.
* sysdeps/unix/sysv/linux/bits/shm.h: Likewise.
* time/Makefile (routines): Add getdate.
* time/time.h: Add prototype for getdate and getdate_r.
* time/getdate.c: New file.
Provided by Mark Kettenis <kettenis@phys.uva.nl>.
1997-06-30 14:49 H.J. Lu <hjl@gnu.ai.mit.edu>
From Ralf Baechle <ralf@informatik.uni-koblenz.de> on
Sat Jun 21 18:11:21 1997:
* sysdeps/unix/sysv/linux/syscalls.list (swapon): Add __swapon alias.
(swapoff): New.
* elf/Makefile: Add linker script support.
(headers): Add bits/dlfcn.h.
* elf/dl-load.c (MAP_BASE_ADDR): New.
* elf/dlfcn.h: Include <bits/dlfcn.h>.
* elf/elf.h: Add MIPS support.
* sysdeps/generic/Dist: Add entry.h.
* sysdeps/generic/entry.h: New, define the entry symbol.
* elf/rtld.c (_start): Include <entry.h>. Change to ENTRY_POINT.
* sysdeps/generic/dl-sysdep.c (_start): Likewise.
* mips/elf/start.S (_start): Likewise.
* sysdeps/mips/bsd-_setjmp.S: Fix PIC.
* sysdeps/mips/bsd-setjmp.S: Likewise.
* sysdeps/mips/setjmp.S: Likewise.
* mips/elf/start.S: Likewise.
* sysdeps/unix/mips/brk.S: Likewise.
* sysdeps/unix/mips/sysdep.S: Likewise.
* sysdeps/unix/mips/sysdep.h: Likewise.
* sysdeps/unix/mips/wait.S: Likewise.
* sysdeps/mips/dl-machine.h: Update for Linux/MIPS.
* sysdeps/mips/fpu_control.h: Likewise.
* sysdeps/generic/bits/dlfcn.h: New file.
* sysdeps/mips/rtld-ldscript.in: New for Linux/MIPS.
* sysdeps/mips/rtld-parms: Likewise.
* sysdeps/mips/bits/dlfcn.h: Likewise.
* sysdeps/mips/mips64/rtld-parms: Likewise.
* sysdeps/mips/mipsel/rtld-parms: Likewise.
* sysdeps/unix/sysv/linux/mips/Dist: Likewise.
* sysdeps/unix/sysv/linux/mips/Makefile: Likewise.
* sysdeps/unix/sysv/linux/mips/clone.S: Likewise.
* sysdeps/unix/sysv/linux/mips/entry.h: Likewise.
* sysdeps/unix/sysv/linux/mips/fpregdef.h: Likewise.
* sysdeps/unix/sysv/linux/mips/fxstat.c: Likewise.
* sysdeps/unix/sysv/linux/mips/kernel_sigaction.h: Likewise.
* sysdeps/unix/sysv/linux/mips/kernel_stat.h: Likewise.
* sysdeps/unix/sysv/linux/mips/kernel_termios.h: Likewise.
* sysdeps/unix/sysv/linux/mips/lxstat.c: Likewise.
* sysdeps/unix/sysv/linux/mips/regdef.h: Likewise.
* sysdeps/unix/sysv/linux/mips/sgidefs.h: Likewise.
* sysdeps/unix/sysv/linux/mips/syscalls.list: Likewise.
* sysdeps/unix/sysv/linux/mips/ustat.c: Likewise.
* sysdeps/unix/sysv/linux/mips/xmknod.c: Likewise.
* sysdeps/unix/sysv/linux/mips/xstat.c: Likewise.
* sysdeps/unix/sysv/linux/mips/bits/endian.h: Likewise.
* sysdeps/unix/sysv/linux/mips/bits/fcntl.h: Likewise.
* sysdeps/unix/sysv/linux/mips/bits/ioctl-types.h:
* sysdeps/unix/sysv/linux/mips/bits/ipc.h: Likewise.
* sysdeps/unix/sysv/linux/mips/bits/shm.h: Likewise.
* sysdeps/unix/sysv/linux/mips/bits/sigaction.h: Likewise.
* sysdeps/unix/sysv/linux/mips/bits/signum.h: Likewise.
* sysdeps/unix/sysv/linux/mips/bits/socket.h: Likewise.
* sysdeps/unix/sysv/linux/mips/bits/stat.h: Likewise.
* sysdeps/unix/sysv/linux/mips/bits/statfs.h: Likewise.
* sysdeps/unix/sysv/linux/mips/bits/termios.h: Likewise.
* sysdeps/unix/sysv/linux/mips/bits/time.h: Likewise.
* sysdeps/unix/sysv/linux/mips/sys/acct.h: Likewise.
* sysdeps/unix/sysv/linux/mips/sys/asm.h: Likewise.
* sysdeps/unix/sysv/linux/mips/sys/cachectl.h: Likewise.
* sysdeps/unix/sysv/linux/mips/sys/fpregdef.h: Likewise.
* sysdeps/unix/sysv/linux/mips/sys/procfs.h: Likewise.
* sysdeps/unix/sysv/linux/mips/sys/regdef.h: Likewise.
* sysdeps/unix/sysv/linux/mips/sys/syscall.h: Likewise.
* sysdeps/unix/sysv/linux/mips/sys/sysmips.h: Likewise.
1997-04-09 19:05 H.J. Lu (hjl@gnu.ai.mit.edu)
* isomac.c (xstrndup): New, use it instead of strndup ().
1997-07-02 08:55 H.J. Lu <hjl@gnu.ai.mit.edu>
* sysdeps/i386/dl-machine.h (elf_machine_rel): Print
the program name for different sizes.
1997-07-10 15:47 Fila Kolodny <fila@ibi.com>
* nis/ypclnt.c: Change references to MAXHOSTNAMELEN to NIS_MAXNAMELEN.
Add include of rpcsvc/nis.h.
* inet/getnameinfo.c: Delete references to MAXHOSTNAMELEN.
* sysdeps/posix/getaddrinfo.c: Likewise.
Change size of variable buffer to be big enough to hold an IPv6
address in printable format.
1997-07-12 18:47 Ulrich Drepper <drepper@cygnus.com>
* assert/assert.h [!NDEBUG] (assert, assert_perror): Don't use ||
and && in tests to allow use in C++ code which overloads these
operators. Reported by Istvan Marko <istvan@cmdmail.amd.com>.
* configure.in: Move mips64* recognition before mips*.
Patch by Zack Weinberg <zack@rabi.phys.columbia.edu>.
1997-07-03 20:44 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* Makerules (lib%.so, $(common-objpfx)libc.so): Don't use
automatic variables in dependency lists.
(build-shlib): Always filter out the version script file.
* extra-lib.mk ($(objpfx)$(lib).so): Depend on version script.
1997-07-12 17:56 Ulrich Drepper <drepper@cygnus.com>
* login/login.c (tty_name): Test return value of ttyname_r for !=
0, not < 0.
* misc/ttyslot.c (ttyslot): Test return value of ttyname_r for ==
0, not >= 0.
* sysdeps/unix/getlogin.c (getlogin): Test return value of
ttyname_r for != 0.
* sysdeps/unix/getlogin_r.c (getlogin_r): Likewise.
1997-07-10 Andreas Jaeger <aj@arthur.rhein-neckar.de>
* login/utmp_file.c (getutline_r_file): Fix type: compare with
*result.
1997-07-11 00:21 Mark Kettenis <kettenis@phys.uva.nl>
* login/Makefile (headers): Add utmpx.h and bits/utmpx.h.
1997-07-09 19:21 Mark Kettenis <kettenis@phys.uva.nl>
* login/programs/utmpd.c, login/programs/database.c,
login/programs/request.c: Prepare messages for
internationalization.
* login/programs/utmpd.c:
(main): Change handling of errors in opening the database.
* login/programs/database.c:
(open_database, synchronize_dtatabase, initialize_database):
Properly handle errors.
(get_mtime): Use fstat instead of stat. All callers changed.
* login/getutent_r.c: Make setutxent a weak alias for __setutxent.
* login/getutent.c: Rename getutent to __getutent and make
getutent a weak alias.
Make getutxent a weak alias for __getutent.
* login/utmpx.h: New file.
* sysdeps/gnu/bits/utmp.h: Cleanup. Added comments.
* sysdeps/gnu/bits/utmpx.h: New file.
* stdio-common/strops.c: Partialy undo last change. Will need
more investigation.
1997-07-12 23:35:19 +00:00
|
|
|
/*
|
|
|
|
buffer is the size of an unformatted IPv6 address in printable format.
|
|
|
|
*/
|
1997-08-20 03:53:21 +00:00
|
|
|
while (at2 != NULL)
|
|
|
|
{
|
|
|
|
if (req->ai_flags & AI_CANONNAME)
|
|
|
|
{
|
|
|
|
struct hostent *h = NULL;
|
1996-10-21 01:26:31 +00:00
|
|
|
|
1997-08-20 03:53:21 +00:00
|
|
|
int herrno;
|
|
|
|
struct hostent th;
|
|
|
|
size_t tmpbuflen = 512;
|
2003-04-23 17:19:51 +00:00
|
|
|
char *tmpbuf = NULL;
|
1996-10-21 01:26:31 +00:00
|
|
|
|
1997-08-20 03:53:21 +00:00
|
|
|
do
|
|
|
|
{
|
2003-04-23 17:19:51 +00:00
|
|
|
tmpbuf = extend_alloca (tmpbuf, tmpbuflen, tmpbuflen * 2);
|
1997-08-20 03:53:21 +00:00
|
|
|
rc = __gethostbyaddr_r (at2->addr,
|
|
|
|
((at2->family == AF_INET6)
|
|
|
|
? sizeof(struct in6_addr)
|
|
|
|
: sizeof(struct in_addr)),
|
|
|
|
at2->family, &th, tmpbuf, tmpbuflen,
|
|
|
|
&h, &herrno);
|
|
|
|
|
|
|
|
}
|
2003-04-23 17:19:51 +00:00
|
|
|
while (rc == ERANGE && herrno == NETDB_INTERNAL);
|
1997-08-20 03:53:21 +00:00
|
|
|
|
1999-09-12 19:24:42 +00:00
|
|
|
if (rc != 0 && herrno == NETDB_INTERNAL)
|
1997-08-20 03:53:21 +00:00
|
|
|
{
|
|
|
|
__set_h_errno (herrno);
|
|
|
|
return -EAI_SYSTEM;
|
|
|
|
}
|
|
|
|
|
2002-08-29 08:51:26 +00:00
|
|
|
if (h != NULL)
|
1997-08-20 03:53:21 +00:00
|
|
|
c = h->h_name;
|
2002-08-29 08:51:26 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
/* We have to try to get the canonical in some other
|
|
|
|
way. If we are looking for either AF_INET or
|
|
|
|
AF_INET6 try the other line. */
|
|
|
|
if (req->ai_family == AF_UNSPEC)
|
|
|
|
{
|
|
|
|
struct addrinfo *p = NULL;
|
|
|
|
struct addrinfo **end = &p;
|
|
|
|
struct addrinfo localreq = *req;
|
|
|
|
struct addrinfo *runp;
|
|
|
|
|
|
|
|
localreq.ai_family = AF_INET + AF_INET6 - at2->family;
|
|
|
|
(void) gaih_inet (name, service, &localreq, end);
|
|
|
|
|
|
|
|
runp = p;
|
|
|
|
while (runp != NULL)
|
|
|
|
{
|
|
|
|
if (p->ai_canonname != name)
|
|
|
|
{
|
|
|
|
c = strdupa (p->ai_canonname);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
runp = runp->ai_next;
|
|
|
|
}
|
|
|
|
|
|
|
|
freeaddrinfo (p);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If this code is used the missing canonical name is
|
|
|
|
substituted with the name passed in by the user. */
|
|
|
|
if (c == NULL)
|
|
|
|
c = name;
|
|
|
|
}
|
1997-08-20 03:53:21 +00:00
|
|
|
|
|
|
|
if (c == NULL)
|
|
|
|
return GAIH_OKIFUNSPEC | -EAI_NONAME;
|
|
|
|
|
2004-03-13 06:53:42 +00:00
|
|
|
#ifdef HAVE_LIBIDN
|
|
|
|
if (req->ai_flags & AI_CANONIDN)
|
|
|
|
{
|
2004-03-17 20:02:19 +00:00
|
|
|
int idn_flags = 0;
|
|
|
|
if (req->ai_flags & AI_IDN_ALLOW_UNASSIGNED)
|
|
|
|
idn_flags |= IDNA_ALLOW_UNASSIGNED;
|
|
|
|
if (req->ai_flags & AI_IDN_USE_STD3_ASCII_RULES)
|
|
|
|
idn_flags |= IDNA_USE_STD3_ASCII_RULES;
|
|
|
|
|
2004-03-13 06:53:42 +00:00
|
|
|
char *out;
|
2004-03-17 20:02:19 +00:00
|
|
|
int rc = __idna_to_unicode_lzlz (c, &out, idn_flags);
|
2004-03-13 06:53:42 +00:00
|
|
|
if (rc != IDNA_SUCCESS)
|
|
|
|
{
|
|
|
|
if (rc == IDNA_MALLOC_ERROR)
|
|
|
|
return -EAI_MEMORY;
|
|
|
|
if (rc == IDNA_DLOPEN_ERROR)
|
|
|
|
return -EAI_SYSTEM;
|
|
|
|
return -EAI_IDN_ENCODE;
|
|
|
|
}
|
|
|
|
/* In case the output string is the same as the input
|
|
|
|
string no new string has been allocated. */
|
|
|
|
if (out != c)
|
|
|
|
{
|
|
|
|
c = strdupa (out);
|
|
|
|
free (out);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1997-08-20 03:53:21 +00:00
|
|
|
namelen = strlen (c) + 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
namelen = 0;
|
|
|
|
|
|
|
|
if (at2->family == AF_INET6)
|
2000-11-10 04:15:55 +00:00
|
|
|
{
|
|
|
|
family = AF_INET6;
|
|
|
|
socklen = sizeof (struct sockaddr_in6);
|
2003-04-24 23:45:17 +00:00
|
|
|
|
|
|
|
/* If we looked up IPv4 mapped address discard them here if
|
|
|
|
the caller isn't interested in all address and we have
|
|
|
|
found at least one IPv6 address. */
|
|
|
|
if (! got_ipv6
|
|
|
|
&& (req->ai_flags & (AI_V4MAPPED|AI_ALL)) == AI_V4MAPPED
|
|
|
|
&& IN6_IS_ADDR_V4MAPPED (at2->addr))
|
|
|
|
goto ignore;
|
2000-11-10 04:15:55 +00:00
|
|
|
}
|
1997-08-20 03:53:21 +00:00
|
|
|
else
|
2000-11-10 04:15:55 +00:00
|
|
|
{
|
|
|
|
family = AF_INET;
|
|
|
|
socklen = sizeof (struct sockaddr_in);
|
|
|
|
}
|
1997-08-20 03:53:21 +00:00
|
|
|
|
|
|
|
for (st2 = st; st2 != NULL; st2 = st2->next)
|
|
|
|
{
|
|
|
|
*pai = malloc (sizeof (struct addrinfo) + socklen + namelen);
|
|
|
|
if (*pai == NULL)
|
|
|
|
return -EAI_MEMORY;
|
|
|
|
|
|
|
|
(*pai)->ai_flags = req->ai_flags;
|
2000-11-10 04:15:55 +00:00
|
|
|
(*pai)->ai_family = family;
|
1997-08-20 03:53:21 +00:00
|
|
|
(*pai)->ai_socktype = st2->socktype;
|
|
|
|
(*pai)->ai_protocol = st2->protocol;
|
|
|
|
(*pai)->ai_addrlen = socklen;
|
2003-04-24 23:45:17 +00:00
|
|
|
(*pai)->ai_addr = (void *) (*pai) + sizeof (struct addrinfo);
|
1996-10-21 01:26:31 +00:00
|
|
|
#if SALEN
|
2000-03-23 21:34:58 +00:00
|
|
|
(*pai)->ai_addr->sa_len = socklen;
|
1996-10-21 01:26:31 +00:00
|
|
|
#endif /* SALEN */
|
2000-11-10 04:15:55 +00:00
|
|
|
(*pai)->ai_addr->sa_family = family;
|
update from main archive 970221
1997-02-22 00:17 Ulrich Drepper <drepper@cygnus.com>
* catgets/gencat.c: Change to use argp.
* db/makedb: Likewise.
* locale/programs/localedef.c: Likewise.
* locale/programs/locale.c: Little adjustment for better usage of
argp.
1997-02-20 20:07 Greg McGary <gkm@eng.ascend.com>
* Makeconfig: Add rules for libc with bounded pointers.
* Makerules: Likewise.
* config.make.in: Likewise.
* configure.in: Likewise.
1997-02-21 10:41 Miles Bader <miles@gnu.ai.mit.edu>
* argp.h (OPTION_NO_USAGE): New macro.
* argp-help.c (usage_long_opt, usage_argful_short_opt,
add_argless_short_opt): Implement OPTION_NO_USAGE.
1997-02-20 16:41 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de>
* malloc/obstack.h: Fix typo.
1997-02-20 15:56 Miles Bader <miles@gnu.ai.mit.edu>
* argp-fmtstream.c (__argp_fmtstream_update): Account for case
where NEXTLINE points one past the end of the active buffer.
* argp-help.c <stddef.h>: New include.
(__argp_failure): Only exit if STATE says it's ok.
(print_header, hol_entry_help): Use UPARAMS fields rather than
constants.
(_help): Call fill_in_uparams if necessary.
(struct hol_help_state): New type.
(struct pentry_state): Add hhstate field. Remove prev_entry &
sep_groups fields.
(hol_entry_help): Add HHSTATE parameter. Remove prev_entry &
sep_groups parameters.
Suppress duplicate arguments if requested, and note the fact.
(print_header, comma): Use PEST->hhstate fields.
(hol_help): Add HHSTATE variable & pass to hol_entry_help.
Remove LAST_ENTRY & SEP_GROUPS variables.
If any suplicate arguments were suppressed, print explanatory note.
(filter_doc): Replace PEST parameter with STATE.
(struct uparams): New type.
(uparams): New variable.
(struct uparam_name): New type.
(uparam_names): New variable.
(fill_in_uparams): New function.
(__argp_failure, __argp_error, __argp_state_help): Make STATE
parameter const.
* argp.h (argp_state_help, __argp_state_help, argp_usage,
__argp_usage, argp_error, __argp_error, argp_failure,
__argp_failure): Make STATE parameter const.
(ARGP_KEY_HELP_DUP_ARGS_NOTE): New macro.
* argp.h (argp_program_bug_address): Make const.
1997-02-20 19:20 Ulrich Drepper <drepper@cygnus.com>
* sysdeps/unix/mman/syscalls.list: Explain msync interface.
1997-02-19 01:37 Erik Troan <ewt@redhat.com>
* shadow/sgetspent_r.c: Accept empty third, fourth and fifth fields.
1997-02-20 14:44 Andreas Jaeger <aj@arthur.pfalz.de>
* stdio-common/test-fseek.c: Remove temporary file, add
copyright.
1997-02-20 17:51 Ulrich Drepper <drepper@cygnus.com>
* sysdeps/generic/netinet/in.h: Protect contents using
__BEGIN/END_DECLS. Reported by a sun <asun@zoology.washington.edu>.
* inet/net/ethernet.h: Move to sysdeps/unix/sysv/linux/net.
* inet/Makefile (headers): Remove net/ethernet.h.
* sysdeps/unix/sysv/linux/Makefile: Install net/ethernet.h.
* sysdeps/unix/sysv/linux/Dist: Distribute net/ethernet.h.
1997-02-20 15:23 Thorsten Kukuk <kukuk@weber.uni-paderborn.de>
* nss/nsswitch.c (__nss_configure_lookup): Use correct test when
searching in sorted array.
1997-02-20 01:24 Philip Blundell <pjb27@cam.ac.uk>
* inet/getnameinfo.c: Change to use reentrant getXXbyYY functions
and protect modification of global data.
1997-02-19 18:48 Miles Bader <miles@gnu.ai.mit.edu>
* argp-parse.c (argp_default_parser): Set STATE->name for OPT_PROGNAME.
(parser_init): Use the basename for PARSER->state.name.
* argp-help.c (__argp_error, __argp_failure, __argp_state_help):
Use PROGRAM_INVOCATION_SHORT_NAME instead of PROGRAM_INVOCATION_NAME.
* argp-parse.c (parser_init): Set PARSER->state.flags.
Make check whether PARSER has the prog name in argv[0] at the
proper place.
1997-02-19 23:34 Ulrich Drepper <drepper@cygnus.com>
* locale/programs/ld-time.c (time_finish): t_fmt_ampm is optional.
Use default value instead of printing a warning.
* nss/XXX-lookup.c: Add misssing explanation.
1997-02-19 19:14 Andreas Jaeger <aj@arthur.pfalz.de>
* inet/in6_addr.c: Add missing braces.
* inet/getnameinfo.c: Include <arpa/inet.h>.
* sysdeps/posix/getaddrinfo.c: Include <arpa/inet.h>.
1997-02-19 11:46 Ulrich Drepper <drepper@cygnus.com>
* string/strxfrm.c (STRCOLL): Correct handling of `position'
levels with no non-IGNOREd element and handling of NUL byte.
* string/strcoll.c (STRXFRM): Likewise.
* locale/weight.h: Likewise.
* shadow/sgetspent_r.c (LINE_PARSER): Add missing ')'.
1997-02-22 01:20:46 +00:00
|
|
|
|
2000-11-10 04:15:55 +00:00
|
|
|
if (family == AF_INET6)
|
1997-08-20 03:53:21 +00:00
|
|
|
{
|
|
|
|
struct sockaddr_in6 *sin6p =
|
|
|
|
(struct sockaddr_in6 *) (*pai)->ai_addr;
|
1996-10-21 01:26:31 +00:00
|
|
|
|
1997-08-20 03:53:21 +00:00
|
|
|
sin6p->sin6_flowinfo = 0;
|
|
|
|
memcpy (&sin6p->sin6_addr,
|
|
|
|
at2->addr, sizeof (struct in6_addr));
|
2000-03-23 21:34:58 +00:00
|
|
|
sin6p->sin6_port = st2->port;
|
|
|
|
sin6p->sin6_scope_id = at2->scopeid;
|
1997-08-20 03:53:21 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
struct sockaddr_in *sinp =
|
|
|
|
(struct sockaddr_in *) (*pai)->ai_addr;
|
|
|
|
memcpy (&sinp->sin_addr,
|
|
|
|
at2->addr, sizeof (struct in_addr));
|
2000-03-23 21:34:58 +00:00
|
|
|
sinp->sin_port = st2->port;
|
1997-08-20 03:53:21 +00:00
|
|
|
memset (sinp->sin_zero, '\0', sizeof (sinp->sin_zero));
|
|
|
|
}
|
1996-10-21 01:26:31 +00:00
|
|
|
|
1997-08-20 03:53:21 +00:00
|
|
|
if (c)
|
|
|
|
{
|
|
|
|
(*pai)->ai_canonname = ((void *) (*pai) +
|
|
|
|
sizeof (struct addrinfo) + socklen);
|
|
|
|
strcpy ((*pai)->ai_canonname, c);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
(*pai)->ai_canonname = NULL;
|
1996-10-21 01:26:31 +00:00
|
|
|
|
1997-08-20 03:53:21 +00:00
|
|
|
(*pai)->ai_next = NULL;
|
|
|
|
pai = &((*pai)->ai_next);
|
|
|
|
}
|
1996-10-21 01:26:31 +00:00
|
|
|
|
2003-04-24 23:45:17 +00:00
|
|
|
ignore:
|
1997-08-20 03:53:21 +00:00
|
|
|
at2 = at2->next;
|
|
|
|
}
|
1996-10-21 01:26:31 +00:00
|
|
|
}
|
1997-08-20 03:53:21 +00:00
|
|
|
return 0;
|
1996-10-21 01:26:31 +00:00
|
|
|
}
|
|
|
|
|
1997-08-20 03:53:21 +00:00
|
|
|
static struct gaih gaih[] =
|
|
|
|
{
|
|
|
|
{ PF_INET6, gaih_inet },
|
|
|
|
{ PF_INET, gaih_inet },
|
2001-05-23 23:56:31 +00:00
|
|
|
#if 0
|
1997-08-20 03:53:21 +00:00
|
|
|
{ PF_LOCAL, gaih_local },
|
2001-05-23 23:56:31 +00:00
|
|
|
#endif
|
1997-08-20 03:53:21 +00:00
|
|
|
{ PF_UNSPEC, NULL }
|
|
|
|
};
|
1996-10-21 01:26:31 +00:00
|
|
|
|
2003-11-18 07:04:13 +00:00
|
|
|
struct sort_result
|
|
|
|
{
|
|
|
|
struct addrinfo *dest_addr;
|
|
|
|
struct sockaddr_storage source_addr;
|
|
|
|
bool got_source_addr;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
get_scope (const struct sockaddr_storage *ss)
|
|
|
|
{
|
|
|
|
int scope;
|
|
|
|
if (ss->ss_family == PF_INET6)
|
|
|
|
{
|
|
|
|
const struct sockaddr_in6 *in6 = (const struct sockaddr_in6 *) ss;
|
|
|
|
|
|
|
|
if (! IN6_IS_ADDR_MULTICAST (&in6->sin6_addr))
|
|
|
|
{
|
|
|
|
if (IN6_IS_ADDR_LINKLOCAL (&in6->sin6_addr))
|
|
|
|
scope = 2;
|
|
|
|
else if (IN6_IS_ADDR_SITELOCAL (&in6->sin6_addr))
|
|
|
|
scope = 5;
|
|
|
|
else
|
|
|
|
/* XXX Is this the correct default behavior? */
|
|
|
|
scope = 14;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
scope = in6->sin6_addr.s6_addr[1] & 0xf;
|
|
|
|
}
|
|
|
|
else if (ss->ss_family == PF_INET)
|
|
|
|
{
|
|
|
|
const struct sockaddr_in *in = (const struct sockaddr_in *) ss;
|
|
|
|
const uint8_t *addr = (const uint8_t *) &in->sin_addr;
|
|
|
|
|
|
|
|
/* RFC 3484 specifies how to map IPv6 addresses to scopes.
|
|
|
|
169.254/16 and 127/8 are link-local. */
|
|
|
|
if ((addr[0] == 169 && addr[1] == 254) || addr[0] == 127)
|
|
|
|
scope = 2;
|
|
|
|
else if (addr[0] == 10 || (addr[0] == 172 && addr[1] == 16)
|
|
|
|
|| (addr[0] == 192 && addr[1] == 168))
|
|
|
|
scope = 5;
|
|
|
|
else
|
|
|
|
scope = 14;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
/* XXX What is a good default? */
|
|
|
|
scope = 15;
|
|
|
|
|
|
|
|
return scope;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* XXX The system administrator should be able to install other
|
|
|
|
tables. We need to make this configurable. The problem is that
|
|
|
|
the kernel is also involved since it needs the same table. */
|
|
|
|
static const struct prefixlist
|
|
|
|
{
|
|
|
|
struct in6_addr prefix;
|
|
|
|
unsigned int bits;
|
|
|
|
int val;
|
|
|
|
} default_labels[] =
|
|
|
|
{
|
|
|
|
/* See RFC 3484 for the details. */
|
|
|
|
{ { .in6_u = { .u6_addr16 = { 0x0000, 0x0000, 0x0000, 0x0000,
|
|
|
|
0x0000, 0x0000, 0x0000, 0x0001 } } },
|
|
|
|
128, 0 },
|
|
|
|
{ { .in6_u = { .u6_addr16 = { 0x2002, 0x0000, 0x0000, 0x0000,
|
|
|
|
0x0000, 0x0000, 0x0000, 0x0000 } } },
|
|
|
|
16, 2 },
|
|
|
|
{ { .in6_u = { .u6_addr16 = { 0x0000, 0x0000, 0x0000, 0x0000,
|
|
|
|
0x0000, 0x0000, 0x0000, 0x0000 } } },
|
|
|
|
96, 3 },
|
|
|
|
{ { .in6_u = { .u6_addr16 = { 0x0000, 0x0000, 0x0000, 0x0000,
|
|
|
|
0x0000, 0xffff, 0x0000, 0x0000 } } },
|
|
|
|
96, 4 },
|
|
|
|
{ { .in6_u = { .u6_addr16 = { 0x0000, 0x0000, 0x0000, 0x0000,
|
|
|
|
0x0000, 0x0000, 0x0000, 0x0000 } } },
|
|
|
|
0, 1 }
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static const struct prefixlist default_precedence[] =
|
|
|
|
{
|
|
|
|
/* See RFC 3484 for the details. */
|
|
|
|
{ { .in6_u = { .u6_addr16 = { 0x0000, 0x0000, 0x0000, 0x0000,
|
|
|
|
0x0000, 0x0000, 0x0000, 0x0001 } } },
|
|
|
|
128, 50 },
|
|
|
|
{ { .in6_u = { .u6_addr16 = { 0x2002, 0x0000, 0x0000, 0x0000,
|
|
|
|
0x0000, 0x0000, 0x0000, 0x0000 } } },
|
|
|
|
16, 30 },
|
|
|
|
{ { .in6_u = { .u6_addr16 = { 0x0000, 0x0000, 0x0000, 0x0000,
|
|
|
|
0x0000, 0x0000, 0x0000, 0x0000 } } },
|
|
|
|
96, 20 },
|
|
|
|
{ { .in6_u = { .u6_addr16 = { 0x0000, 0x0000, 0x0000, 0x0000,
|
|
|
|
0x0000, 0xffff, 0x0000, 0x0000 } } },
|
|
|
|
96, 10 },
|
|
|
|
{ { .in6_u = { .u6_addr16 = { 0x0000, 0x0000, 0x0000, 0x0000,
|
|
|
|
0x0000, 0x0000, 0x0000, 0x0000 } } },
|
|
|
|
0, 40 }
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
match_prefix (const struct sockaddr_storage *ss, const struct prefixlist *list,
|
|
|
|
int default_val)
|
|
|
|
{
|
|
|
|
int idx;
|
|
|
|
struct sockaddr_in6 in6_mem;
|
|
|
|
const struct sockaddr_in6 *in6;
|
|
|
|
|
|
|
|
if (ss->ss_family == PF_INET6)
|
|
|
|
in6 = (const struct sockaddr_in6 *) ss;
|
|
|
|
else if (ss->ss_family == PF_INET)
|
|
|
|
{
|
|
|
|
const struct sockaddr_in *in = (const struct sockaddr_in *) ss;
|
|
|
|
|
|
|
|
/* Convert to IPv6 address. */
|
|
|
|
in6_mem.sin6_family = PF_INET6;
|
|
|
|
in6_mem.sin6_port = in->sin_port;
|
|
|
|
in6_mem.sin6_flowinfo = 0;
|
|
|
|
if (in->sin_addr.s_addr == htonl (0x7f000001))
|
|
|
|
in6_mem.sin6_addr = (struct in6_addr) IN6ADDR_LOOPBACK_INIT;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Construct a V4-to-6 mapped address. */
|
|
|
|
memset (&in6_mem.sin6_addr, '\0', sizeof (in6_mem.sin6_addr));
|
|
|
|
in6_mem.sin6_addr.s6_addr16[5] = 0xffff;
|
|
|
|
in6_mem.sin6_addr.s6_addr32[3] = in->sin_addr.s_addr;
|
|
|
|
in6_mem.sin6_scope_id = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
in6 = &in6_mem;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return default_val;
|
|
|
|
|
|
|
|
for (idx = 0; ; ++idx)
|
|
|
|
{
|
|
|
|
unsigned int bits = list[idx].bits;
|
|
|
|
uint8_t *mask = list[idx].prefix.s6_addr;
|
|
|
|
uint8_t *val = in6->sin6_addr.s6_addr;
|
|
|
|
|
|
|
|
while (bits > 8)
|
|
|
|
{
|
|
|
|
if (*mask != *val)
|
|
|
|
break;
|
|
|
|
|
|
|
|
++mask;
|
|
|
|
++val;
|
|
|
|
bits -= 8;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bits < 8)
|
|
|
|
{
|
2004-02-16 18:48:51 +00:00
|
|
|
if ((*mask & (0xff00 >> bits)) == (*val & (0xff00 >> bits)))
|
2003-11-18 07:04:13 +00:00
|
|
|
/* Match! */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return list[idx].val;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
get_label (const struct sockaddr_storage *ss)
|
|
|
|
{
|
|
|
|
/* XXX What is a good default value? */
|
|
|
|
return match_prefix (ss, default_labels, INT_MAX);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
get_precedence (const struct sockaddr_storage *ss)
|
|
|
|
{
|
|
|
|
/* XXX What is a good default value? */
|
|
|
|
return match_prefix (ss, default_precedence, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
rfc3484_sort (const void *p1, const void *p2)
|
|
|
|
{
|
|
|
|
const struct sort_result *a1 = (const struct sort_result *) p1;
|
|
|
|
const struct sort_result *a2 = (const struct sort_result *) p2;
|
|
|
|
|
|
|
|
/* Rule 1: Avoid unusable destinations.
|
|
|
|
We have the got_source_addr flag set if the destination is reachable. */
|
|
|
|
if (a1->got_source_addr && ! a2->got_source_addr)
|
|
|
|
return -1;
|
|
|
|
if (! a1->got_source_addr && a2->got_source_addr)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
|
|
|
|
/* Rule 2: Prefer matching scope. Only interesting if both
|
|
|
|
destination addresses are IPv6. */
|
|
|
|
int a1_dst_scope
|
|
|
|
= get_scope ((struct sockaddr_storage *) a1->dest_addr->ai_addr);
|
|
|
|
|
|
|
|
int a2_dst_scope
|
|
|
|
= get_scope ((struct sockaddr_storage *) a2->dest_addr->ai_addr);
|
|
|
|
|
|
|
|
if (a1->got_source_addr)
|
|
|
|
{
|
|
|
|
int a1_src_scope = get_scope (&a1->source_addr);
|
|
|
|
int a2_src_scope = get_scope (&a2->source_addr);
|
|
|
|
|
|
|
|
if (a1_dst_scope == a1_src_scope && a2_dst_scope != a2_src_scope)
|
|
|
|
return -1;
|
|
|
|
if (a1_dst_scope != a1_src_scope && a2_dst_scope == a2_src_scope)
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Rule 3: Avoid deprecated addresses.
|
|
|
|
That's something only the kernel could decide. */
|
|
|
|
|
|
|
|
/* Rule 4: Prefer home addresses.
|
|
|
|
Another thing only the kernel can decide. */
|
|
|
|
|
|
|
|
/* Rule 5: Prefer matching label. */
|
|
|
|
if (a1->got_source_addr)
|
|
|
|
{
|
|
|
|
int a1_dst_label
|
|
|
|
= get_label ((struct sockaddr_storage *) a1->dest_addr->ai_addr);
|
|
|
|
int a1_src_label = get_label (&a1->source_addr);
|
|
|
|
|
|
|
|
int a2_dst_label
|
|
|
|
= get_label ((struct sockaddr_storage *) a2->dest_addr->ai_addr);
|
|
|
|
int a2_src_label = get_label (&a2->source_addr);
|
|
|
|
|
|
|
|
if (a1_dst_label == a1_src_label && a2_dst_label != a2_src_label)
|
|
|
|
return -1;
|
|
|
|
if (a1_dst_label != a1_src_label && a2_dst_label == a2_src_label)
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Rule 6: Prefer higher precedence. */
|
|
|
|
int a1_prec
|
|
|
|
= get_precedence ((struct sockaddr_storage *) a1->dest_addr->ai_addr);
|
|
|
|
int a2_prec
|
|
|
|
= get_precedence ((struct sockaddr_storage *) a2->dest_addr->ai_addr);
|
|
|
|
|
|
|
|
if (a1_prec > a2_prec)
|
|
|
|
return -1;
|
|
|
|
if (a1_prec < a2_prec)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
|
|
|
|
/* Rule 7: Prefer native transport.
|
|
|
|
XXX How to recognize tunnels? */
|
|
|
|
|
|
|
|
|
|
|
|
/* Rule 8: Prefer smaller scope. */
|
|
|
|
if (a1_dst_scope < a2_dst_scope)
|
|
|
|
return -1;
|
|
|
|
if (a1_dst_scope > a2_dst_scope)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
|
|
|
|
/* Rule 9: Use longest matching prefix. */
|
|
|
|
if (a1->got_source_addr
|
|
|
|
&& a1->dest_addr->ai_family == a2->dest_addr->ai_family)
|
|
|
|
{
|
|
|
|
int bit1 = 0;
|
|
|
|
int bit2 = 0;
|
|
|
|
|
|
|
|
if (a1->dest_addr->ai_family == PF_INET)
|
|
|
|
{
|
|
|
|
assert (a1->source_addr.ss_family == PF_INET);
|
|
|
|
assert (a2->source_addr.ss_family == PF_INET);
|
|
|
|
|
|
|
|
struct sockaddr_in *in1_dst;
|
|
|
|
struct sockaddr_in *in1_src;
|
|
|
|
struct sockaddr_in *in2_dst;
|
|
|
|
struct sockaddr_in *in2_src;
|
|
|
|
|
|
|
|
in1_dst = (struct sockaddr_in *) a1->dest_addr->ai_addr;
|
|
|
|
in1_src = (struct sockaddr_in *) &a1->source_addr;
|
|
|
|
in2_dst = (struct sockaddr_in *) a2->dest_addr->ai_addr;
|
|
|
|
in2_src = (struct sockaddr_in *) &a2->source_addr;
|
|
|
|
|
|
|
|
bit1 = ffs (in1_dst->sin_addr.s_addr ^ in1_src->sin_addr.s_addr);
|
|
|
|
bit2 = ffs (in2_dst->sin_addr.s_addr ^ in2_src->sin_addr.s_addr);
|
|
|
|
}
|
|
|
|
else if (a1->dest_addr->ai_family == PF_INET6)
|
|
|
|
{
|
|
|
|
assert (a1->source_addr.ss_family == PF_INET6);
|
|
|
|
assert (a2->source_addr.ss_family == PF_INET6);
|
|
|
|
|
|
|
|
struct sockaddr_in6 *in1_dst;
|
|
|
|
struct sockaddr_in6 *in1_src;
|
|
|
|
struct sockaddr_in6 *in2_dst;
|
|
|
|
struct sockaddr_in6 *in2_src;
|
|
|
|
|
|
|
|
in1_dst = (struct sockaddr_in6 *) a1->dest_addr->ai_addr;
|
|
|
|
in1_src = (struct sockaddr_in6 *) &a1->source_addr;
|
|
|
|
in2_dst = (struct sockaddr_in6 *) a2->dest_addr->ai_addr;
|
|
|
|
in2_src = (struct sockaddr_in6 *) &a2->source_addr;
|
|
|
|
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < 4; ++i)
|
|
|
|
if (in1_dst->sin6_addr.s6_addr32[i]
|
|
|
|
!= in1_src->sin6_addr.s6_addr32[i]
|
|
|
|
|| (in2_dst->sin6_addr.s6_addr32[i]
|
|
|
|
!= in2_src->sin6_addr.s6_addr32[i]))
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (i < 4)
|
|
|
|
{
|
|
|
|
bit1 = ffs (in1_dst->sin6_addr.s6_addr32[i]
|
|
|
|
^ in1_src->sin6_addr.s6_addr32[i]);
|
|
|
|
bit2 = ffs (in2_dst->sin6_addr.s6_addr32[i]
|
|
|
|
^ in2_src->sin6_addr.s6_addr32[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bit1 > bit2)
|
|
|
|
return -1;
|
|
|
|
if (bit1 < bit2)
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Rule 10: Otherwise, leave the order unchanged. */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1997-08-20 03:53:21 +00:00
|
|
|
int
|
|
|
|
getaddrinfo (const char *name, const char *service,
|
|
|
|
const struct addrinfo *hints, struct addrinfo **pai)
|
1996-10-21 01:26:31 +00:00
|
|
|
{
|
1999-09-12 19:24:42 +00:00
|
|
|
int i = 0, j = 0, last_i = 0;
|
2003-11-18 07:04:13 +00:00
|
|
|
int nresults = 0;
|
1997-02-19 04:43:53 +00:00
|
|
|
struct addrinfo *p = NULL, **end;
|
1996-10-21 01:26:31 +00:00
|
|
|
struct gaih *g = gaih, *pg = NULL;
|
|
|
|
struct gaih_service gaih_service, *pservice;
|
2003-04-24 23:45:17 +00:00
|
|
|
struct addrinfo local_hints;
|
1996-10-21 01:26:31 +00:00
|
|
|
|
1997-08-20 03:53:21 +00:00
|
|
|
if (name != NULL && name[0] == '*' && name[1] == 0)
|
1997-02-19 04:43:53 +00:00
|
|
|
name = NULL;
|
|
|
|
|
1997-08-20 03:53:21 +00:00
|
|
|
if (service != NULL && service[0] == '*' && service[1] == 0)
|
1997-02-19 04:43:53 +00:00
|
|
|
service = NULL;
|
|
|
|
|
1997-08-20 03:53:21 +00:00
|
|
|
if (name == NULL && service == NULL)
|
1996-10-21 01:26:31 +00:00
|
|
|
return EAI_NONAME;
|
|
|
|
|
1997-08-20 03:53:21 +00:00
|
|
|
if (hints == NULL)
|
|
|
|
hints = &default_hints;
|
1996-10-21 01:26:31 +00:00
|
|
|
|
2003-04-24 23:45:17 +00:00
|
|
|
if (hints->ai_flags
|
|
|
|
& ~(AI_PASSIVE|AI_CANONNAME|AI_NUMERICHOST|AI_ADDRCONFIG|AI_V4MAPPED
|
2004-03-08 04:10:31 +00:00
|
|
|
#ifdef HAVE_LIBIDN
|
2004-03-17 20:02:19 +00:00
|
|
|
|AI_IDN|AI_CANONIDN|AI_IDN_ALLOW_UNASSIGNED
|
|
|
|
|AI_IDN_USE_STD3_ASCII_RULES
|
2004-03-08 04:10:31 +00:00
|
|
|
#endif
|
2004-02-16 21:00:54 +00:00
|
|
|
|AI_ALL))
|
1996-10-21 01:26:31 +00:00
|
|
|
return EAI_BADFLAGS;
|
|
|
|
|
2004-02-16 21:00:54 +00:00
|
|
|
if ((hints->ai_flags & AI_CANONNAME) && name == NULL)
|
1996-10-21 01:26:31 +00:00
|
|
|
return EAI_BADFLAGS;
|
|
|
|
|
2003-04-24 23:45:17 +00:00
|
|
|
if (hints->ai_flags & AI_ADDRCONFIG)
|
|
|
|
{
|
|
|
|
/* Determine whether we have IPv4 or IPv6 interfaces or both.
|
|
|
|
We cannot cache the results since new interfaces could be
|
2003-06-10 08:58:05 +00:00
|
|
|
added at any time. */
|
|
|
|
bool seen_ipv4;
|
|
|
|
bool seen_ipv6;
|
|
|
|
__check_pf (&seen_ipv4, &seen_ipv6);
|
2003-04-24 23:45:17 +00:00
|
|
|
|
|
|
|
/* Now make a decision on what we return, if anything. */
|
|
|
|
if (hints->ai_family == PF_UNSPEC)
|
|
|
|
{
|
|
|
|
/* If we haven't seen both IPv4 and IPv6 interfaces we can
|
|
|
|
narrow down the search. */
|
|
|
|
if (! seen_ipv4 || ! seen_ipv6)
|
|
|
|
{
|
|
|
|
local_hints = *hints;
|
|
|
|
local_hints.ai_family = seen_ipv4 ? PF_INET : PF_INET6;
|
|
|
|
hints = &local_hints;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ((hints->ai_family == PF_INET && ! seen_ipv4)
|
|
|
|
|| (hints->ai_family == PF_INET6 && ! seen_ipv6))
|
|
|
|
/* We cannot possibly return a valid answer. */
|
|
|
|
return EAI_NONAME;
|
|
|
|
}
|
|
|
|
|
1997-08-20 03:53:21 +00:00
|
|
|
if (service && service[0])
|
|
|
|
{
|
|
|
|
char *c;
|
|
|
|
gaih_service.name = service;
|
|
|
|
gaih_service.num = strtoul (gaih_service.name, &c, 10);
|
|
|
|
if (*c)
|
|
|
|
gaih_service.num = -1;
|
1997-02-19 04:43:53 +00:00
|
|
|
else
|
1997-08-20 03:53:21 +00:00
|
|
|
/* Can't specify a numerical socket unless a protocol family was
|
|
|
|
given. */
|
2000-11-10 04:15:55 +00:00
|
|
|
if (hints->ai_socktype == 0 && hints->ai_protocol == 0)
|
1997-02-19 04:43:53 +00:00
|
|
|
return EAI_SERVICE;
|
1997-08-20 03:53:21 +00:00
|
|
|
pservice = &gaih_service;
|
|
|
|
}
|
|
|
|
else
|
1996-10-21 01:26:31 +00:00
|
|
|
pservice = NULL;
|
|
|
|
|
1997-02-19 04:43:53 +00:00
|
|
|
if (pai)
|
|
|
|
end = &p;
|
|
|
|
else
|
|
|
|
end = NULL;
|
|
|
|
|
1997-08-20 03:53:21 +00:00
|
|
|
while (g->gaih)
|
|
|
|
{
|
1999-07-28 03:27:45 +00:00
|
|
|
if (hints->ai_family == g->family || hints->ai_family == AF_UNSPEC)
|
1997-08-20 03:53:21 +00:00
|
|
|
{
|
|
|
|
j++;
|
1999-07-28 03:27:45 +00:00
|
|
|
if (pg == NULL || pg->gaih != g->gaih)
|
1997-08-20 03:53:21 +00:00
|
|
|
{
|
|
|
|
pg = g;
|
1999-07-28 03:27:45 +00:00
|
|
|
i = g->gaih (name, pservice, hints, end);
|
|
|
|
if (i != 0)
|
1997-08-20 03:53:21 +00:00
|
|
|
{
|
1999-09-12 19:24:42 +00:00
|
|
|
/* EAI_NODATA is a more specific result as it says that
|
|
|
|
we found a result but it is not usable. */
|
|
|
|
if (last_i != (GAIH_OKIFUNSPEC | -EAI_NODATA))
|
|
|
|
last_i = i;
|
|
|
|
|
1999-07-28 03:27:45 +00:00
|
|
|
if (hints->ai_family == AF_UNSPEC && (i & GAIH_OKIFUNSPEC))
|
2002-08-29 08:51:26 +00:00
|
|
|
{
|
|
|
|
++g;
|
|
|
|
continue;
|
|
|
|
}
|
1997-08-20 03:53:21 +00:00
|
|
|
|
2002-08-29 08:51:26 +00:00
|
|
|
freeaddrinfo (p);
|
1997-08-20 03:53:21 +00:00
|
|
|
|
1999-07-28 03:27:45 +00:00
|
|
|
return -(i & GAIH_EAI);
|
1997-08-20 03:53:21 +00:00
|
|
|
}
|
|
|
|
if (end)
|
2003-11-18 07:04:13 +00:00
|
|
|
while (*end)
|
|
|
|
{
|
|
|
|
end = &((*end)->ai_next);
|
|
|
|
++nresults;
|
|
|
|
}
|
1997-08-20 03:53:21 +00:00
|
|
|
}
|
1996-10-21 01:26:31 +00:00
|
|
|
}
|
1997-08-20 03:53:21 +00:00
|
|
|
++g;
|
1996-10-21 01:26:31 +00:00
|
|
|
}
|
|
|
|
|
1997-08-20 03:53:21 +00:00
|
|
|
if (j == 0)
|
1996-10-21 01:26:31 +00:00
|
|
|
return EAI_FAMILY;
|
|
|
|
|
2003-11-18 07:04:13 +00:00
|
|
|
if (nresults > 1)
|
|
|
|
{
|
|
|
|
/* Sort results according to RFC 3484. */
|
|
|
|
struct sort_result results[nresults];
|
|
|
|
struct addrinfo *q;
|
|
|
|
|
|
|
|
for (i = 0, q = p; q != NULL; ++i, q = q->ai_next)
|
|
|
|
{
|
|
|
|
results[i].dest_addr = q;
|
|
|
|
results[i].got_source_addr = false;
|
|
|
|
|
|
|
|
/* We overwrite the type with SOCK_DGRAM since we do not
|
|
|
|
want connect() to connect to the other side. If we
|
|
|
|
cannot determine the source address remember this
|
|
|
|
fact. */
|
|
|
|
int fd = __socket (q->ai_family, SOCK_DGRAM, IPPROTO_IP);
|
|
|
|
if (fd != -1)
|
|
|
|
{
|
|
|
|
socklen_t sl = sizeof (results[i].source_addr);
|
|
|
|
if (__connect (fd, q->ai_addr, q->ai_addrlen) == 0
|
|
|
|
&& __getsockname (fd,
|
|
|
|
(struct sockaddr *) &results[i].source_addr,
|
|
|
|
&sl) == 0)
|
|
|
|
results[i].got_source_addr = true;
|
|
|
|
|
|
|
|
close_not_cancel_no_status (fd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We got all the source addresses we can get, now sort using
|
|
|
|
the information. */
|
|
|
|
qsort (results, nresults, sizeof (results[0]), rfc3484_sort);
|
|
|
|
|
|
|
|
/* Queue the results up as they come out of sorting. */
|
|
|
|
q = p = results[0].dest_addr;
|
|
|
|
for (i = 1; i < nresults; ++i)
|
|
|
|
q = q->ai_next = results[i].dest_addr;
|
|
|
|
q->ai_next = NULL;
|
|
|
|
}
|
|
|
|
|
1997-08-20 03:53:21 +00:00
|
|
|
if (p)
|
|
|
|
{
|
|
|
|
*pai = p;
|
|
|
|
return 0;
|
|
|
|
}
|
1996-10-21 01:26:31 +00:00
|
|
|
|
1999-09-12 19:24:42 +00:00
|
|
|
if (pai == NULL && last_i == 0)
|
1997-02-19 04:43:53 +00:00
|
|
|
return 0;
|
|
|
|
|
2002-08-29 08:51:26 +00:00
|
|
|
freeaddrinfo (p);
|
1996-10-21 01:26:31 +00:00
|
|
|
|
1999-09-12 19:24:42 +00:00
|
|
|
return last_i ? -(last_i & GAIH_EAI) : EAI_NONAME;
|
1996-10-21 01:26:31 +00:00
|
|
|
}
|
2002-08-06 06:09:28 +00:00
|
|
|
libc_hidden_def (getaddrinfo)
|
1996-10-21 01:26:31 +00:00
|
|
|
|
2003-06-16 17:18:06 +00:00
|
|
|
static_link_warning (getaddrinfo)
|
|
|
|
|
1997-08-20 03:53:21 +00:00
|
|
|
void
|
|
|
|
freeaddrinfo (struct addrinfo *ai)
|
1996-10-21 01:26:31 +00:00
|
|
|
{
|
|
|
|
struct addrinfo *p;
|
|
|
|
|
1997-08-20 03:53:21 +00:00
|
|
|
while (ai != NULL)
|
|
|
|
{
|
|
|
|
p = ai;
|
|
|
|
ai = ai->ai_next;
|
|
|
|
free (p);
|
|
|
|
}
|
1996-10-21 01:26:31 +00:00
|
|
|
}
|
2002-08-06 06:09:28 +00:00
|
|
|
libc_hidden_def (freeaddrinfo)
|