]> git.proxmox.com Git - mirror_edk2.git/blobdiff - StdLib/BsdSocketLib/getnetbydns.c
edk2: Remove AppPkg, StdLib, StdLibPrivateInternalFiles
[mirror_edk2.git] / StdLib / BsdSocketLib / getnetbydns.c
diff --git a/StdLib/BsdSocketLib/getnetbydns.c b/StdLib/BsdSocketLib/getnetbydns.c
deleted file mode 100644 (file)
index b0fdef5..0000000
+++ /dev/null
@@ -1,318 +0,0 @@
-/*-\r
- * Copyright (c) 1985, 1988, 1993\r
- *     The Regents of the University of California.  All rights reserved.\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 the University of\r
- *    California, Berkeley, Intel Corporation, and its contributors.\r
- * \r
- * 4. Neither the name of University, Intel Corporation, or their respective\r
- *    contributors may be used to endorse or promote products derived from\r
- *    this software without specific prior written permission.\r
- * \r
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS, INTEL CORPORATION AND\r
- * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,\r
- * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS\r
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS,\r
- * INTEL CORPORATION OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,\r
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT\r
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\r
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\r
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF\r
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 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
-/* Portions Copyright (c) 1993 Carlos Leandro and Rui Salgueiro\r
- *     Dep. Matematica Universidade de Coimbra, Portugal, Europe\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.\r
- */\r
-\r
-#if defined(LIBC_SCCS) && !defined(lint)\r
-static char sccsid[] = "@(#)gethostnamadr.c    8.1 (Berkeley) 6/4/93";\r
-static char rcsid[] = "$Id: getnetbydns.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/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 <netdb.h>\r
-#include <resolv.h>\r
-#include <ctype.h>\r
-#include <errno.h>\r
-#include <string.h>\r
-#include <unistd.h>\r
-#ifdef _ORG_FREEBSD_\r
-#include <syslog.h>\r
-#endif\r
-\r
-#include "res_config.h"\r
-#include "Socklib_internals.h"\r
-\r
-extern int h_errno;\r
-\r
-#define BYADDR 0\r
-#define BYNAME 1\r
-#define        MAXALIASES      35\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
-       long    al;\r
-       char    ac;\r
-} align;\r
-\r
-static struct netent *\r
-getnetanswer(querybuf *answer, int anslen, int net_i)\r
-{\r
-\r
-       register HEADER *hp;\r
-       register u_char *cp;\r
-       register int n;\r
-       u_char *eom;\r
-       int type, class, buflen, ancount, qdcount, haveanswer, i, nchar;\r
-       char aux1[MAXHOSTNAMELEN], aux2[MAXHOSTNAMELEN], ans[MAXHOSTNAMELEN];\r
-       char *in, *st, *pauxt, *bp, **ap;\r
-       char *paux1 = &aux1[0], *paux2 = &aux2[0], flag = 0;\r
-static struct netent net_entry;\r
-static char *net_aliases[MAXALIASES], netbuf[PACKETSZ];\r
-\r
-       /*\r
-        * find first satisfactory answer\r
-        *\r
-        *      answer --> +------------+  ( MESSAGE )\r
-        *                 |   Header   |\r
-        *                 +------------+\r
-        *                 |  Question  | the question for the name server\r
-        *                 +------------+\r
-        *                 |   Answer   | RRs answering the question\r
-        *                 +------------+\r
-        *                 | Authority  | RRs pointing toward an authority\r
-        *                 | Additional | RRs holding additional information\r
-        *                 +------------+\r
-        */\r
-       eom = answer->buf + anslen;\r
-       hp = &answer->hdr;\r
-       ancount = ntohs(hp->ancount); /* #/records in the answer section */\r
-       qdcount = ntohs(hp->qdcount); /* #/entries in the question section */\r
-       bp = netbuf;\r
-       buflen = sizeof(netbuf);\r
-       cp = answer->buf + HFIXEDSZ;\r
-       if (!qdcount) {\r
-               if (hp->aa)\r
-                       h_errno = HOST_NOT_FOUND;\r
-               else\r
-                       h_errno = TRY_AGAIN;\r
-               return (NULL);\r
-       }\r
-       while (qdcount-- > 0)\r
-               cp += __dn_skipname(cp, eom) + QFIXEDSZ;\r
-       ap = net_aliases;\r
-       *ap = NULL;\r
-       net_entry.n_aliases = net_aliases;\r
-       haveanswer = 0;\r
-       while (--ancount >= 0 && cp < eom) {\r
-               n = dn_expand(answer->buf, eom, cp, bp, buflen);\r
-               if ((n < 0) || !res_dnok(bp))\r
-                       break;\r
-               cp += n;\r
-               ans[0] = '\0';\r
-               (void)strncpy(&ans[0], bp, sizeof(ans) - 1);\r
-               ans[sizeof(ans) - 1] = '\0';\r
-               GETSHORT(type, cp);\r
-               GETSHORT(class, cp);\r
-               cp += INT32SZ;          /* TTL */\r
-               GETSHORT(n, cp);\r
-               if (class == C_IN && type == T_PTR) {\r
-                       n = dn_expand(answer->buf, eom, cp, bp, buflen);\r
-                       if ((n < 0) || !res_hnok(bp)) {\r
-                               cp += n;\r
-                               return (NULL);\r
-                       }\r
-                       cp += n; \r
-                       *ap++ = bp;\r
-                       bp += strlen(bp) + 1;\r
-                       net_entry.n_addrtype =\r
-                               (class == C_IN) ? AF_INET : AF_UNSPEC;\r
-                       haveanswer++;\r
-               }\r
-       }\r
-       if (haveanswer) {\r
-               *ap = NULL;\r
-               switch (net_i) {\r
-               case BYADDR:\r
-                       net_entry.n_name = *net_entry.n_aliases;\r
-                       net_entry.n_net = 0L;\r
-                       break;\r
-               case BYNAME:\r
-                       in = *net_entry.n_aliases;\r
-                       net_entry.n_name = &ans[0];\r
-                       aux2[0] = '\0';\r
-                       for (i = 0; i < 4; i++) {\r
-                               for (st = in, nchar = 0;\r
-                                    *st != '.';\r
-                                    st++, nchar++)\r
-                                       ;\r
-                               if (nchar != 1 || *in != '0' || flag) {\r
-                                       flag = 1;\r
-                                       (void)strncpy(paux1,\r
-                                                     (i==0) ? in : in-1,\r
-                                                     (i==0) ?nchar : nchar+1);\r
-                                       paux1[(i==0) ? nchar : nchar+1] = '\0';\r
-                                       pauxt = paux2;\r
-                                       paux2 = strcat(paux1, paux2);\r
-                                       paux1 = pauxt;\r
-                               }\r
-                               in = ++st;\r
-                       }                 \r
-                       net_entry.n_net = inet_network(paux2);\r
-                       break;\r
-               }\r
-               net_entry.n_aliases++;\r
-               return (&net_entry);\r
-       }\r
-       h_errno = TRY_AGAIN;\r
-       return (NULL);\r
-}\r
-\r
-struct netent *\r
-_getnetbydnsaddr(register unsigned long net, register int net_type)\r
-{\r
-       unsigned int netbr[4];\r
-       int nn, anslen;\r
-       querybuf buf;\r
-       char qbuf[MAXDNAME];\r
-       unsigned long net2;\r
-       struct netent *net_entry;\r
-\r
-       if (net_type != AF_INET)\r
-               return (NULL);\r
-\r
-       for (nn = 4, net2 = net; net2; net2 >>= 8)\r
-               netbr[--nn] = net2 & 0xff;\r
-       switch (nn) {\r
-       case 3:         /* Class A */\r
-               sprintf(qbuf, "0.0.0.%u.in-addr.arpa", netbr[3]);\r
-               break;\r
-       case 2:         /* Class B */\r
-               sprintf(qbuf, "0.0.%u.%u.in-addr.arpa", netbr[3], netbr[2]);\r
-               break;\r
-       case 1:         /* Class C */\r
-               sprintf(qbuf, "0.%u.%u.%u.in-addr.arpa", netbr[3], netbr[2],\r
-                   netbr[1]);\r
-               break;\r
-       case 0:         /* Class D - E */\r
-               sprintf(qbuf, "%u.%u.%u.%u.in-addr.arpa", netbr[3], netbr[2],\r
-                   netbr[1], netbr[0]);\r
-               break;\r
-       }\r
-       anslen = res_query(qbuf, C_IN, T_PTR, (u_char *)&buf, sizeof(buf));\r
-       if (anslen < 0) {\r
-#ifdef DEBUG\r
-               if (_res.options & RES_DEBUG)\r
-                       printf("res_query failed\n");\r
-#endif\r
-               return (NULL);\r
-       }\r
-       net_entry = getnetanswer(&buf, anslen, BYADDR);\r
-       if (net_entry) {\r
-               unsigned u_net = net;   /* maybe net should be unsigned ? */\r
-\r
-               /* Strip trailing zeros */\r
-               while ((u_net & 0xff) == 0 && u_net != 0)\r
-                       u_net >>= 8;\r
-               net_entry->n_net = u_net;\r
-               return (net_entry);\r
-       }\r
-       return (NULL);\r
-}\r
-\r
-struct netent *\r
-_getnetbydnsname(register const char *net)\r
-{\r
-       int anslen;\r
-       querybuf buf;\r
-       char qbuf[MAXDNAME];\r
-\r
-       if ((_res.options & RES_INIT) == 0 && res_init() == -1) {\r
-               h_errno = NETDB_INTERNAL;\r
-               return (NULL);\r
-       }\r
-       strncpy(qbuf, net, sizeof(qbuf) - 1);\r
-       qbuf[sizeof(qbuf) - 1] = '\0';\r
-       anslen = res_search(qbuf, C_IN, T_PTR, (u_char *)&buf, sizeof(buf));\r
-       if (anslen < 0) {\r
-#ifdef DEBUG\r
-               if (_res.options & RES_DEBUG)\r
-                       printf("res_query failed\n");\r
-#endif\r
-               return (NULL);\r
-       }\r
-       return getnetanswer(&buf, anslen, BYNAME);\r
-}\r
-\r
-void\r
-_setnetdnsent(int stayopen)\r
-{\r
-       if (stayopen)\r
-               _res.options |= RES_STAYOPEN | RES_USEVC;\r
-}\r
-\r
-void\r
-_endnetdnsent()\r
-{\r
-       _res.options &= ~(RES_STAYOPEN | RES_USEVC);\r
-       res_close();\r
-}\r