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.
|
|
|
|
4. All advertising materials mentioning features or use of this software
|
|
|
|
must display the following acknowledgement with the name(s) of the
|
|
|
|
authors as specified in the copyright notice(s) substituted where
|
|
|
|
indicated:
|
|
|
|
|
|
|
|
This product includes software developed by <name(s)>, The Inner
|
|
|
|
Net, and other contributors.
|
|
|
|
|
|
|
|
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>
|
|
|
|
#include <netdb.h>
|
2000-05-27 08:09:40 +00:00
|
|
|
#include <resolv.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>
|
1997-02-19 04:43:53 +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
|
|
|
|
1997-08-20 03:53:21 +00:00
|
|
|
static struct gaih_servtuple nullserv = { NULL, 0, 0, 0 };
|
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;
|
|
|
|
char *name;
|
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
|
|
|
|
1997-08-20 03:53:21 +00:00
|
|
|
static struct gaih_typeproto gaih_inet_typeproto[] =
|
|
|
|
{
|
2000-01-18 09:56:22 +00:00
|
|
|
{ 0, 0, NULL, 0 },
|
|
|
|
{ SOCK_STREAM, IPPROTO_TCP, (char *) "tcp", 0 },
|
2000-01-05 21:32:20 +00:00
|
|
|
{ SOCK_DGRAM, IPPROTO_UDP, (char *) "udp", 0 },
|
2000-11-10 04:15:55 +00:00
|
|
|
{ SOCK_RAW, 0, (char *) "raw", GAI_PROTO_PROTOANY|GAI_PROTO_NOSERVICE },
|
2000-01-05 21:32:20 +00:00
|
|
|
{ 0, 0, NULL, 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);
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct addrinfo default_hints =
|
|
|
|
{ 0, PF_UNSPEC, 0, 0, 0, NULL, NULL, NULL };
|
|
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2000-01-05 21:32:20 +00:00
|
|
|
struct gaih_typeproto *tp = gaih_inet_typeproto + 1;
|
|
|
|
|
|
|
|
while (tp->name != NULL
|
|
|
|
&& ((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
|
|
|
|
|
|
|
if (tp->name == NULL)
|
|
|
|
{
|
|
|
|
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
|
|
|
}
|
1996-10-21 01:26:31 +00:00
|
|
|
|
1997-08-20 03:53:21 +00:00
|
|
|
static int
|
|
|
|
gaih_inet_serv (const char *servicename, 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;
|
|
|
|
}
|
|
|
|
|
1997-08-20 03:53:21 +00:00
|
|
|
#define gethosts(_family, _type) \
|
|
|
|
{ \
|
|
|
|
int i, herrno; \
|
|
|
|
size_t tmpbuflen; \
|
|
|
|
struct hostent th; \
|
|
|
|
char *tmpbuf; \
|
|
|
|
tmpbuflen = 512; \
|
2000-11-18 08:30:20 +00:00
|
|
|
no_data = 0; \
|
1997-08-20 03:53:21 +00:00
|
|
|
do { \
|
|
|
|
tmpbuflen *= 2; \
|
|
|
|
tmpbuf = __alloca (tmpbuflen); \
|
|
|
|
rc = __gethostbyname2_r (name, _family, &th, tmpbuf, \
|
|
|
|
tmpbuflen, &h, &herrno); \
|
1999-09-05 00:08:27 +00:00
|
|
|
} while (rc == ERANGE && herrno == NETDB_INTERNAL); \
|
2000-08-21 19:12:24 +00:00
|
|
|
if (rc != 0) \
|
1997-08-20 03:53:21 +00:00
|
|
|
{ \
|
2000-08-21 19:12:24 +00:00
|
|
|
if (herrno == NETDB_INTERNAL) \
|
|
|
|
{ \
|
|
|
|
__set_h_errno (herrno); \
|
|
|
|
return -EAI_SYSTEM; \
|
|
|
|
} \
|
|
|
|
if (herrno == TRY_AGAIN) \
|
2000-11-18 08:30:20 +00:00
|
|
|
no_data = EAI_AGAIN; \
|
|
|
|
else \
|
|
|
|
no_data = herrno == NO_DATA; \
|
1997-08-20 03:53:21 +00:00
|
|
|
} \
|
2000-11-18 08:30:20 +00:00
|
|
|
else if (h != NULL) \
|
1997-08-20 03:53:21 +00:00
|
|
|
{ \
|
|
|
|
for (i = 0; h->h_addr_list[i]; i++) \
|
|
|
|
{ \
|
2000-11-10 04:15:55 +00:00
|
|
|
if (*pat == NULL) { \
|
1999-09-12 19:24:42 +00:00
|
|
|
*pat = __alloca (sizeof(struct gaih_addrtuple)); \
|
2000-11-10 04:15:55 +00:00
|
|
|
(*pat)->scopeid = 0; \
|
|
|
|
} \
|
1997-08-20 03:53:21 +00:00
|
|
|
(*pat)->next = NULL; \
|
|
|
|
(*pat)->family = _family; \
|
|
|
|
memcpy ((*pat)->addr, h->h_addr_list[i], \
|
|
|
|
sizeof(_type)); \
|
|
|
|
pat = &((*pat)->next); \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
{
|
|
|
|
struct gaih_typeproto *tp = gaih_inet_typeproto;
|
|
|
|
struct gaih_servtuple *st = &nullserv;
|
1997-02-19 04:43:53 +00:00
|
|
|
struct gaih_addrtuple *at = NULL;
|
1997-08-20 03:53:21 +00:00
|
|
|
int rc;
|
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;
|
|
|
|
|
|
|
|
while (tp->name != NULL
|
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;
|
|
|
|
|
1997-08-20 03:53:21 +00:00
|
|
|
if (tp->name == NULL)
|
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)
|
|
|
|
{
|
|
|
|
if (tp->name != NULL)
|
|
|
|
{
|
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;
|
|
|
|
for (tp++; tp->name; tp++)
|
|
|
|
{
|
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
|
|
|
}
|
|
|
|
if (st == &nullserv)
|
|
|
|
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;
|
|
|
|
for (++tp; tp->name != NULL; ++tp)
|
|
|
|
{
|
|
|
|
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
|
|
|
|
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;
|
|
|
|
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;
|
|
|
|
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;
|
1999-12-08 09:15:00 +00:00
|
|
|
int no_inet6_data;
|
2000-05-27 08:09:40 +00:00
|
|
|
int old_res_options = _res.options;
|
|
|
|
|
|
|
|
/* 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)
|
|
|
|
_res.options &= ~RES_USE_INET6;
|
1997-08-20 03:53:21 +00:00
|
|
|
|
1999-07-28 03:27:45 +00:00
|
|
|
if (req->ai_family == AF_UNSPEC || req->ai_family == AF_INET6)
|
1997-08-20 03:53:21 +00:00
|
|
|
gethosts (AF_INET6, struct in6_addr);
|
1999-12-08 09:15:00 +00:00
|
|
|
no_inet6_data = no_data;
|
1997-08-20 03:53:21 +00:00
|
|
|
|
2000-05-27 08:09:40 +00:00
|
|
|
if (req->ai_family == AF_UNSPEC)
|
|
|
|
_res.options = old_res_options;
|
|
|
|
|
1999-07-28 03:27:45 +00:00
|
|
|
if (req->ai_family == AF_UNSPEC || req->ai_family == AF_INET)
|
1997-08-20 03:53:21 +00:00
|
|
|
gethosts (AF_INET, struct in_addr);
|
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)
|
|
|
|
memcpy (at->addr, &in6addr_loopback, sizeof (struct in6_addr));
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
char buffer[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255"];
|
1996-10-21 01:26:31 +00:00
|
|
|
|
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;
|
|
|
|
char *tmpbuf;
|
1996-10-21 01:26:31 +00:00
|
|
|
|
1997-08-20 03:53:21 +00:00
|
|
|
do
|
|
|
|
{
|
|
|
|
tmpbuflen *= 2;
|
|
|
|
tmpbuf = __alloca (tmpbuflen);
|
1996-10-21 01:26:31 +00:00
|
|
|
|
1997-08-20 03:53:21 +00:00
|
|
|
if (tmpbuf == NULL)
|
|
|
|
return -EAI_MEMORY;
|
|
|
|
|
|
|
|
rc = __gethostbyaddr_r (at2->addr,
|
|
|
|
((at2->family == AF_INET6)
|
|
|
|
? sizeof(struct in6_addr)
|
|
|
|
: sizeof(struct in_addr)),
|
|
|
|
at2->family, &th, tmpbuf, tmpbuflen,
|
|
|
|
&h, &herrno);
|
|
|
|
|
|
|
|
}
|
1999-09-12 19:24:42 +00:00
|
|
|
while (rc == errno && 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (h == NULL)
|
|
|
|
c = inet_ntop (at2->family, at2->addr, buffer, sizeof(buffer));
|
|
|
|
else
|
|
|
|
c = h->h_name;
|
|
|
|
|
|
|
|
if (c == NULL)
|
|
|
|
return GAIH_OKIFUNSPEC | -EAI_NONAME;
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
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;
|
|
|
|
(*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
|
|
|
|
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 },
|
|
|
|
{ PF_LOCAL, gaih_local },
|
|
|
|
{ PF_UNSPEC, NULL }
|
|
|
|
};
|
1996-10-21 01:26:31 +00:00
|
|
|
|
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;
|
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;
|
|
|
|
|
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
|
|
|
|
1999-02-16 11:06:33 +00:00
|
|
|
if (hints->ai_flags & ~(AI_PASSIVE|AI_CANONNAME|AI_NUMERICHOST))
|
1996-10-21 01:26:31 +00:00
|
|
|
return EAI_BADFLAGS;
|
|
|
|
|
1997-08-20 03:53:21 +00:00
|
|
|
if ((hints->ai_flags & AI_CANONNAME) && name == NULL)
|
1996-10-21 01:26:31 +00:00
|
|
|
return EAI_BADFLAGS;
|
|
|
|
|
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))
|
1997-08-20 03:53:21 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if (p)
|
|
|
|
freeaddrinfo (p);
|
|
|
|
|
1999-07-28 03:27:45 +00:00
|
|
|
return -(i & GAIH_EAI);
|
1997-08-20 03:53:21 +00:00
|
|
|
}
|
|
|
|
if (end)
|
|
|
|
while(*end) end = &((*end)->ai_next);
|
|
|
|
}
|
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;
|
|
|
|
|
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;
|
|
|
|
|
1996-10-21 01:26:31 +00:00
|
|
|
if (p)
|
1997-08-20 03:53:21 +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
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|