]> git.proxmox.com Git - mirror_edk2.git/blobdiff - StdLib/BsdSocketLib/gethostbydns.c
edk2: Remove AppPkg, StdLib, StdLibPrivateInternalFiles
[mirror_edk2.git] / StdLib / BsdSocketLib / gethostbydns.c
diff --git a/StdLib/BsdSocketLib/gethostbydns.c b/StdLib/BsdSocketLib/gethostbydns.c
deleted file mode 100644 (file)
index 17c43ba..0000000
+++ /dev/null
@@ -1,816 +0,0 @@
-/*\r
- * ++Copyright++ 1985, 1988, 1993\r
- * -\r
- * Copyright (c) 1985, 1988, 1993\r
- *     The Regents of the University of California.  All rights reserved.\r
- *\r
- * Redistribution and use in source and binary forms, with or without\r
- * modification, are permitted provided that the following conditions\r
- * are met:\r
- * 1. Redistributions of source code must retain the above copyright\r
- *    notice, this list of conditions and the following disclaimer.\r
- * 2. Redistributions in binary form must reproduce the above copyright\r
- *    notice, this list of conditions and the following disclaimer in the\r
- *    documentation and/or other materials provided with the distribution.\r
- * 3. All advertising materials mentioning features or use of this software\r
- *    must display the following acknowledgement:\r
- *     This product includes software developed by the University of\r
- *     California, Berkeley and its contributors.\r
- * 4. Neither the name of the University nor the names of its contributors\r
- *    may be used to endorse or promote products derived from this software\r
- *    without specific prior written permission.\r
- *\r
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND\r
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE\r
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
- * SUCH DAMAGE.\r
- * -\r
- * Portions Copyright (c) 1993 by Digital Equipment Corporation.\r
- *\r
- * Permission to use, copy, modify, and distribute this software for any\r
- * purpose with or without fee is hereby granted, provided that the above\r
- * copyright notice and this permission notice appear in all copies, and that\r
- * the name of Digital Equipment Corporation not be used in advertising or\r
- * publicity pertaining to distribution of the document or software without\r
- * specific, written prior permission.\r
- *\r
- * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL\r
- * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES\r
- * OF MERCHANTABILITY AND FITNESS.   IN NO EVENT SHALL DIGITAL EQUIPMENT\r
- * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL\r
- * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR\r
- * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS\r
- * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS\r
- * SOFTWARE.\r
- * -\r
- * --Copyright--\r
- */\r
-\r
-/*\r
- * Portions copyright (c) 1999, 2000\r
- * Intel Corporation.\r
- * All rights reserved.\r
- * \r
- * Redistribution and use in source and binary forms, with or without\r
- * modification, are permitted provided that the following conditions\r
- * are met:\r
- * \r
- * 1. Redistributions of source code must retain the above copyright\r
- *    notice, this list of conditions and the following disclaimer.\r
- * \r
- * 2. Redistributions in binary form must reproduce the above copyright\r
- *    notice, this list of conditions and the following disclaimer in the\r
- *    documentation and/or other materials provided with the distribution.\r
- * \r
- * 3. All advertising materials mentioning features or use of this software\r
- *    must display the following acknowledgement:\r
- * \r
- *    This product includes software developed by Intel Corporation and\r
- *    its contributors.\r
- * \r
- * 4. Neither the name of Intel Corporation or its contributors may be\r
- *    used to endorse or promote products derived from this software\r
- *    without specific prior written permission.\r
- * \r
- * THIS SOFTWARE IS PROVIDED BY INTEL CORPORATION AND CONTRIBUTORS ``AS IS''\r
- * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
- * ARE DISCLAIMED.  IN NO EVENT SHALL INTEL CORPORATION OR CONTRIBUTORS BE\r
- * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF\r
- * THE POSSIBILITY OF SUCH DAMAGE.\r
- * \r
- */\r
-\r
-#if defined(LIBC_SCCS) && !defined(lint)\r
-static char sccsid[] = "@(#)gethostnamadr.c    8.1 (Berkeley) 6/4/93";\r
-static char fromrcsid[] = "From: Id: gethnamaddr.c,v 8.23 1998/04/07 04:59:46 vixie Exp $";\r
-static char rcsid[] = "$Id: gethostbydns.c,v 1.1.1.1 2003/11/19 01:51:27 kyu3 Exp $";\r
-#endif /* LIBC_SCCS and not lint */\r
-\r
-#include <sys/types.h>\r
-#include <sys/param.h>\r
-#include <sys/socket.h>\r
-#include <netinet/in.h>\r
-#include <arpa/inet.h>\r
-#include <arpa/nameser.h>\r
-\r
-#include <stdio.h>\r
-#include <unistd.h>\r
-#include <string.h>\r
-#include <netdb.h>\r
-#include <resolv.h>\r
-#include <ctype.h>\r
-#include <errno.h>\r
-#ifdef _ORG_FREEBSD_\r
-#include <syslog.h>\r
-#else\r
-#include <stdlib.h>\r
-u_int32_t _getlong(const u_char *src);\r
-u_int16_t _getshort(const u_char *src);\r
-#endif\r
-\r
-#include "res_config.h"\r
-#include "Socklib_internals.h"\r
-\r
-#define SPRINTF(x) ((size_t)sprintf x)\r
-\r
-#define        MAXALIASES      35\r
-#define        MAXADDRS        35\r
-\r
-#ifdef _ORG_FREEBSD_\r
-static const char AskedForGot[] =\r
-               "gethostby*.gethostanswer: asked for \"%s\", got \"%s\"";\r
-#endif\r
-\r
-static char *h_addr_ptrs[MAXADDRS + 1];\r
-\r
-static struct hostent host;\r
-static char *host_aliases[MAXALIASES];\r
-static char hostbuf[8*1024];\r
-static u_char host_addr[16];   /* IPv4 or IPv6 */\r
-\r
-#ifdef RESOLVSORT\r
-static void addrsort(char **, int);\r
-#endif\r
-\r
-#if PACKETSZ > 1024\r
-#define        MAXPACKET       PACKETSZ\r
-#else\r
-#define        MAXPACKET       1024\r
-#endif\r
-\r
-typedef union {\r
-    HEADER hdr;\r
-    u_char buf[MAXPACKET];\r
-} querybuf;\r
-\r
-typedef union {\r
-    int32_t al;\r
-    char ac;\r
-} align;\r
-\r
-extern int h_errno;\r
-int _dns_ttl_;\r
-\r
-#ifdef DEBUG_RES\r
-static void\r
-dprintf(char *msg, int num)\r
-{\r
-       if (_res.options & RES_DEBUG) {\r
-               int save = errno;\r
-\r
-               printf(msg, num);\r
-               errno = save;\r
-       }\r
-}\r
-#else\r
-# define dprintf(msg, num) /*nada*/\r
-#endif\r
-\r
-#define BOUNDED_INCR(x) \\r
-       do { \\r
-               cp += x; \\r
-               if (cp > eom) { \\r
-                       h_errno = NO_RECOVERY; \\r
-                       return (NULL); \\r
-               } \\r
-       } while (0)\r
-\r
-#define BOUNDS_CHECK(ptr, count) \\r
-       do { \\r
-               if ((ptr) + (count) > eom) { \\r
-                       h_errno = NO_RECOVERY; \\r
-                       return (NULL); \\r
-               } \\r
-       } while (0)\r
-\r
-static struct hostent *\r
-gethostanswer(const querybuf *answer, int anslen, const char *qname, int qtype)\r
-{\r
-       register const HEADER *hp;\r
-       register const u_char *cp;\r
-       register int n;\r
-       const u_char *eom, *erdata;\r
-       char *bp, **ap, **hap;\r
-       int type, class, buflen, ancount, qdcount;\r
-       int haveanswer, had_error;\r
-       int toobig = 0;\r
-       char tbuf[MAXDNAME];\r
-       const char *tname;\r
-       int (*name_ok)(const char *);\r
-\r
-       tname = qname;\r
-       host.h_name = NULL;\r
-       eom = answer->buf + anslen;\r
-       switch (qtype) {\r
-       case T_A:\r
-       case T_AAAA:\r
-               name_ok = res_hnok;\r
-               break;\r
-       case T_PTR:\r
-               name_ok = res_dnok;\r
-               break;\r
-       default:\r
-               h_errno = NO_RECOVERY;\r
-               return (NULL);  /* XXX should be abort(); */\r
-       }\r
-       /*\r
-        * find first satisfactory answer\r
-        */\r
-       hp = &answer->hdr;\r
-       ancount = ntohs(hp->ancount);\r
-       qdcount = ntohs(hp->qdcount);\r
-       bp = hostbuf;\r
-       buflen = sizeof hostbuf;\r
-       cp = answer->buf;\r
-       BOUNDED_INCR(HFIXEDSZ);\r
-       if (qdcount != 1) {\r
-               h_errno = NO_RECOVERY;\r
-               return (NULL);\r
-       }\r
-       n = dn_expand(answer->buf, eom, cp, bp, buflen);\r
-       if ((n < 0) || !(*name_ok)(bp)) {\r
-               h_errno = NO_RECOVERY;\r
-               return (NULL);\r
-       }\r
-       BOUNDED_INCR(n + QFIXEDSZ);\r
-       if (qtype == T_A || qtype == T_AAAA) {\r
-               /* res_send() has already verified that the query name is the\r
-                * same as the one we sent; this just gets the expanded name\r
-                * (i.e., with the succeeding search-domain tacked on).\r
-                */\r
-               n = (int)strlen(bp) + 1;                /* for the \0 */\r
-               if (n >= MAXHOSTNAMELEN) {\r
-                       h_errno = NO_RECOVERY;\r
-                       return (NULL);\r
-               }\r
-               host.h_name = bp;\r
-               bp += n;\r
-               buflen -= n;\r
-               /* The qname can be abbreviated, but h_name is now absolute. */\r
-               qname = host.h_name;\r
-       }\r
-       ap = host_aliases;\r
-       *ap = NULL;\r
-       host.h_aliases = host_aliases;\r
-       hap = h_addr_ptrs;\r
-       *hap = NULL;\r
-       host.h_addr_list = h_addr_ptrs;\r
-       haveanswer = 0;\r
-       had_error = 0;\r
-       _dns_ttl_ = -1;\r
-       while (ancount-- > 0 && cp < eom && !had_error) {\r
-               n = dn_expand(answer->buf, eom, cp, bp, buflen);\r
-               if ((n < 0) || !(*name_ok)(bp)) {\r
-                       had_error++;\r
-                       continue;\r
-               }\r
-               cp += n;                        /* name */\r
-               BOUNDS_CHECK(cp, 3 * INT16SZ + INT32SZ);\r
-               type = _getshort(cp);\r
-               cp += INT16SZ;                  /* type */\r
-               class = _getshort(cp);\r
-               cp += INT16SZ;                  /* class */\r
-               if (qtype == T_A  && type == T_A)\r
-                       _dns_ttl_ = _getlong(cp);\r
-               cp += INT32SZ;                  /* TTL */\r
-               n = _getshort(cp);\r
-               cp += INT16SZ;                  /* len */\r
-               BOUNDS_CHECK(cp, n);\r
-               erdata = cp + n;\r
-               if (class != C_IN) {\r
-                       /* XXX - debug? syslog? */\r
-                       cp += n;\r
-                       continue;               /* XXX - had_error++ ? */\r
-               }\r
-               if ((qtype == T_A || qtype == T_AAAA) && type == T_CNAME) {\r
-                       if (ap >= &host_aliases[MAXALIASES-1])\r
-                               continue;\r
-                       n = dn_expand(answer->buf, eom, cp, tbuf, sizeof tbuf);\r
-                       if ((n < 0) || !(*name_ok)(tbuf)) {\r
-                               had_error++;\r
-                               continue;\r
-                       }\r
-                       cp += n;\r
-                       if (cp != erdata) {\r
-                               h_errno = NO_RECOVERY;\r
-                               return (NULL);\r
-                       }\r
-                       /* Store alias. */\r
-                       *ap++ = bp;\r
-                       n = (int)strlen(bp) + 1;        /* for the \0 */\r
-                       if (n >= MAXHOSTNAMELEN) {\r
-                               had_error++;\r
-                               continue;\r
-                       }\r
-                       bp += n;\r
-                       buflen -= n;\r
-                       /* Get canonical name. */\r
-                       n = (int)strlen(tbuf) + 1;      /* for the \0 */\r
-                       if (n > buflen || n >= MAXHOSTNAMELEN) {\r
-                               had_error++;\r
-                               continue;\r
-                       }\r
-                       strcpy(bp, tbuf);\r
-                       host.h_name = bp;\r
-                       bp += n;\r
-                       buflen -= n;\r
-                       continue;\r
-               }\r
-               if (qtype == T_PTR && type == T_CNAME) {\r
-                       n = dn_expand(answer->buf, eom, cp, tbuf, sizeof tbuf);\r
-                       if (n < 0 || !res_dnok(tbuf)) {\r
-                               had_error++;\r
-                               continue;\r
-                       }\r
-                       cp += n;\r
-                       if (cp != erdata) {\r
-                               h_errno = NO_RECOVERY;\r
-                               return (NULL);\r
-                       }\r
-                       /* Get canonical name. */\r
-                       n = (int)strlen(tbuf) + 1;      /* for the \0 */\r
-                       if (n > buflen || n >= MAXHOSTNAMELEN) {\r
-                               had_error++;\r
-                               continue;\r
-                       }\r
-                       strcpy(bp, tbuf);\r
-                       tname = bp;\r
-                       bp += n;\r
-                       buflen -= n;\r
-                       continue;\r
-               }\r
-               if (type != qtype) {\r
-#ifdef _ORG_FREEBSD_\r
-                       syslog(LOG_NOTICE|LOG_AUTH,\r
-       "gethostby*.gethostanswer: asked for \"%s %s %s\", got type \"%s\"",\r
-                              qname, p_class(C_IN), p_type(qtype),\r
-                              p_type(type));\r
-#endif\r
-                       cp += n;\r
-                       continue;               /* XXX - had_error++ ? */\r
-               }\r
-               switch (type) {\r
-               case T_PTR:\r
-                       if (strcasecmp(tname, bp) != 0) {\r
-#ifdef _ORG_FREEBSD_\r
-                               syslog(LOG_NOTICE|LOG_AUTH,\r
-                                      AskedForGot, qname, bp);\r
-#endif\r
-                               cp += n;\r
-                               continue;       /* XXX - had_error++ ? */\r
-                       }\r
-                       n = dn_expand(answer->buf, eom, cp, bp, buflen);\r
-                       if ((n < 0) || !res_hnok(bp)) {\r
-                               had_error++;\r
-                               break;\r
-                       }\r
-#if MULTI_PTRS_ARE_ALIASES\r
-                       cp += n;\r
-                       if (cp != erdata) {\r
-                               h_errno = NO_RECOVERY;\r
-                               return (NULL);\r
-                       }\r
-                       if (!haveanswer)\r
-                               host.h_name = bp;\r
-                       else if (ap < &host_aliases[MAXALIASES-1])\r
-                               *ap++ = bp;\r
-                       else\r
-                               n = -1;\r
-                       if (n != -1) {\r
-                               n = (int)strlen(bp) + 1;        /* for the \0 */\r
-                               if (n >= MAXHOSTNAMELEN) {\r
-                                       had_error++;\r
-                                       break;\r
-                               }\r
-                               bp += n;\r
-                               buflen -= n;\r
-                       }\r
-                       break;\r
-#else\r
-                       host.h_name = bp;\r
-                       if (_res.options & RES_USE_INET6) {\r
-                               n = strlen(bp) + 1;     /* for the \0 */\r
-                               if (n >= MAXHOSTNAMELEN) {\r
-                                       had_error++;\r
-                                       break;\r
-                               }\r
-                               bp += n;\r
-                               buflen -= n;\r
-                               _map_v4v6_hostent(&host, &bp, &buflen);\r
-                       }\r
-                       h_errno = NETDB_SUCCESS;\r
-                       return (&host);\r
-#endif\r
-               case T_A:\r
-               case T_AAAA:\r
-                       if (strcasecmp(host.h_name, bp) != 0) {\r
-#ifdef _ORG_FREEBSD_\r
-                               syslog(LOG_NOTICE|LOG_AUTH,\r
-                                      AskedForGot, host.h_name, bp);\r
-#endif\r
-                               cp += n;\r
-                               continue;       /* XXX - had_error++ ? */\r
-                       }\r
-                       if (n != host.h_length) {\r
-                               cp += n;\r
-                               continue;\r
-                       }\r
-                       if (!haveanswer) {\r
-                               register int nn;\r
-\r
-                               host.h_name = bp;\r
-                               nn = (int)strlen(bp) + 1;       /* for the \0 */\r
-                               bp += nn;\r
-                               buflen -= nn;\r
-                       }\r
-\r
-                       bp += sizeof(align) - ((size_t)bp % sizeof(align));\r
-\r
-                       if (bp + n >= &hostbuf[sizeof hostbuf]) {\r
-                               dprintf("size (%d) too big\n", n);\r
-                               had_error++;\r
-                               continue;\r
-                       }\r
-                       if (hap >= &h_addr_ptrs[MAXADDRS-1]) {\r
-                               if (!toobig++)\r
-                                       dprintf("Too many addresses (%d)\n",\r
-                                               MAXADDRS);\r
-                               cp += n;\r
-                               continue;\r
-                       }\r
-      *hap++ = bp;\r
-                       bcopy(cp, bp, n);\r
-                       bp += n;\r
-                       buflen -= n;\r
-                       cp += n;\r
-                       if (cp != erdata) {\r
-                               h_errno = NO_RECOVERY;\r
-                               return (NULL);\r
-                       }\r
-                       break;\r
-               default:\r
-                       dprintf("Impossible condition (type=%d)\n", type);\r
-                       h_errno = NO_RECOVERY;\r
-                       return (NULL);\r
-                       /* BIND has abort() here, too risky on bad data */\r
-               }\r
-               if (!had_error)\r
-                       haveanswer++;\r
-       }\r
-       if (haveanswer) {\r
-               *ap = NULL;\r
-               *hap = NULL;\r
-# if defined(RESOLVSORT)\r
-               /*\r
-                * Note: we sort even if host can take only one address\r
-                * in its return structures - should give it the "best"\r
-                * address in that case, not some random one\r
-                */\r
-               if (_res.nsort && haveanswer > 1 && qtype == T_A)\r
-                       addrsort(h_addr_ptrs, haveanswer);\r
-# endif /*RESOLVSORT*/\r
-               if (!host.h_name) {\r
-                       n = (int)strlen(qname) + 1;     /* for the \0 */\r
-                       if (n > buflen || n >= MAXHOSTNAMELEN)\r
-                               goto no_recovery;\r
-                       strcpy(bp, qname);\r
-                       host.h_name = bp;\r
-                       bp += n;\r
-                       buflen -= n;\r
-               }\r
-               if (_res.options & RES_USE_INET6)\r
-                       _map_v4v6_hostent(&host, &bp, &buflen);\r
-               h_errno = NETDB_SUCCESS;\r
-               return (&host);\r
-       }\r
- no_recovery:\r
-       h_errno = NO_RECOVERY;\r
-       return (NULL);\r
-}\r
-\r
-struct hostent *\r
-__dns_getanswer(const char *answer, int anslen, const char *qname, int qtype)\r
-{\r
-       switch(qtype) {\r
-       case T_AAAA:\r
-               host.h_addrtype = AF_INET6;\r
-               host.h_length = IN6ADDRSZ;\r
-               break;\r
-       case T_A:\r
-       default:\r
-               host.h_addrtype = AF_INET;\r
-               host.h_length = INADDRSZ;\r
-               break;\r
-       }\r
-\r
-       return(gethostanswer((const querybuf *)answer, anslen, qname, qtype));\r
-}\r
-\r
-struct hostent *\r
-_gethostbydnsname(const char *name, int af)\r
-{\r
-       querybuf buf;\r
-       register const char *cp;\r
-       char *bp;\r
-       int n, size, type, len;\r
-\r
-       if ((_res.options & RES_INIT) == 0 && res_init() == -1) {\r
-               h_errno = NETDB_INTERNAL;\r
-               return (NULL);\r
-       }\r
-\r
-       switch (af) {\r
-       case AF_INET:\r
-               size = INADDRSZ;\r
-               type = T_A;\r
-               break;\r
-       case AF_INET6:\r
-               size = IN6ADDRSZ;\r
-               type = T_AAAA;\r
-               break;\r
-       default:\r
-               h_errno = NETDB_INTERNAL;\r
-               errno = EAFNOSUPPORT;\r
-               return (NULL);\r
-       }\r
-\r
-       host.h_addrtype = af;\r
-       host.h_length = size;\r
-\r
-       /*\r
-        * if there aren't any dots, it could be a user-level alias.\r
-        * this is also done in res_query() since we are not the only\r
-        * function that looks up host names.\r
-        */\r
-       if (!strchr(name, '.') && ( NULL != (cp = __hostalias(name))))\r
-               name = cp;\r
-\r
-       /*\r
-        * disallow names consisting only of digits/dots, unless\r
-        * they end in a dot.\r
-        */\r
-       if (isdigit(name[0]))\r
-               for (cp = name;; ++cp) {\r
-                       if (!*cp) {\r
-                               if (*--cp == '.')\r
-                                       break;\r
-                               /*\r
-                                * All-numeric, no dot at the end.\r
-                                * Fake up a hostent as if we'd actually\r
-                                * done a lookup.\r
-                                */\r
-                               if (inet_pton(af, name, host_addr) <= 0) {\r
-                                       h_errno = HOST_NOT_FOUND;\r
-                                       return (NULL);\r
-                               }\r
-                               strncpy(hostbuf, name, MAXDNAME);\r
-                               hostbuf[MAXDNAME] = '\0';\r
-                               bp = hostbuf + MAXDNAME;\r
-                               len = sizeof hostbuf - MAXDNAME;\r
-                               host.h_name = hostbuf;\r
-                               host.h_aliases = host_aliases;\r
-                               host_aliases[0] = NULL;\r
-                               h_addr_ptrs[0] = (char *)host_addr;\r
-                               h_addr_ptrs[1] = NULL;\r
-                               host.h_addr_list = h_addr_ptrs;\r
-                               if (_res.options & RES_USE_INET6)\r
-                                       _map_v4v6_hostent(&host, &bp, &len);\r
-                               h_errno = NETDB_SUCCESS;\r
-                               return (&host);\r
-                       }\r
-                       if (!isdigit(*cp) && *cp != '.') \r
-                               break;\r
-               }\r
-       if ((isxdigit(name[0]) && strchr(name, ':') != NULL) ||\r
-           name[0] == ':')\r
-               for (cp = name;; ++cp) {\r
-                       if (!*cp) {\r
-                               if (*--cp == '.')\r
-                                       break;\r
-                               /*\r
-                                * All-IPv6-legal, no dot at the end.\r
-                                * Fake up a hostent as if we'd actually\r
-                                * done a lookup.\r
-                                */\r
-                               if (inet_pton(af, name, host_addr) <= 0) {\r
-                                       h_errno = HOST_NOT_FOUND;\r
-                                       return (NULL);\r
-                               }\r
-                               strncpy(hostbuf, name, MAXDNAME);\r
-                               hostbuf[MAXDNAME] = '\0';\r
-                               bp = hostbuf + MAXDNAME;\r
-                               len = sizeof hostbuf - MAXDNAME;\r
-                               host.h_name = hostbuf;\r
-                               host.h_aliases = host_aliases;\r
-                               host_aliases[0] = NULL;\r
-                               h_addr_ptrs[0] = (char *)host_addr;\r
-                               h_addr_ptrs[1] = NULL;\r
-                               host.h_addr_list = h_addr_ptrs;\r
-                               h_errno = NETDB_SUCCESS;\r
-                               return (&host);\r
-                       }\r
-                       if (!isxdigit(*cp) && *cp != ':' && *cp != '.') \r
-                               break;\r
-               }\r
-\r
-       if ((n = res_search(name, C_IN, type, buf.buf, sizeof(buf))) < 0) {\r
-               dprintf("res_search failed (%d)\n", n);\r
-               return (NULL);\r
-       }\r
-       return (gethostanswer(&buf, n, name, type));\r
-}\r
-\r
-struct hostent *\r
-_gethostbydnsaddr(const char *addr, int len, int af)\r
-{\r
-       const u_char *uaddr = (const u_char *)addr;\r
-       static const u_char mapped[] = { 0,0, 0,0, 0,0, 0,0, 0,0, 0xff,0xff };\r
-       static const u_char tunnelled[] = { 0,0, 0,0, 0,0, 0,0, 0,0, 0,0 };\r
-       int n, size;\r
-       querybuf buf;\r
-       register struct hostent *hp;\r
-       char qbuf[MAXDNAME+1], *qp;\r
-#ifdef SUNSECURITY\r
-       register struct hostent *rhp;\r
-       char **haddr;\r
-       u_long old_options;\r
-       char hname2[MAXDNAME+1];\r
-#endif /*SUNSECURITY*/\r
-       \r
-       if ((_res.options & RES_INIT) == 0 && res_init() == -1) {\r
-               h_errno = NETDB_INTERNAL;\r
-               return (NULL);\r
-       }\r
-       if (af == AF_INET6 && len == IN6ADDRSZ &&\r
-           (!bcmp(uaddr, mapped, sizeof mapped) ||\r
-            !bcmp(uaddr, tunnelled, sizeof tunnelled))) {\r
-               /* Unmap. */\r
-               addr += sizeof mapped;\r
-               uaddr += sizeof mapped;\r
-               af = AF_INET;\r
-               len = INADDRSZ;\r
-       }\r
-       switch (af) {\r
-       case AF_INET:\r
-               size = INADDRSZ;\r
-               break;\r
-       case AF_INET6:\r
-               size = IN6ADDRSZ;\r
-               break;\r
-       default:\r
-               errno = EAFNOSUPPORT;\r
-               h_errno = NETDB_INTERNAL;\r
-               return (NULL);\r
-       }\r
-       if (size != len) {\r
-               errno = EINVAL;\r
-               h_errno = NETDB_INTERNAL;\r
-               return (NULL);\r
-       }\r
-       switch (af) {\r
-       case AF_INET:\r
-               (void) sprintf(qbuf, "%u.%u.%u.%u.in-addr.arpa",\r
-                              (uaddr[3] & 0xff),\r
-                              (uaddr[2] & 0xff),\r
-                              (uaddr[1] & 0xff),\r
-                              (uaddr[0] & 0xff));\r
-               break;\r
-       case AF_INET6:\r
-               qp = qbuf;\r
-               for (n = IN6ADDRSZ - 1; n >= 0; n--) {\r
-                       qp += SPRINTF((qp, "%x.%x.",\r
-                                      uaddr[n] & 0xf,\r
-                                      (uaddr[n] >> 4) & 0xf));\r
-               }\r
-               strcpy(qp, "ip6.int");\r
-               break;\r
-       default:\r
-               abort();\r
-       }\r
-       n = res_query(qbuf, C_IN, T_PTR, (u_char *)buf.buf, sizeof buf.buf);\r
-       if (n < 0) {\r
-               dprintf("res_query failed (%d)\n", n);\r
-               return (NULL);\r
-       }\r
-       if ( NULL == (hp = gethostanswer(&buf, n, qbuf, T_PTR)))\r
-               return (NULL);  /* h_errno was set by gethostanswer() */\r
-#ifdef SUNSECURITY\r
-       if (af == AF_INET) {\r
-           /*\r
-            * turn off search as the name should be absolute,\r
-            * 'localhost' should be matched by defnames\r
-            */\r
-           strncpy(hname2, hp->h_name, MAXDNAME);\r
-           hname2[MAXDNAME] = '\0';\r
-           old_options = _res.options;\r
-           _res.options &= ~RES_DNSRCH;\r
-           _res.options |= RES_DEFNAMES;\r
-           if (!(rhp = gethostbyname(hname2))) {\r
-#ifdef _ORG_FREEBSD_\r
-               syslog(LOG_NOTICE|LOG_AUTH,\r
-                      "gethostbyaddr: No A record for %s (verifying [%s])",\r
-                      hname2, inet_ntoa(*((struct in_addr *)addr)));\r
-#endif\r
-               _res.options = old_options;\r
-               h_errno = HOST_NOT_FOUND;\r
-               return (NULL);\r
-           }\r
-           _res.options = old_options;\r
-           for (haddr = rhp->h_addr_list; *haddr; haddr++)\r
-               if (!memcmp(*haddr, addr, INADDRSZ))\r
-                       break;\r
-           if (!*haddr) {\r
-#ifdef _ORG_FREEBSD_\r
-               syslog(LOG_NOTICE|LOG_AUTH,\r
-                      "gethostbyaddr: A record of %s != PTR record [%s]",\r
-                      hname2, inet_ntoa(*((struct in_addr *)addr)));\r
-#endif\r
-               h_errno = HOST_NOT_FOUND;\r
-               return (NULL);\r
-           }\r
-       }\r
-#endif /*SUNSECURITY*/\r
-       hp->h_addrtype = af;\r
-       hp->h_length = len;\r
-       bcopy(addr, host_addr, len);\r
-       h_addr_ptrs[0] = (char *)host_addr;\r
-       h_addr_ptrs[1] = NULL;\r
-       if (af == AF_INET && (_res.options & RES_USE_INET6)) {\r
-               _map_v4v6_address((char*)host_addr, (char*)host_addr);\r
-               hp->h_addrtype = AF_INET6;\r
-               hp->h_length = IN6ADDRSZ;\r
-       }\r
-       h_errno = NETDB_SUCCESS;\r
-       return (hp);\r
-}\r
-\r
-#ifdef RESOLVSORT\r
-static void\r
-addrsort(char **ap, int num)\r
-{\r
-       short i, j;\r
-       char **p;\r
-       short aval[MAXADDRS];\r
-       short needsort = 0;\r
-\r
-       p = ap;\r
-       for (i = 0; i < num; i++, p++) {\r
-           for (j = 0 ; (unsigned)j < _res.nsort; j++)\r
-               if (_res.sort_list[j].addr.s_addr == \r
-                   (((struct in_addr *)(*p))->s_addr & _res.sort_list[j].mask))\r
-                       break;\r
-           aval[i] = j;\r
-           if (needsort == 0 && i > 0 && j < aval[i-1])\r
-               needsort = i;\r
-       }\r
-       if (!needsort)\r
-           return;\r
-\r
-       while (needsort < num) {\r
-           for (j = needsort - 1; j >= 0; j--) {\r
-               if (aval[j] > aval[j+1]) {\r
-                   char *hp;\r
-\r
-                   i = aval[j];\r
-                   aval[j] = aval[j+1];\r
-                   aval[j+1] = i;\r
-\r
-                   hp = ap[j];\r
-                   ap[j] = ap[j+1];\r
-                   ap[j+1] = hp;\r
-\r
-               } else\r
-                   break;\r
-           }\r
-           needsort++;\r
-       }\r
-}\r
-#endif\r
-void\r
-_sethostdnsent(int stayopen)\r
-{\r
-       if ((_res.options & RES_INIT) == 0 && res_init() == -1)\r
-               return;\r
-       if (stayopen)\r
-               _res.options |= RES_STAYOPEN | RES_USEVC;\r
-}\r
-\r
-void\r
-_endhostdnsent()\r
-{\r
-       _res.options &= ~(RES_STAYOPEN | RES_USEVC);\r
-       res_close();\r
-}\r