summaryrefslogtreecommitdiffstats
path: root/lib/libc
diff options
context:
space:
mode:
authorpeter <peter@FreeBSD.org>1996-01-13 09:03:58 +0000
committerpeter <peter@FreeBSD.org>1996-01-13 09:03:58 +0000
commit05184daaef969978db8f5aa4df2c3c5edac44c51 (patch)
tree1aa115c29231422c8a28d2fe8a54407622c4698e /lib/libc
parent6ba0bb5bfcd0dcb90300a37b199f1bef4c8e2490 (diff)
downloadFreeBSD-src-05184daaef969978db8f5aa4df2c3c5edac44c51.zip
FreeBSD-src-05184daaef969978db8f5aa4df2c3c5edac44c51.tar.gz
The last of the bind-4.9.3-REL resolver merges.
Diffstat (limited to 'lib/libc')
-rw-r--r--lib/libc/net/gethostbydns.c154
-rw-r--r--lib/libc/net/gethostbyht.c51
-rw-r--r--lib/libc/net/getnetbyaddr.c56
-rw-r--r--lib/libc/net/getnetbydns.c163
-rw-r--r--lib/libc/net/getnetbyht.c20
-rw-r--r--lib/libc/net/herror.c4
-rw-r--r--lib/libc/net/inet_addr.c78
-rw-r--r--lib/libc/net/res_config.h3
8 files changed, 280 insertions, 249 deletions
diff --git a/lib/libc/net/gethostbydns.c b/lib/libc/net/gethostbydns.c
index 7b1e2d6..46213f8 100644
--- a/lib/libc/net/gethostbydns.c
+++ b/lib/libc/net/gethostbydns.c
@@ -53,7 +53,7 @@
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid[] = "@(#)gethostnamadr.c 8.1 (Berkeley) 6/4/93";
-static char rcsid[] = "$Id: gethostbydns.c,v 1.6 1995/08/21 09:15:32 bde Exp $";
+static char rcsid[] = "$Id: gethostbydns.c,v 1.7 1995/10/22 14:39:02 phk Exp $";
#endif /* LIBC_SCCS and not lint */
#include <sys/param.h>
@@ -76,10 +76,8 @@ static char rcsid[] = "$Id: gethostbydns.c,v 1.6 1995/08/21 09:15:32 bde Exp $";
#define MAXALIASES 35
#define MAXADDRS 35
-#define MULTI_PTRS_ARE_ALIASES 1 /* XXX - experimental */
-
static const char AskedForGot[] =
- "gethostby*.gethostanswer: asked for \"%s\", got \"%s\"";
+ "gethostby*.gethostanswer: asked for \"%s\", got \"%s\"";
static char *h_addr_ptrs[MAXADDRS + 1];
@@ -90,6 +88,10 @@ static struct in_addr host_addr;
static FILE *hostf = NULL;
static int stayopen = 0;
+#ifdef RESOLVSORT
+static void addrsort __P((char **, int));
+#endif
+
#if PACKETSZ > 1024
#define MAXPACKET PACKETSZ
#else
@@ -126,51 +128,6 @@ dprintf(msg, num)
#endif
-#ifdef RESOLVSORT
-static void
-addrsort(ap, num)
- char **ap;
- int num;
-{
- int i, j;
- char **p;
- short aval[MAXADDRS];
- int needsort = 0;
-
- p = ap;
- for (i = 0; i < num; i++, p++) {
- for (j = 0 ; (unsigned)j < _res.nsort; j++)
- if (_res.sort_list[j].addr.s_addr ==
- (((struct in_addr *)(*p))->s_addr & _res.sort_list[j].mask))
- break;
- aval[i] = j;
- if (needsort == 0 && i > 0 && j < aval[i-1])
- needsort = i;
- }
- if (!needsort)
- return;
-
- while (needsort < num) {
- for (j = needsort - 1; j >= 0; j--) {
- if (aval[j] > aval[j+1]) {
- char *hp;
-
- i = aval[j];
- aval[j] = aval[j+1];
- aval[j+1] = i;
-
- hp = ap[j];
- ap[j] = ap[j+1];
- ap[j+1] = hp;
-
- } else
- break;
- }
- needsort++;
- }
-}
-#endif
-
static struct hostent *
gethostanswer(answer, anslen, qname, qclass, qtype)
const querybuf *answer;
@@ -187,7 +144,9 @@ gethostanswer(answer, anslen, qname, qclass, qtype)
int haveanswer, had_error;
int toobig = 0;
char tbuf[MAXDNAME+1];
+ const char *tname;
+ tname = qname;
host.h_name = NULL;
eom = answer->buf + anslen;
/*
@@ -225,7 +184,9 @@ gethostanswer(answer, anslen, qname, qclass, qtype)
host.h_aliases = host_aliases;
hap = h_addr_ptrs;
*hap = NULL;
+#if BSD >= 43 || defined(h_addr) /* new-style hostent structure */
host.h_addr_list = h_addr_ptrs;
+#endif
haveanswer = 0;
had_error = 0;
while (ancount-- > 0 && cp < eom && !had_error) {
@@ -257,7 +218,7 @@ gethostanswer(answer, anslen, qname, qclass, qtype)
cp += n;
if (host.h_name && strcasecmp(host.h_name, bp) != 0) {
syslog(LOG_NOTICE|LOG_AUTH,
- "gethostby*.gethostanswer: asked for \"%s\", got CNAME for \"%s\"",
+ "gethostby*.gethostanswer: asked for \"%s\", got CNAME for \"%s\"",
host.h_name, bp);
continue; /* XXX - had_error++ ? */
}
@@ -278,19 +239,36 @@ gethostanswer(answer, anslen, qname, qclass, qtype)
buflen -= n;
continue;
}
+ if (qtype == T_PTR && type == T_CNAME) {
+ n = dn_expand(answer->buf, eom, cp, tbuf, sizeof tbuf);
+ if (n < 0) {
+ had_error++;
+ continue;
+ }
+ cp += n;
+ /* Get canonical name. */
+ n = strlen(tbuf) + 1; /* for the \0 */
+ if (n > buflen) {
+ had_error++;
+ continue;
+ }
+ strcpy(bp, tbuf);
+ tname = bp;
+ bp += n;
+ buflen -= n;
+ continue;
+ }
if (type != qtype) {
- /* CNAME->PTR should not cause a log message. */
- if (!(qtype == T_PTR && type == T_CNAME))
syslog(LOG_NOTICE|LOG_AUTH,
- "gethostby*.gethostanswer: asked for \"%s %s %s\", got type \"%s\"",
- qname, p_class(qclass), p_type(qtype),
- p_type(type));
+ "gethostby*.gethostanswer: asked for \"%s %s %s\", got type \"%s\"",
+ qname, p_class(qclass), p_type(qtype),
+ p_type(type));
cp += n;
continue; /* XXX - had_error++ ? */
}
switch (type) {
case T_PTR:
- if (strcasecmp(qname, bp) != 0) {
+ if (strcasecmp(tname, bp) != 0) {
syslog(LOG_NOTICE|LOG_AUTH,
AskedForGot, qname, bp);
cp += n;
@@ -301,7 +279,7 @@ gethostanswer(answer, anslen, qname, qclass, qtype)
had_error++;
break;
}
-#if MULTI_PTRS_ARE_ALIASES
+#ifdef MULTI_PTRS_ARE_ALIASES
cp += n;
if (!haveanswer)
host.h_name = bp;
@@ -355,7 +333,7 @@ gethostanswer(answer, anslen, qname, qclass, qtype)
if (hap >= &h_addr_ptrs[MAXADDRS-1]) {
if (!toobig++)
dprintf("Too many addresses (%d)\n",
- MAXADDRS);
+ MAXADDRS);
cp += n;
continue;
}
@@ -384,6 +362,11 @@ gethostanswer(answer, anslen, qname, qclass, qtype)
qclass == C_IN && qtype == T_A)
addrsort(h_addr_ptrs, haveanswer);
# endif /*RESOLVSORT*/
+#if BSD >= 43 || defined(h_addr) /* new-style hostent structure */
+ /* nothing */
+#else
+ host.h_addr = h_addr_ptrs[0];
+#endif /*BSD*/
if (!host.h_name) {
n = strlen(qname) + 1; /* for the \0 */
strcpy(bp, qname);
@@ -445,10 +428,15 @@ _gethostbydnsname(name)
host.h_length = INT32SZ;
h_addr_ptrs[0] = (char *)&host_addr;
h_addr_ptrs[1] = NULL;
+#if BSD >= 43 || defined(h_addr) /* new-style hostent structure */
host.h_addr_list = h_addr_ptrs;
+#else
+ host.h_addr = h_addr_ptrs[0];
+#endif
+ h_errno = NETDB_SUCCESS;
return (&host);
}
- if (!isdigit(*cp) && *cp != '.')
+ if (!isdigit(*cp) && *cp != '.')
break;
}
@@ -474,7 +462,7 @@ _gethostbydnsaddr(addr, len, type)
u_long old_options;
char hname2[MAXDNAME+1];
#endif /*SUNSECURITY*/
-
+
if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
h_errno = NETDB_INTERNAL;
return (NULL);
@@ -535,10 +523,56 @@ _gethostbydnsaddr(addr, len, type)
return (hp);
}
+#ifdef RESOLVSORT
+static void
+addrsort(ap, num)
+ char **ap;
+ int num;
+{
+ int i, j;
+ char **p;
+ short aval[MAXADDRS];
+ int needsort = 0;
+
+ p = ap;
+ for (i = 0; i < num; i++, p++) {
+ for (j = 0 ; (unsigned)j < _res.nsort; j++)
+ if (_res.sort_list[j].addr.s_addr ==
+ (((struct in_addr *)(*p))->s_addr & _res.sort_list[j].mask))
+ break;
+ aval[i] = j;
+ if (needsort == 0 && i > 0 && j < aval[i-1])
+ needsort = i;
+ }
+ if (!needsort)
+ return;
+
+ while (needsort < num) {
+ for (j = needsort - 1; j >= 0; j--) {
+ if (aval[j] > aval[j+1]) {
+ char *hp;
+
+ i = aval[j];
+ aval[j] = aval[j+1];
+ aval[j+1] = i;
+
+ hp = ap[j];
+ ap[j] = ap[j+1];
+ ap[j+1] = hp;
+
+ } else
+ break;
+ }
+ needsort++;
+ }
+}
+#endif
void
_sethostdnsent(stayopen)
int stayopen;
{
+ if ((_res.options & RES_INIT) == 0 && res_init() == -1)
+ return;
if (stayopen)
_res.options |= RES_STAYOPEN | RES_USEVC;
}
diff --git a/lib/libc/net/gethostbyht.c b/lib/libc/net/gethostbyht.c
index 4b616cd..9f1fa4c 100644
--- a/lib/libc/net/gethostbyht.c
+++ b/lib/libc/net/gethostbyht.c
@@ -53,7 +53,7 @@
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid[] = "@(#)gethostnamadr.c 8.1 (Berkeley) 6/4/93";
-static char rcsid[] = "$Id: gethostbyht.c,v 1.1 1994/09/25 02:12:11 pst Exp $";
+static char rcsid[] = "$Id: gethostbyht.c,v 1.2 1995/05/30 05:40:44 rgrimes Exp $";
#endif /* LIBC_SCCS and not lint */
#include <sys/param.h>
@@ -67,21 +67,20 @@ static char rcsid[] = "$Id: gethostbyht.c,v 1.1 1994/09/25 02:12:11 pst Exp $";
#include <string.h>
#define MAXALIASES 35
-#define MAXADDRS 35
static struct hostent host;
static char *host_aliases[MAXALIASES];
static char hostbuf[BUFSIZ+1];
static FILE *hostf = NULL;
-static char hostaddr[MAXADDRS];
-static char *host_addrs[2];
+static struct in_addr host_addr;
+static char *h_addr_ptrs[2];
static int stayopen = 0;
void
_sethosthtent(f)
int f;
{
- if (hostf == NULL)
+ if (!hostf)
hostf = fopen(_PATH_HOSTS, "r" );
else
rewind(hostf);
@@ -103,33 +102,40 @@ gethostent()
char *p;
register char *cp, **q;
- if (hostf == NULL && (hostf = fopen(_PATH_HOSTS, "r" )) == NULL)
+ if (!hostf && !(hostf = fopen(_PATH_HOSTS, "r" ))) {
+ h_errno = NETDB_INTERNAL;
return (NULL);
+ }
again:
- if ((p = fgets(hostbuf, BUFSIZ, hostf)) == NULL)
+ if (!(p = fgets(hostbuf, sizeof hostbuf, hostf))) {
+ h_errno = HOST_NOT_FOUND;
return (NULL);
+ }
if (*p == '#')
goto again;
- cp = strpbrk(p, "#\n");
- if (cp == NULL)
+ if (!(cp = strpbrk(p, "#\n")))
goto again;
*cp = '\0';
- cp = strpbrk(p, " \t");
- if (cp == NULL)
+ if (!(cp = strpbrk(p, " \t")))
goto again;
*cp++ = '\0';
/* THIS STUFF IS INTERNET SPECIFIC */
- host.h_addr_list = host_addrs;
- host.h_addr = hostaddr;
- *((u_int32_t *)host.h_addr) = inet_addr(p);
- host.h_length = sizeof (u_int32_t);
+ if (!inet_aton(p, &host_addr))
+ goto again;
+ h_addr_ptrs[0] = (char *)&host_addr;
+ h_addr_ptrs[1] = NULL;
+#if BSD >= 43 || defined(h_addr) /* new-style hostent structure */
+ host.h_addr_list = h_addr_ptrs;
+#else
+ host.h_addr = h_addr_ptrs[0];
+#endif
+ host.h_length = sizeof(u_int32_t);
host.h_addrtype = AF_INET;
while (*cp == ' ' || *cp == '\t')
cp++;
host.h_name = cp;
q = host.h_aliases = host_aliases;
- cp = strpbrk(cp, " \t");
- if (cp != NULL)
+ if (cp = strpbrk(cp, " \t"))
*cp++ = '\0';
while (cp && *cp) {
if (*cp == ' ' || *cp == '\t') {
@@ -138,11 +144,11 @@ again:
}
if (q < &host_aliases[MAXALIASES - 1])
*q++ = cp;
- cp = strpbrk(cp, " \t");
- if (cp != NULL)
+ if (cp = strpbrk(cp, " \t"))
*cp++ = '\0';
}
*q = NULL;
+ h_errno = NETDB_SUCCESS;
return (&host);
}
@@ -152,9 +158,9 @@ _gethostbyhtname(name)
{
register struct hostent *p;
register char **cp;
-
+
sethostent(0);
- while ((p = gethostent())) {
+ while (p = gethostent()) {
if (strcasecmp(p->h_name, name) == 0)
break;
for (cp = p->h_aliases; *cp != 0; cp++)
@@ -174,9 +180,10 @@ _gethostbyhtaddr(addr, len, type)
register struct hostent *p;
sethostent(0);
- while ((p = gethostent()))
+ while (p = gethostent())
if (p->h_addrtype == type && !bcmp(p->h_addr, addr, len))
break;
endhostent();
return (p);
}
+
diff --git a/lib/libc/net/getnetbyaddr.c b/lib/libc/net/getnetbyaddr.c
deleted file mode 100644
index fd3f260..0000000
--- a/lib/libc/net/getnetbyaddr.c
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Copyright (c) 1983, 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.
- */
-
-#if defined(LIBC_SCCS) && !defined(lint)
-static char sccsid[] = "@(#)getnetbyaddr.c 8.1 (Berkeley) 6/4/93";
-#endif /* LIBC_SCCS and not lint */
-
-#include <netdb.h>
-
-extern int _net_stayopen;
-
-struct netent *
-getnetbyaddr(net, type)
- register long net;
- register int type;
-{
- register struct netent *p;
-
- setnetent(_net_stayopen);
- while (p = getnetent())
- if (p->n_addrtype == type && p->n_net == net)
- break;
- if (!_net_stayopen)
- endnetent();
- return (p);
-}
diff --git a/lib/libc/net/getnetbydns.c b/lib/libc/net/getnetbydns.c
index 440ebf8..4464fed 100644
--- a/lib/libc/net/getnetbydns.c
+++ b/lib/libc/net/getnetbydns.c
@@ -50,10 +50,17 @@
* -
* --Copyright--
*/
+/* Portions Copyright (c) 1993 Carlos Leandro and Rui Salgueiro
+ * Dep. Matematica Universidade de Coimbra, Portugal, Europe
+ *
+ * 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.
+ */
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid[] = "@(#)gethostnamadr.c 8.1 (Berkeley) 6/4/93";
-static char rcsid[] = "$Id: getnetbydns.c,v 1.3 1995/05/30 05:40:46 rgrimes Exp $";
+static char rcsid[] = "$Id: getnetbydns.c,v 1.4 1995/10/22 14:39:04 phk Exp $";
#endif /* LIBC_SCCS and not lint */
#include <sys/param.h>
@@ -61,20 +68,23 @@ static char rcsid[] = "$Id: getnetbydns.c,v 1.3 1995/05/30 05:40:46 rgrimes Exp
#include <netinet/in.h>
#include <arpa/inet.h>
#include <arpa/nameser.h>
+
+#include <stdio.h>
#include <netdb.h>
#include <resolv.h>
-#include <stdio.h>
-#include <unistd.h>
#include <ctype.h>
#include <errno.h>
#include <string.h>
+#include <unistd.h>
#include <syslog.h>
-#define BYNAME 0
-#define BYADDR 1
+#include "res_config.h"
+
+extern int h_errno;
+#define BYADDR 0
+#define BYNAME 1
#define MAXALIASES 35
-#define MAXADDRS 35
#if PACKETSZ > 1024
#define MAXPACKET PACKETSZ
@@ -83,17 +93,15 @@ static char rcsid[] = "$Id: getnetbydns.c,v 1.3 1995/05/30 05:40:46 rgrimes Exp
#endif
typedef union {
- HEADER hdr;
- u_char buf[MAXPACKET];
+ HEADER hdr;
+ u_char buf[MAXPACKET];
} querybuf;
typedef union {
- int32_t al;
- char ac;
+ long al;
+ char ac;
} align;
-extern int h_errno;
-
static struct netent *
getnetanswer(answer, anslen, net_i)
querybuf *answer;
@@ -101,20 +109,15 @@ getnetanswer(answer, anslen, net_i)
int net_i;
{
- register HEADER *hp;
- register u_char *cp;
- register int n;
- u_char *eom;
- int type, class, buflen, ancount, qdcount,
- haveanswer, i, nchar;
- char aux1[30], aux2[30], ans[30],
- *in, *st, *pauxt, *bp, **ap,
- *paux1 = &aux1[0],
- *paux2 = &aux2[0],
- flag = 0;
-static struct netent net_entry;
-static char *net_aliases[MAXALIASES],
- netbuf[BUFSIZ+1];
+ register HEADER *hp;
+ register u_char *cp;
+ register int n;
+ u_char *eom;
+ int type, class, buflen, ancount, qdcount, haveanswer, i, nchar;
+ char aux1[30], aux2[30], ans[30], *in, *st, *pauxt, *bp, **ap,
+ *paux1 = &aux1[0], *paux2 = &aux2[0], flag = 0;
+static struct netent net_entry;
+static char *net_aliases[MAXALIASES], netbuf[BUFSIZ+1];
/*
* find first satisfactory answer
@@ -142,12 +145,10 @@ static char *net_aliases[MAXALIASES],
h_errno = HOST_NOT_FOUND;
else
h_errno = TRY_AGAIN;
-
- return ((struct netent *) NULL);
+ return (NULL);
}
- while (qdcount-- > 0){
+ while (qdcount-- > 0)
cp += __dn_skipname(cp, eom) + QFIXEDSZ;
- }
ap = net_aliases;
*ap = NULL;
net_entry.n_aliases = net_aliases;
@@ -169,27 +170,26 @@ static char *net_aliases[MAXALIASES],
cp += n;
return (NULL);
}
- cp += n;
+ cp += n;
*ap++ = bp;
- bp += (strlen(bp) + 1);
- net_entry.n_addrtype = (class == C_IN)
- ? AF_INET
- : AF_UNSPEC;
+ bp += strlen(bp) + 1;
+ net_entry.n_addrtype =
+ (class == C_IN) ? AF_INET : AF_UNSPEC;
haveanswer++;
}
}
if (haveanswer) {
*ap = NULL;
switch (net_i) {
- case BYADDR :
+ case BYADDR:
net_entry.n_name = *net_entry.n_aliases;
net_entry.n_net = 0L;
break;
- case BYNAME :
+ case BYNAME:
in = *net_entry.n_aliases;
net_entry.n_name = &ans[0];
aux2[0] = '\0';
- for (i = 0; i < 4; i++) {
+ for (i = 0; i < 4; i++) {
for (st = in, nchar = 0;
*st != '.';
st++, nchar++)
@@ -197,23 +197,23 @@ static char *net_aliases[MAXALIASES],
if (nchar != 1 || *in != '0' || flag) {
flag = 1;
(void)strncpy(paux1,
- (i==0) ?in :in-1,
- (i==0) ?nchar :nchar+1);
- paux1[(i==0) ?nchar :nchar+1] = '\0';
+ (i==0) ? in : in-1,
+ (i==0) ?nchar : nchar+1);
+ paux1[(i==0) ? nchar : nchar+1] = '\0';
pauxt = paux2;
paux2 = strcat(paux1, paux2);
paux1 = pauxt;
}
in = ++st;
- }
+ }
net_entry.n_net = inet_network(paux2);
+ break;
}
net_entry.n_aliases++;
return (&net_entry);
- } else {
- h_errno = TRY_AGAIN;
- return ((struct netent *) NULL);
}
+ h_errno = TRY_AGAIN;
+ return (NULL);
}
struct netent *
@@ -221,41 +221,40 @@ _getnetbydnsaddr(net, net_type)
register long net;
register int net_type;
{
- unsigned int netbr[4];
- int nn, anslen;
- querybuf buf;
- char qbuf[MAXDNAME];
- unsigned long net2;
- struct netent *net_entry;
+ unsigned int netbr[4];
+ int nn, anslen;
+ querybuf buf;
+ char qbuf[MAXDNAME];
+ unsigned long net2;
+ struct netent *net_entry;
if (net_type != AF_INET)
return (NULL);
- for (nn = 4, net2 = net; net2; net2 >>= 8) {
+ for (nn = 4, net2 = net; net2; net2 >>= 8)
netbr[--nn] = net2 & 0xff;
- }
switch (nn) {
- case 3: /* Class A */
- (void)sprintf(qbuf, "0.0.0.%u.in-addr.arpa",
- netbr[3]);
- break;
- case 2: /* Class B */
- (void)sprintf(qbuf, "0.0.%u.%u.in-addr.arpa",
- netbr[3], netbr[2]);
- break;
- case 1: /* Class C */
- (void)sprintf(qbuf, "0.%u.%u.%u.in-addr.arpa",
- netbr[3], netbr[2], netbr[1]);
- break;
- case 0: /* Class D - E */
- (void)sprintf(qbuf, "%u.%u.%u.%u.in-addr.arpa",
- netbr[3], netbr[2], netbr[1], netbr[0]);
- break;
+ case 3: /* Class A */
+ sprintf(qbuf, "0.0.0.%u.in-addr.arpa", netbr[3]);
+ break;
+ case 2: /* Class B */
+ sprintf(qbuf, "0.0.%u.%u.in-addr.arpa", netbr[3], netbr[2]);
+ break;
+ case 1: /* Class C */
+ sprintf(qbuf, "0.%u.%u.%u.in-addr.arpa", netbr[3], netbr[2],
+ netbr[1]);
+ break;
+ case 0: /* Class D - E */
+ sprintf(qbuf, "%u.%u.%u.%u.in-addr.arpa", netbr[3], netbr[2],
+ netbr[1], netbr[0]);
+ break;
}
- anslen = res_query(qbuf, C_IN, T_PTR, buf.buf, sizeof buf.buf);
+ anslen = res_query(qbuf, C_IN, T_PTR, (u_char *)&buf, sizeof(buf));
if (anslen < 0) {
+#ifdef DEBUG
if (_res.options & RES_DEBUG)
printf("res_query failed\n");
+#endif
return (NULL);
}
net_entry = getnetanswer(&buf, anslen, BYADDR);
@@ -263,28 +262,34 @@ _getnetbydnsaddr(net, net_type)
unsigned u_net = net; /* maybe net should be unsigned ? */
/* Strip trailing zeros */
- while ((u_net & 0xff) == 0 && u_net != 0) {
+ while ((u_net & 0xff) == 0 && u_net != 0)
u_net >>= 8;
- }
net_entry->n_net = u_net;
+ return (net_entry);
}
- return (net_entry);
+ return (NULL);
}
struct netent *
_getnetbydnsname(net)
register const char *net;
{
- int anslen;
- querybuf buf;
- char qbuf[MAXDNAME];
+ int anslen;
+ querybuf buf;
+ char qbuf[MAXDNAME];
- (void)strcpy(&qbuf[0],net);
- anslen = res_search(qbuf, C_IN, T_PTR, buf.buf, sizeof buf.buf);
+ if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
+ h_errno = NETDB_INTERNAL;
+ return (NULL);
+ }
+ strcpy(&qbuf[0], net);
+ anslen = res_search(qbuf, C_IN, T_PTR, (u_char *)&buf, sizeof(buf));
if (anslen < 0) {
+#ifdef DEBUG
if (_res.options & RES_DEBUG)
printf("res_query failed\n");
- return NULL;
+#endif
+ return (NULL);
}
return getnetanswer(&buf, anslen, BYNAME);
}
diff --git a/lib/libc/net/getnetbyht.c b/lib/libc/net/getnetbyht.c
index 4f6439c..24ca2ed 100644
--- a/lib/libc/net/getnetbyht.c
+++ b/lib/libc/net/getnetbyht.c
@@ -31,6 +31,16 @@
* SUCH DAMAGE.
*/
+/* Portions Copyright (c) 1993 Carlos Leandro and Rui Salgueiro
+ * Dep. Matematica Universidade de Coimbra, Portugal, Europe
+ *
+ * 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.
+ *
+ * from getnetent.c 1.1 (Coimbra) 93/06/02
+ */
+
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid[] = "@(#)getnetent.c 8.1 (Berkeley) 6/4/93";
#endif /* LIBC_SCCS and not lint */
@@ -39,6 +49,7 @@ static char sccsid[] = "@(#)getnetent.c 8.1 (Berkeley) 6/4/93";
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
+#include <arpa/nameser.h>
#include <netdb.h>
#include <stdio.h>
#include <string.h>
@@ -55,6 +66,7 @@ void
_setnethtent(f)
int f;
{
+
if (netf == NULL)
netf = fopen(_PATH_NETWORKS, "r" );
else
@@ -65,6 +77,7 @@ _setnethtent(f)
void
_endnethtent()
{
+
if (netf) {
fclose(netf);
netf = NULL;
@@ -103,7 +116,7 @@ again:
net.n_net = inet_network(cp);
net.n_addrtype = AF_INET;
q = net.n_aliases = net_aliases;
- if (p != NULL)
+ if (p != NULL)
cp = p;
while (cp && *cp) {
if (*cp == ' ' || *cp == '\t') {
@@ -128,7 +141,7 @@ _getnetbyhtname(name)
register char **cp;
setnetent(_net_stayopen);
- while ((p = getnetent())) {
+ while (p = getnetent()) {
if (strcasecmp(p->n_name, name) == 0)
break;
for (cp = p->n_aliases; *cp != 0; cp++)
@@ -141,7 +154,6 @@ found:
return (p);
}
-
struct netent *
_getnetbyhtaddr(net, type)
register long net;
@@ -150,7 +162,7 @@ _getnetbyhtaddr(net, type)
register struct netent *p;
setnetent(_net_stayopen);
- while ((p = getnetent()))
+ while (p = getnetent())
if (p->n_addrtype == type && p->n_net == net)
break;
if (!_net_stayopen)
diff --git a/lib/libc/net/herror.c b/lib/libc/net/herror.c
index 9b94ee4..84626ed 100644
--- a/lib/libc/net/herror.c
+++ b/lib/libc/net/herror.c
@@ -53,7 +53,7 @@
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid[] = "@(#)herror.c 8.1 (Berkeley) 6/4/93";
-static char rcsid[] = "$Id: herror.c,v 1.2 1995/05/30 05:40:49 rgrimes Exp $";
+static char rcsid[] = "$Id: herror.c,v 1.3 1995/08/20 20:02:41 peter Exp $";
#endif /* LIBC_SCCS and not lint */
#include <sys/types.h>
@@ -69,7 +69,7 @@ const char *h_errlist[] = {
"Unknown server error", /* 3 NO_RECOVERY */
"No address associated with name", /* 4 NO_ADDRESS */
};
-int h_nerr = { sizeof(h_errlist)/sizeof(h_errlist[0]) };
+int h_nerr = { sizeof h_errlist / sizeof h_errlist[0] };
extern int h_errno;
diff --git a/lib/libc/net/inet_addr.c b/lib/libc/net/inet_addr.c
index f69d0fc..a1ac899 100644
--- a/lib/libc/net/inet_addr.c
+++ b/lib/libc/net/inet_addr.c
@@ -1,7 +1,9 @@
/*
+ * ++Copyright++ 1983, 1990, 1993
+ * -
* Copyright (c) 1983, 1990, 1993
- * The Regents of the University of California. All rights reserved.
- *
+ * 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:
@@ -12,12 +14,12 @@
* 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.
+ * 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
@@ -29,10 +31,31 @@
* 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.
+ * -
+ * --Copyright--
*/
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid[] = "@(#)inet_addr.c 8.1 (Berkeley) 6/17/93";
+static char rcsid[] = "$Id$";
#endif /* LIBC_SCCS and not lint */
#include <sys/param.h>
@@ -55,7 +78,7 @@ inet_addr(cp)
return (INADDR_NONE);
}
-/*
+/*
* Check whether "cp" is a valid ascii representation
* of an Internet address and convert to a binary address.
* Returns 1 if the address is valid, 0 if not.
@@ -73,50 +96,52 @@ inet_aton(cp, addr)
u_int parts[4];
register u_int *pp = parts;
+ c = *cp;
for (;;) {
/*
* Collect number up to ``.''.
* Values are specified as for C:
- * 0x=hex, 0=octal, other=decimal.
+ * 0x=hex, 0=octal, isdigit=decimal.
*/
+ if (!isdigit(c))
+ return (0);
val = 0; base = 10;
- if (*cp == '0') {
- if (*++cp == 'x' || *cp == 'X')
- base = 16, cp++;
+ if (c == '0') {
+ c = *++cp;
+ if (c == 'x' || c == 'X')
+ base = 16, c = *++cp;
else
base = 8;
}
- while ((c = *cp) != '\0') {
+ for (;;) {
if (isascii(c) && isdigit(c)) {
val = (val * base) + (c - '0');
- cp++;
- continue;
- }
- if (base == 16 && isascii(c) && isxdigit(c)) {
- val = (val << 4) +
+ c = *++cp;
+ } else if (base == 16 && isascii(c) && isxdigit(c)) {
+ val = (val << 4) |
(c + 10 - (islower(c) ? 'a' : 'A'));
- cp++;
- continue;
- }
- break;
+ c = *++cp;
+ } else
+ break;
}
- if (*cp == '.') {
+ if (c == '.') {
/*
* Internet format:
* a.b.c.d
- * a.b.c (with c treated as 16-bits)
+ * a.b.c (with c treated as 16 bits)
* a.b (with b treated as 24 bits)
*/
- if (pp >= parts + 3 || val > 0xff)
+ if (pp >= parts + 3)
return (0);
- *pp++ = val, cp++;
+ *pp++ = val;
+ c = *++cp;
} else
break;
}
/*
* Check for trailing characters.
*/
- if (*cp && (!isascii(*cp) || !isspace(*cp)))
+ if (c != '\0' && (!isascii(c) || !isspace(c)))
return (0);
/*
* Concoct the address according to
@@ -125,6 +150,9 @@ inet_aton(cp, addr)
n = pp - parts + 1;
switch (n) {
+ case 0:
+ return (0); /* initial nondigit */
+
case 1: /* a -- 32 bits */
break;
diff --git a/lib/libc/net/res_config.h b/lib/libc/net/res_config.h
index a1339d9..7d55664 100644
--- a/lib/libc/net/res_config.h
+++ b/lib/libc/net/res_config.h
@@ -1,7 +1,8 @@
#define DEBUG 1 /* enable debugging code (needed for dig) */
#undef ALLOW_T_UNSPEC /* enable the "unspec" RR type for old athena */
#define RESOLVSORT /* allow sorting of addresses in gethostbyname */
-#undef RFC1535 /* comply with RFC1535 */
+#define RFC1535 /* comply with RFC1535 (STRONGLY reccomended by vixie)*/
#undef ALLOW_UPDATES /* destroy your system security */
#undef USELOOPBACK /* res_init() bind to localhost */
#undef SUNSECURITY /* verify gethostbyaddr() calls - WE DONT NEED IT */
+#define MULTI_PTRS_ARE_ALIASES /* fold multiple PTR records into aliases */
OpenPOWER on IntegriCloud