From 76942b0fed33963e6ed1c404ef8d0f9b7aee104d Mon Sep 17 00:00:00 2001 From: Mark Andrews Date: Thu, 27 Jan 2000 08:08:03 +0000 Subject: [PATCH] checkpoint --- bin/tests/gxbn_test.c | 14 +- lib/lwres/Makefile.in | 7 +- lib/lwres/gethost.c | 145 +++++++-- lib/lwres/getnet.c | 58 ++-- lib/lwres/herror.c | 96 ++++++ lib/lwres/include/lwres/netdb.h.in | 474 +++++++++++++++++++++-------- 6 files changed, 616 insertions(+), 178 deletions(-) create mode 100644 lib/lwres/herror.c diff --git a/bin/tests/gxbn_test.c b/bin/tests/gxbn_test.c index eb3076d648..18d709bd22 100644 --- a/bin/tests/gxbn_test.c +++ b/bin/tests/gxbn_test.c @@ -16,7 +16,11 @@ */ #include +#include #include + +#include + #include static void @@ -46,21 +50,23 @@ print_he(struct hostent *he, int error, const char *fun, const char *name) { i++; } } else { - printf("%s(%s): error = %d\n", fun, name, error); + printf("%s(%s): error = %d (%s)\n", fun, name, error, + hstrerror(error)); } } int main(int argc, char **argv) { struct hostent *he; - char **c; int error; + (void)argc; + while (argv[1] != NULL) { he = gethostbyname(argv[1]); - print_he(he, 0 /* XXX h_errno */, "gethostbyname", argv[1]); + print_he(he, h_errno, "gethostbyname", argv[1]); - he = getipnodebyname(argv[1], AF_INET, AI_DEFAULT|AI_ALL, + he = getipnodebyname(argv[1], AF_INET6, AI_DEFAULT|AI_ALL, &error); print_he(he, error, "getipnodebyname", argv[1]); if (he != NULL) diff --git a/lib/lwres/Makefile.in b/lib/lwres/Makefile.in index dd57e95772..359c2b8320 100644 --- a/lib/lwres/Makefile.in +++ b/lib/lwres/Makefile.in @@ -27,12 +27,13 @@ CWARNINGS = # Alphabetically OBJS = context.@O@ getaddrinfo.@O@ gethost.@O@ getipnode.@O@ \ - getnameinfo.@O@ getnet.@O@ lwbuffer.@O@ lwpacket.@O@ \ - lwresutil.@O@ lwres_gabn.@O@ lwres_gnba.@O@ lwres_noop.@O@ + getnameinfo.@O@ getnet.@O@ herror.@O@ lwbuffer.@O@ \ + lwpacket.@O@ lwresutil.@O@ lwres_gabn.@O@ lwres_gnba.@O@ \ + lwres_noop.@O@ # Alphabetically SRCS = context.c getaddrinfo.c gethost.c getipnode.c \ - getnameinfo.c getnet.c lwbuffer.c lwpacket.c \ + getnameinfo.c getnet.c herror.c lwbuffer.c lwpacket.c \ lwresutil.c lwres_gabn.c lwres_gnba.c lwres_noop.c LIBS = @LIBS@ diff --git a/lib/lwres/gethost.c b/lib/lwres/gethost.c index 1a43898b06..927e46b3db 100644 --- a/lib/lwres/gethost.c +++ b/lib/lwres/gethost.c @@ -1,8 +1,10 @@ #include #include #include +#include static struct hostent *he = NULL; +static int copytobuf(struct hostent *, struct hostent *, char *, int); struct hostent * gethostbyname(const char *name) { @@ -16,19 +18,18 @@ gethostbyname(const char *name) { return (he); } -#ifdef ISC_LWRES_GETHOSTBYADDRVOID struct hostent * -gethostbyaddr(const void *addr, size_t len, int type) { +gethostbyname2(const char *name, int af) { int error; - if (he != NULL) + if (he != NULL) freehostent(he); - he = getipnodebyaddr(addr, len, type, &error); + he = getipnodebyname(name, af, 0, &error); h_errno = error; return (he); } -#else + struct hostent * gethostbyaddr(const char *addr, int len, int type) { int error; @@ -40,7 +41,6 @@ gethostbyaddr(const char *addr, int len, int type) { h_errno = error; return (he); } -#endif struct hostent * gethostent(void) { @@ -51,28 +51,131 @@ gethostent(void) { return (NULL); } -#ifdef ISC_LWRES_SETHOSTENTINT -int -sethostent(int stayopen) { - (void)stayopen; - return (0); -} -#else void sethostent(int stayopen) { /* empty */ (void)stayopen; } -#endif -#ifdef ISC_LWRES_ENDHOSTENTINT -int -endhostent(void) { - return(0); -} -#else void endhostent(void) { /* empty */ } -#endif + +struct hostent * +gethostbyname_r(const char *name, struct hostent *resbuf, + char *buf, int buflen, int *error) { + struct hostent *he; + int res; + + he = getipnodebyname(name, AF_INET, 0, error); + if (he == NULL) + return (NULL); + res = copytobuf(he, resbuf, buf, buflen); + if (he != NULL) + freehostent(he); + if (res != 0) { + errno = ERANGE; + return (NULL); + } + return (resbuf); +} + +struct hostent * +gethostbyaddr_r(const char *addr, int len, int type, struct hostent *resbuf, + char *buf, int buflen, int *error) { + struct hostent *he; + int res; + + he = getipnodebyaddr(addr, len, type, error); + if (he == NULL) + return (NULL); + res = copytobuf(he, resbuf, buf, buflen); + if (he != NULL) + freehostent(he); + if (res != 0) { + errno = ERANGE; + return (NULL); + } + return (resbuf); +} + +struct hostent * +gethostent_r(struct hostent *resbuf, char *buf, int buflen, int *error) { + (void)resbuf; + (void)buf; + (void)buflen; + *error = 0; + return (NULL); +} + +void +sethostent_r(int stayopen) { + (void)stayopen; + /* empty */ +} + +void +endhostent_r(void) { + /* empty */ +} + +static int +copytobuf(struct hostent *he, struct hostent *hptr, char *buf, int buflen) { + char *cp; + char **ptr; + int i, n; + int nptr, len; + + /* Find out the amount of space required to store the answer. */ + nptr = 2; /* NULL ptrs */ + len = (char *)ALIGN(buf) - buf; + for (i = 0; he->h_addr_list[i]; i++, nptr++) { + len += he->h_length; + } + for (i = 0; he->h_aliases[i]; i++, nptr++) { + len += strlen(he->h_aliases[i]) + 1; + } + len += strlen(he->h_name) + 1; + len += nptr * sizeof(char*); + + if (len > buflen) { + return (-1); + } + + /* copy address size and type */ + hptr->h_addrtype = he->h_addrtype; + n = hptr->h_length = he->h_length; + + ptr = (char **)ALIGN(buf); + cp = (char *)ALIGN(buf) + nptr * sizeof(char *); + + /* copy address list */ + hptr->h_addr_list = ptr; + for (i = 0; he->h_addr_list[i]; i++ , ptr++) { + memcpy(cp, he->h_addr_list[i], n); + hptr->h_addr_list[i] = cp; + cp += n; + i++; + } + hptr->h_addr_list[i] = NULL; + ptr++; + + /* copy official name */ + n = strlen(he->h_name) + 1; + strcpy(cp, he->h_name); + hptr->h_name = cp; + cp += n; + + /* copy aliases */ + hptr->h_aliases = ptr; + for (i = 0 ; he->h_aliases[i]; i++) { + n = strlen(he->h_aliases[i]) + 1; + strcpy(cp, he->h_aliases[i]); + hptr->h_aliases[i] = cp; + cp += n; + } + hptr->h_aliases[i] = NULL; + + return (0); +} diff --git a/lib/lwres/getnet.c b/lib/lwres/getnet.c index 48bd976caf..25907521f6 100644 --- a/lib/lwres/getnet.c +++ b/lib/lwres/getnet.c @@ -12,18 +12,6 @@ getnetbyname(const char *name) { return (NULL); } -#ifdef ISC_LWRES_GETNETBYADDRINADDR -struct netent * -getnetbyaddr(in_addr_t net, int type) { - - if (type == AF_INET) - return (NULL); - - /* XXX */ - UNUSED(net); - return (NULL); -} -#else struct netent * getnetbyaddr(unsigned long net, int type) { @@ -34,7 +22,6 @@ getnetbyaddr(unsigned long net, int type) { UNUSED(net); return (NULL); } -#endif struct netent * getnetent() { @@ -42,32 +29,43 @@ getnetent() { return (NULL); } -#ifdef ISC_LWRES_SETNETENTINT -int -setnetent(int stayopen) { - - UNUSED(stayopen); - /* empty */ - return (1); /* success */ -} -#else void setnetent(int stayopen) { UNUSED(stayopen); /* empty */ } -#endif -#ifdef ISC_LWRES_ENDNETENTINT -int -endnetent() { - return (0); -} -#else void endnetent() { /* empty */ } -#endif +struct netent * +getnetbyname_r(const char *name, struct netent *resbuf, char *buf, + int buflen) +{ + return (NULL); +} + +struct netent * +getnetbyaddr_r(long addr, int type, struct netent *resbuf, char *buf, + int buflen) +{ + return (NULL); +} + +struct netent * +getnetent_r(struct netent *resbuf, char *buf, int buflen) { + return (NULL); +} + +void +setnetent_r(int stayopen) { + (void)stayopen; +} + +void +endnetent_r(void) { + /* empty */ +} diff --git a/lib/lwres/herror.c b/lib/lwres/herror.c new file mode 100644 index 0000000000..9c1460718e --- /dev/null +++ b/lib/lwres/herror.c @@ -0,0 +1,96 @@ +/* + * Copyright (c) 1987, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University 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 THE REGENTS 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 REGENTS 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. + */ + +/* + * Portions Copyright (c) 1996-1999 by Internet Software Consortium. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS + * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE + * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL + * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR + * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS + * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS + * SOFTWARE. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static const char sccsid[] = "@(#)herror.c 8.1 (Berkeley) 6/4/93"; +static const char rcsid[] = "$Id: herror.c,v 1.1 2000/01/27 08:08:02 marka Exp $"; +#endif /* LIBC_SCCS and not lint */ + +#include +#include + +int h_errno; + +/* + * these have never been declared in any header file so make them static + */ + +static const char *h_errlist[] = { + "Resolver Error 0 (no error)", + "Unknown host", /* 1 HOST_NOT_FOUND */ + "Host name lookup failure", /* 2 TRY_AGAIN */ + "Unknown server error", /* 3 NO_RECOVERY */ + "No address associated with name", /* 4 NO_ADDRESS */ +}; + +static int h_nerr = { sizeof h_errlist / sizeof h_errlist[0] }; + + +/* + * herror -- + * print the error indicated by the h_errno value. + */ +void +herror(const char *s) { + fprintf(stderr, "%s: %s\n", s, hstrerror(h_errno)); +} + +/* + * hstrerror -- + * return the string associated with a given "host" errno value. + */ +const char * +hstrerror(int err) { + if (err < 0) + return ("Resolver internal error"); + else if (err < h_nerr) + return (h_errlist[err]); + return ("Unknown resolver error"); +} diff --git a/lib/lwres/include/lwres/netdb.h.in b/lib/lwres/include/lwres/netdb.h.in index 5d79dae29a..0fb168c3a9 100644 --- a/lib/lwres/include/lwres/netdb.h.in +++ b/lib/lwres/include/lwres/netdb.h.in @@ -18,157 +18,391 @@ #ifndef lwres_netdb_h #define lwres_netdb_h 1 -#include +/* + * ++Copyright++ 1980, 1983, 1988, 1993 + * - + * Copyright (c) 1980, 1983, 1988, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University 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 THE REGENTS 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 REGENTS 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. + * - + * Portions Copyright (c) 1993 by Digital Equipment Corporation. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies, and that + * the name of Digital Equipment Corporation not be used in advertising or + * publicity pertaining to distribution of the document or software without + * specific, written prior permission. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL + * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT + * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL + * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR + * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS + * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS + * SOFTWARE. + * - + * Portions Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by WIDE Project and + * its contributors. + * 4. Neither the name of the project 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 THE PROJECT 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 PROJECT 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. + * - + * --Copyright-- + */ /* - * Define if we need to define struct addrinfo. + * @(#)netdb.h 8.1 (Berkeley) 6/2/93 + * $Id: netdb.h.in,v 1.8 2000/01/27 08:08:00 marka Exp $ */ -@ISC_LWRES_NEEDADDRINFO@ -/* - * Define if we need to prototype getipnodeby{name,addr} - * and freehostent. - */ -@ISC_LWRES_GETIPNODEPROTO@ - -/* - * Define if we need to prototype getaddrinfo and freeaddrinfo. - */ -@ISC_LWRES_GETADDRINFOPROTO@ - -/* - * Define if we need to prototype getnameinfo. - */ -@ISC_LWRES_GETNAMEINFOPROTO@ - -/* - * Define if sethostent returns int. - */ -@ISC_LWRES_SETNETENTINT@ - -/* - * Define if endhostent returns int. - */ -@ISC_LWRES_ENDNETENTINT@ - -/* - * Define if gethostbyaddr takes a void * as first arguement. - */ -@ISC_LWRES_GETHOSTBYADDRVOID@ - -/* - * Define if sethostent returns an int. - */ -@ISC_LWRES_SETHOSTENTINT@ - -/* - * Define if endhostent returns an int. - */ -@ISC_LWRES_ENDHOSTENTINT@ - -/* - * Define if h_errno if not defined by netdb.h. - */ -@ISC_LWRES_NEEDHERRNO@ - -#ifdef ISC_LWRES_NEEDADDRINFO -struct addrinfo { - int ai_flags; /* AI_PASSIVE, AI_CANONNAME */ - int ai_family; /* PF_xxx */ - int ai_socktype; /* SOCK_xxx */ - int ai_protocol; /* 0 or IPPROTO_xxx for IPv4 and IPv6 */ - size_t ai_addrlen; /* length of ai_addr */ - char *ai_canonname; /* canonical name for hostname */ - struct sockaddr *ai_addr; /* binary address */ - struct addrinfo *ai_next; /* next structure in linked list */ -}; +#include +#if (!defined(BSD)) || (BSD < 199306) +# include #endif +#include +#include +#include + +#ifndef _PATH_HEQUIV +#define _PATH_HEQUIV "/etc/hosts.equiv" +#endif +#ifndef _PATH_HOSTS +#define _PATH_HOSTS "/etc/hosts" +#endif +#ifndef _PATH_NETWORKS +#define _PATH_NETWORKS "/etc/networks" +#endif +#ifndef _PATH_PROTOCOLS +#define _PATH_PROTOCOLS "/etc/protocols" +#endif +#ifndef _PATH_SERVICES +#define _PATH_SERVICES "/etc/services" +#endif + +/* + * Structures returned by network data base library. All addresses are + * supplied in host order, and returned in network order (suitable for + * use in system calls). + */ +struct hostent { + char *h_name; /* official name of host */ + char **h_aliases; /* alias list */ + int h_addrtype; /* host address type */ + int h_length; /* length of address */ + char **h_addr_list; /* list of addresses from name server */ +#define h_addr h_addr_list[0] /* address, for backward compatiblity */ +}; + +/* + * Assumption here is that a network number + * fits in an unsigned long -- probably a poor one. + */ +struct netent { + char *n_name; /* official name of net */ + char **n_aliases; /* alias list */ + int n_addrtype; /* net address type */ + unsigned long n_net; /* network # */ +}; + +struct servent { + char *s_name; /* official service name */ + char **s_aliases; /* alias list */ + int s_port; /* port # */ + char *s_proto; /* protocol to use */ +}; + +struct protoent { + char *p_name; /* official protocol name */ + char **p_aliases; /* alias list */ + int p_proto; /* protocol # */ +}; + +struct addrinfo { + int ai_flags; /* AI_PASSIVE, AI_CANONNAME */ + int ai_family; /* PF_xxx */ + int ai_socktype; /* SOCK_xxx */ + int ai_protocol; /* 0 or IPPROTO_xxx for IPv4 and IPv6 */ + size_t ai_addrlen; /* length of ai_addr */ + char *ai_canonname; /* canonical name for hostname */ + struct sockaddr *ai_addr; /* binary address */ + struct addrinfo *ai_next; /* next structure in linked list */ +}; + +/* + * Error return codes from gethostbyname() and gethostbyaddr() + * (left in extern int h_errno). + */ + +#define NETDB_INTERNAL -1 /* see errno */ +#define NETDB_SUCCESS 0 /* no problem */ +#define HOST_NOT_FOUND 1 /* Authoritative Answer Host not found */ +#define TRY_AGAIN 2 /* Non-Authoritive Host not found, or SERVERFAIL */ +#define NO_RECOVERY 3 /* Non recoverable errors, FORMERR, REFUSED, NOTIMP */ +#define NO_DATA 4 /* Valid name, no data record of requested type */ +#define NO_ADDRESS NO_DATA /* no address, look for MX record */ /* * Error return codes from getaddrinfo() */ -#ifndef EAI_ADDRFAMILY -#define EAI_ADDRFAMILY 1 /* address family for hostname not supported */ -#define EAI_AGAIN 2 /* temporary failure in name resolution */ -#define EAI_BADFLAGS 3 /* invalid value for ai_flags */ -#define EAI_FAIL 4 /* non-recoverable failure in name resolution */ -#define EAI_FAMILY 5 /* ai_family not supported */ -#define EAI_MEMORY 6 /* memory allocation failure */ -#define EAI_NODATA 7 /* no address associated with hostname */ -#define EAI_NONAME 8 /* hostname nor servname provided, or not known */ -#define EAI_SERVICE 9 /* servname not supported for ai_socktype */ -#define EAI_SOCKTYPE 10 /* ai_socktype not supported */ -#define EAI_SYSTEM 11 /* system error returned in errno */ -#define EAI_BADHINTS 12 -#define EAI_PROTOCOL 13 -#define EAI_MAX 14 -#endif +#define EAI_ADDRFAMILY 1 /* address family for hostname not supported */ +#define EAI_AGAIN 2 /* temporary failure in name resolution */ +#define EAI_BADFLAGS 3 /* invalid value for ai_flags */ +#define EAI_FAIL 4 /* non-recoverable failure in name resolution */ +#define EAI_FAMILY 5 /* ai_family not supported */ +#define EAI_MEMORY 6 /* memory allocation failure */ +#define EAI_NODATA 7 /* no address associated with hostname */ +#define EAI_NONAME 8 /* hostname nor servname provided, or not known */ +#define EAI_SERVICE 9 /* servname not supported for ai_socktype */ +#define EAI_SOCKTYPE 10 /* ai_socktype not supported */ +#define EAI_SYSTEM 11 /* system error returned in errno */ +#define EAI_BADHINTS 12 +#define EAI_PROTOCOL 13 +#define EAI_MAX 14 /* * Flag values for getaddrinfo() */ -#ifndef AI_PASSIVE -#define AI_PASSIVE 0x00000001 -#define AI_CANONNAME 0x00000002 -#endif -#ifndef AI_NUMERICHOST -#define AI_NUMERICHOST 0x00000004 -#endif +#define AI_PASSIVE 0x00000001 +#define AI_CANONNAME 0x00000002 +#define AI_NUMERICHOST 0x00000004 +#define AI_MASK 0x00000007 /* * Flag values for getipnodebyname() */ -#ifndef AI_V4MAPPED -#define AI_V4MAPPED 0x00000008 -#define AI_ALL 0x00000010 -#define AI_ADDRCONFIG 0x00000020 -#define AI_DEFAULT (AI_V4MAPPED|AI_ADDRCONFIG) -#endif +#define AI_V4MAPPED 0x00000008 +#define AI_ALL 0x00000010 +#define AI_ADDRCONFIG 0x00000020 +#define AI_DEFAULT (AI_V4MAPPED|AI_ADDRCONFIG) /* * Constants for getnameinfo() */ -#ifndef NI_MAXHOST -#define NI_MAXHOST 1025 -#define NI_MAXSERV 32 -#endif +#define NI_MAXHOST 1025 +#define NI_MAXSERV 32 /* * Flag values for getnameinfo() */ -#ifndef NI_NOFQDN -#define NI_NOFQDN 0x00000001 -#define NI_NUMERICHOST 0x00000002 -#define NI_NAMEREQD 0x00000004 -#define NI_NUMERICSERV 0x00000008 -#define NI_DGRAM 0x00000010 -#endif +#define NI_NOFQDN 0x00000001 +#define NI_NUMERICHOST 0x00000002 +#define NI_NAMEREQD 0x00000004 +#define NI_NUMERICSERV 0x00000008 +#define NI_DGRAM 0x00000010 -#ifdef ISC_LWRES_GETADDRINFOPROTO -int -getaddrinfo(const char *hostname, const char *servname, - const struct addrinfo *hints, struct addrinfo **res); +/* + * Define to map into lwres_ namespace. + */ -void -freeaddrinfo(struct addrinfo *ai); -#endif +#define LWRES_NAMESPACE -#ifdef ISC_LWRES_GETNAMEINFOPROTO -int -getnameinfo(const struct sockaddr *sa, size_t salen, char *host, - size_t hostlen, char *serv, size_t servlen, int flags); -#endif +#ifdef LWRES_NAMESPACE -#ifdef ISC_LWRES_GETIPNODEPROTO -struct hostent * -getipnodebyname(const char *name, int af, int flags, int *error_num); +#define getnameinfo lwres_getnameinfo +#define getaddrinfo lwres_getaddrinfo +#define freeaddrinfo lwres_freeaddrinfo +#define gai_strerror lwres_gai_strerror -struct hostent * -getipnodebyaddr(const void *src, size_t len, int af, int *error_num); +#define herror lwres_herror +#define hstrerror lwres_hstrerror -void -freehostent(struct hostent *); -#endif +#define getipnodebyname lwres_getipnodebyname +#define getipnodebyaddr lwres_getipnodebyaddr +#define freehostent lwres_freehostent + +#define gethostbyname lwres_gethostbyname +#define gethostbyname2 lwres_gethostbyname2 +#define gethostbyaddr lwres_gethostbyaddr +#define gethostent lwres_gethostent +#define sethostent lwres_sethostent +#define endhostent lwres_endhostent +/* #define sethostfile lwres_sethostfile */ + +#define gethostbyname_r lwres_gethostbyname_r +#define gethostbyaddr_r lwres_gethostbyaddr_r +#define gethostent_r lwres_gethostent_r +#define sethostent_r lwres_sethostent_r +#define endhostent_r lwres_endhostent_r + +#define getservbyname lwres_getservbyname +#define getservbyport lwres_getservbyport +#define getservent lwres_getservent +#define setservent lwres_setservent +#define endservent lwres_endservent + +#define getservbyname_r lwres_getservbyname_r +#define getservbyport_r lwres_getservbyport_r +#define getservent_r lwres_getservent_r +#define setservent_r lwres_setservent_r +#define endservent_r lwres_endservent_r + +#define getprotobyname lwres_getprotobyname +#define getprotobynumber lwres_getprotobynumber +#define getprotoent lwres_getprotoent +#define setprotoent lwres_setprotoent +#define endprotoent lwres_endprotoent + +#define getprotobyname_r lwres_getprotobyname_r +#define getprotobynumber_r lwres_getprotobynumber_r +#define getprotoent_r lwres_getprotoent_r +#define setprotoent_r lwres_setprotoent_r +#define endprotoent_r lwres_endprotoent_r + +#define getnetbyname lwres_getnetbyname +#define getnetbyaddr lwres_getnetbyaddr +#define getnetent lwres_getnetent +#define setnetent lwres_setnetent +#define endnetent lwres_endnetent + +#define getnetbyname_r lwres_getnetbyname_r +#define getnetbyaddr_r lwres_getnetbyaddr_r +#define getnetent_r lwres_getnetent_r +#define setnetent_r lwres_setnetent_r +#define endnetent_r lwres_endnetent_r + +#define h_errno lwres_h_errno #endif + +extern int h_errno; + +__BEGIN_DECLS +void endhostent __P((void)); +void endnetent __P((void)); +void endprotoent __P((void)); +void endservent __P((void)); +struct hostent *gethostbyaddr __P((const char *, int, int)); +struct hostent *gethostbyname __P((const char *)); +struct hostent *gethostbyname2 __P((const char *, int)); +struct hostent *gethostent __P((void)); +struct netent *getnetbyaddr __P((unsigned long, int)); +struct netent *getnetbyname __P((const char *)); +struct netent *getnetent __P((void)); +struct protoent *getprotobyname __P((const char *)); +struct protoent *getprotobynumber __P((int)); +struct protoent *getprotoent __P((void)); +struct servent *getservbyname __P((const char *, const char *)); +struct servent *getservbyport __P((int, const char *)); +struct servent *getservent __P((void)); +void herror __P((const char *)); +const char *hstrerror __P((int)); +void sethostent __P((int)); +/* void sethostfile __P((const char *)); */ +void setnetent __P((int)); +void setprotoent __P((int)); +void setservent __P((int)); +int getaddrinfo __P((const char *, const char *, + const struct addrinfo *, struct addrinfo **)); +int getnameinfo __P((const struct sockaddr *, size_t, char *, + size_t, char *, size_t, int)); +void freeaddrinfo __P((struct addrinfo *)); +char *gai_strerror __P((int)); +struct hostent *getipnodebyname __P((const char *, int, int, int *)); +struct hostent *getipnodebyaddr __P((const void *, size_t, int, int *)); +void freehostent __P((struct hostent *)); + + +#ifdef _REENTRANT +struct hostent *gethostbyaddr_r __P((const char *, int, int, struct hostent *, + char *, int, int *)); +struct hostent *gethostbyname_r __P((const char *, struct hostent *, + char *, int, int *)); +struct hostent *gethostent_r __P((struct hostent *, char *, int, int *)); +void sethostent_r __P((int)); +void endhostent_r __P((void)); + +struct netent *getnetbyname_r __P((const char *, struct netent *, + char *, int)); +struct netent *getnetbyaddr_r __P((long, int, struct netent *, + char *, int)); +struct netent *getnetent_r __P((struct netent *, char *, int)); +void setnetent_r __P((int)); +void endnetent_r __P((void)); + +struct protoent *getprotobyname_r __P((const char *, + struct protoent *, char *, int)); +struct protoent *getprotobynumber_r __P((int, + struct protoent *, char *, int)); +struct protoent *getprotoent_r __P((struct protoent *, char *, int)); +void setprotoent_r __P((int)); +void endprotoent_r __P((void)); + +struct servent *getservbyname_r __P((const char *name, const char *, + struct servent *, char *, int)); +struct servent *getservbyport_r __P((int port, const char *, + struct servent *, char *, int)); +struct servent *getservent_r __P((struct servent *, char *, int)); +void setservent_r __P((int)); +void endservent_r __P((void)); +#endif +__END_DECLS + +/* This is nec'y to make this include file properly replace the sun version. */ +#ifdef sun +#ifdef __GNU_LIBRARY__ +#include +#else +struct rpcent { + char *r_name; /* name of server for this rpc program */ + char **r_aliases; /* alias list */ + int r_number; /* rpc program number */ +}; +struct rpcent *getrpcbyname(), *getrpcbynumber(), *getrpcent(); +#endif /* __GNU_LIBRARY__ */ +#endif /* sun */ +#endif