aboutsummaryrefslogtreecommitdiff
path: root/resolv
diff options
context:
space:
mode:
Diffstat (limited to 'resolv')
-rw-r--r--resolv/Makefile4
-rw-r--r--resolv/arpa/nameser.h8
-rw-r--r--resolv/gethnamaddr.c23
-rw-r--r--resolv/getnetbyname.c4
-rw-r--r--resolv/getnetnamadr.c19
-rw-r--r--resolv/herror.c6
-rw-r--r--resolv/inet_addr.c191
-rw-r--r--resolv/nsap_addr.c1
-rw-r--r--resolv/res_comp.c6
-rw-r--r--resolv/res_debug.c70
-rw-r--r--resolv/res_init.c67
-rw-r--r--resolv/res_mkquery.c12
-rw-r--r--resolv/res_query.c7
-rw-r--r--resolv/res_send.c42
-rw-r--r--resolv/resolv.h9
-rw-r--r--resolv/sethostent.c36
16 files changed, 376 insertions, 129 deletions
diff --git a/resolv/Makefile b/resolv/Makefile
index 510f16c..e07cfb0 100644
--- a/resolv/Makefile
+++ b/resolv/Makefile
@@ -1,4 +1,4 @@
-# Copyright (C) 1994 Free Software Foundation, Inc.
+# Copyright (C) 1994, 1995 Free Software Foundation, Inc.
# This file is part of the GNU C Library.
# The GNU C Library is free software; you can redistribute it and/or
@@ -26,6 +26,6 @@ distribute := ../conf/portability.h
routines := gethnamaddr getnetbyaddr getnetbyname getnetent getnetnamadr \
herror nsap_addr res_comp res_debug res_init res_mkquery \
- res_query res_send sethostent
+ res_query res_send sethostent inet_addr
include ../Rules
diff --git a/resolv/arpa/nameser.h b/resolv/arpa/nameser.h
index 1a660ad..3792b79 100644
--- a/resolv/arpa/nameser.h
+++ b/resolv/arpa/nameser.h
@@ -83,7 +83,7 @@
* is new enough to contain a certain feature.
*/
-#define __BIND 19940417 /* interface version stamp */
+#define __BIND 19950621 /* interface version stamp */
/*
* Define constants based on rfc883
@@ -258,8 +258,7 @@ typedef struct {
unsigned rd: 1; /* recursion desired */
/* fields in fourth byte */
unsigned ra: 1; /* recursion available */
- unsigned pr: 1; /* primary server req'd (!standard) */
- unsigned unused :2; /* unused bits (MBZ as of 4.9.3a3) */
+ unsigned unused :3; /* unused bits (MBZ as of 4.9.3a3) */
unsigned rcode :4; /* response code */
#endif
#if BYTE_ORDER == LITTLE_ENDIAN || BYTE_ORDER == PDP_ENDIAN
@@ -271,8 +270,7 @@ typedef struct {
unsigned qr :1; /* response flag */
/* fields in fourth byte */
unsigned rcode :4; /* response code */
- unsigned unused :2; /* unused bits (MBZ as of 4.9.3a3) */
- unsigned pr :1; /* primary server req'd (!standard) */
+ unsigned unused :3; /* unused bits (MBZ as of 4.9.3a3) */
unsigned ra :1; /* recursion available */
#endif
/* remaining bytes */
diff --git a/resolv/gethnamaddr.c b/resolv/gethnamaddr.c
index 55a3fb0..d3b68f7 100644
--- a/resolv/gethnamaddr.c
+++ b/resolv/gethnamaddr.c
@@ -250,10 +250,12 @@ getanswer(answer, anslen, qname, qclass, qtype)
continue;
}
if (type != qtype) {
- syslog(LOG_NOTICE|LOG_AUTH,
+ /* CNAME->PTR should not cause a log message. */
+ if (!(qtype == T_PTR && type == T_CNAME))
+ syslog(LOG_NOTICE|LOG_AUTH,
"gethostby*.getanswer: asked for \"%s %s %s\", got type \"%s\"",
- qname, p_class(qclass), p_type(qtype),
- p_type(type));
+ qname, p_class(qclass), p_type(qtype),
+ p_type(type));
cp += n;
continue; /* XXX - had_error++ ? */
}
@@ -380,6 +382,11 @@ gethostbyname(name)
int n;
extern struct hostent *_gethtbyname();
+ if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
+ h_errno = NETDB_INTERNAL;
+ return (NULL);
+ }
+
/*
* if there aren't any dots, it could be a user-level alias.
* this is also done in res_query() since we are not the only
@@ -406,7 +413,9 @@ gethostbyname(name)
h_errno = HOST_NOT_FOUND;
return (NULL);
}
- host.h_name = (char *)name;
+ strncpy(hostbuf, name, MAXDNAME);
+ hostbuf[MAXDNAME] = '\0';
+ host.h_name = hostbuf;
host.h_aliases = host_aliases;
host_aliases[0] = NULL;
host.h_addrtype = AF_INET;
@@ -451,6 +460,10 @@ gethostbyaddr(addr, len, type)
#endif /*SUNSECURITY*/
extern struct hostent *_gethtbyaddr();
+ if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
+ h_errno = NETDB_INTERNAL;
+ return (NULL);
+ }
if (type != AF_INET) {
errno = EAFNOSUPPORT;
h_errno = NETDB_INTERNAL;
@@ -480,7 +493,7 @@ gethostbyaddr(addr, len, type)
old_options = _res.options;
_res.options &= ~RES_DNSRCH;
_res.options |= RES_DEFNAMES;
- if (!(rhp = gethostbyname(hp->h_name))) {
+ if (!(rhp = gethostbyname(hname2))) {
syslog(LOG_NOTICE|LOG_AUTH,
"gethostbyaddr: No A record for %s (verifying [%s])",
hname2, inet_ntoa(*((struct in_addr *)addr)));
diff --git a/resolv/getnetbyname.c b/resolv/getnetbyname.c
index 1d2029f..cc3f281 100644
--- a/resolv/getnetbyname.c
+++ b/resolv/getnetbyname.c
@@ -44,11 +44,7 @@ extern int _net_stayopen;
struct netent *
_getnetbyname(name)
-#if (defined(sun) || defined(DGUX))
- register char *name;
-#else
register const char *name;
-#endif
{
register struct netent *p;
register char **cp;
diff --git a/resolv/getnetnamadr.c b/resolv/getnetnamadr.c
index 19a31af..e5cc505 100644
--- a/resolv/getnetnamadr.c
+++ b/resolv/getnetnamadr.c
@@ -56,7 +56,6 @@ static char rcsid[] = "$Id$";
#include <ctype.h>
#include <errno.h>
#include <string.h>
-#include "conf/portability.h"
extern int h_errno;
@@ -65,11 +64,7 @@ extern int errno;
#endif
struct netent *_getnetbyaddr __P((long net, int type));
-#if defined(sun)
-struct netent *_getnetbyname __P((char *name));
-#else
struct netent *_getnetbyname __P((const char *name));
-#endif
#define BYADDR 0
#define BYNAME 1
@@ -102,8 +97,7 @@ getnetanswer(answer, anslen, net_i)
register u_char *cp;
register int n;
u_char *eom;
- int type, class, buflen, ancount, qdcount, haveanswer, i, nchar,
- getclass = C_ANY, net_length = 0;
+ 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;
@@ -264,19 +258,18 @@ getnetbyaddr(net, net_type)
struct netent *
getnetbyname(net)
-#if defined(sun)
- register char *net;
-#else
register const char *net;
-#endif
{
- unsigned int netbr[4];
int anslen;
querybuf buf;
char qbuf[MAXDNAME];
struct netent *net_entry;
- strcpy(&qbuf[0],net);
+ 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
diff --git a/resolv/herror.c b/resolv/herror.c
index 872a009..988e52c 100644
--- a/resolv/herror.c
+++ b/resolv/herror.c
@@ -68,7 +68,7 @@ static char rcsid[] = "$Id$";
# include "../conf/portability.h"
#endif
-char *h_errlist[] = {
+const char *h_errlist[] = {
"Resolver Error 0 (no error)",
"Unknown host", /* 1 HOST_NOT_FOUND */
"Host name lookup failure", /* 2 TRY_AGAIN */
@@ -98,7 +98,7 @@ herror(s)
v->iov_len = 2;
v++;
}
- v->iov_base = hstrerror(h_errno);
+ v->iov_base = (char *)hstrerror(h_errno);
v->iov_len = strlen(v->iov_base);
v++;
v->iov_base = "\n";
@@ -106,7 +106,7 @@ herror(s)
writev(STDERR_FILENO, iov, (v - iov) + 1);
}
-char *
+const char *
hstrerror(err)
int err;
{
diff --git a/resolv/inet_addr.c b/resolv/inet_addr.c
new file mode 100644
index 0000000..2a15067
--- /dev/null
+++ b/resolv/inet_addr.c
@@ -0,0 +1,191 @@
+/*
+ * ++Copyright++ 1983, 1990, 1993
+ * -
+ * Copyright (c) 1983, 1990, 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.
+ * -
+ * --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>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <ctype.h>
+#include "../conf/portability.h"
+
+/* these are compatibility routines, not needed on recent BSD releases */
+
+#ifndef NEED_INETADDR
+int __inet_addr_unneeded__;
+#else
+
+/*
+ * Ascii internet address interpretation routine.
+ * The value returned is in network order.
+ */
+u_long
+inet_addr(cp)
+ register const char *cp;
+{
+ struct in_addr val;
+
+ if (inet_aton(cp, &val))
+ return (val.s_addr);
+ return (INADDR_NONE);
+}
+#endif /*NEED_INETADDR*/
+
+#ifndef NEED_INETATON
+int __inet_aton_unneeded__;
+#else
+
+/*
+ * 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.
+ * This replaces inet_addr, the return value from which
+ * cannot distinguish between failure and a local broadcast address.
+ */
+int
+inet_aton(cp, addr)
+ register const char *cp;
+ struct in_addr *addr;
+{
+ register u_long val;
+ register int base, n;
+ register char c;
+ 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.
+ */
+ val = 0; base = 10;
+ if (c == '0') {
+ c = *++cp;
+ if (c == 'x' || c == 'X')
+ base = 16, c = *++cp;
+ else
+ base = 8;
+ }
+ while (c != '\0') {
+ if (isascii(c) && isdigit(c)) {
+ val = (val * base) + (c - '0');
+ c = *++cp;
+ } else if (base == 16 && isascii(c) && isxdigit(c)) {
+ val = (val << 4) |
+ (c + 10 - (islower(c) ? 'a' : 'A'));
+ c = *++cp;
+ } else
+ break;
+ }
+ if (c == '.') {
+ /*
+ * Internet format:
+ * a.b.c.d
+ * a.b.c (with c treated as 16 bits)
+ * a.b (with b treated as 24 bits)
+ */
+ if (pp >= parts + 3 || val > 0xff)
+ return (0);
+ *pp++ = val;
+ c = *++cp;
+ } else
+ break;
+ }
+ /*
+ * Check for trailing characters.
+ */
+ if (c && (!isascii(c) || (!isspace(c) && !ispunct(c))))
+ return (0);
+ /*
+ * Concoct the address according to
+ * the number of parts specified.
+ */
+ n = pp - parts + 1;
+ switch (n) {
+
+ case 0:
+ return (0); /* initial nondigit */
+
+ case 1: /* a -- 32 bits */
+ break;
+
+ case 2: /* a.b -- 8.24 bits */
+ if (val > 0xffffff)
+ return (0);
+ val |= parts[0] << 24;
+ break;
+
+ case 3: /* a.b.c -- 8.8.16 bits */
+ if (val > 0xffff)
+ return (0);
+ val |= (parts[0] << 24) | (parts[1] << 16);
+ break;
+
+ case 4: /* a.b.c.d -- 8.8.8.8 bits */
+ if (val > 0xff)
+ return (0);
+ val |= (parts[0] << 24) | (parts[1] << 16) | (parts[2] << 8);
+ break;
+ }
+ if (addr)
+ addr->s_addr = htonl(val);
+ return (1);
+}
+#endif /*NEED_INETATON*/
diff --git a/resolv/nsap_addr.c b/resolv/nsap_addr.c
index ea18501..6a8b75c 100644
--- a/resolv/nsap_addr.c
+++ b/resolv/nsap_addr.c
@@ -34,7 +34,6 @@ inet_nsap_addr(ascii, binary, maxlen)
int maxlen;
{
register u_char c, nib;
- u_char *start = binary;
u_int len = 0;
while ((c = *ascii++) != '\0' && len < maxlen) {
diff --git a/resolv/res_comp.c b/resolv/res_comp.c
index ad24a98..aa6afa3 100644
--- a/resolv/res_comp.c
+++ b/resolv/res_comp.c
@@ -340,11 +340,7 @@ dn_find(exp_dn, msg, dnptrs, lastdnptr)
}
/*
- * Routines to insert/extract short/long's. Must account for byte
- * order and non-alignment problems. This code at least has the
- * advantage of being portable.
- *
- * used by sendmail.
+ * Routines to insert/extract short/long's.
*/
u_int16_t
diff --git a/resolv/res_debug.c b/resolv/res_debug.c
index 254e1ef..602042e 100644
--- a/resolv/res_debug.c
+++ b/resolv/res_debug.c
@@ -64,6 +64,7 @@ static char rcsid[] = "$Id$";
#include <arpa/nameser.h>
#include <stdio.h>
+#include <netdb.h>
#include <resolv.h>
#if defined(BSD) && (BSD >= 199103)
# include <string.h>
@@ -113,12 +114,13 @@ const char *_res_resultcodes[] = {
"NOCHANGE",
};
-static char retbuf[16];
-
+/* XXX: we should use getservbyport() instead. */
static const char *
dewks(wks)
int wks;
{
+ static char nbuf[20];
+
switch (wks) {
case 5: return "rje";
case 7: return "echo";
@@ -166,14 +168,17 @@ dewks(wks)
case 161: return "snmp";
case 162: return "snmp-trap";
case 170: return "print-srv";
- default: (void) sprintf(retbuf, "%d", wks); return (retbuf);
+ default: (void) sprintf(nbuf, "%d", wks); return (nbuf);
}
}
+/* XXX: we should use getprotobynumber() instead. */
static const char *
deproto(protonum)
int protonum;
{
+ static char nbuf[20];
+
switch (protonum) {
case 1: return "icmp";
case 2: return "igmp";
@@ -187,13 +192,13 @@ deproto(protonum)
case 12: return "pup";
case 16: return "chaos";
case 17: return "udp";
- default: (void) sprintf(retbuf, "%d", protonum); return (retbuf);
+ default: (void) sprintf(nbuf, "%d", protonum); return (nbuf);
}
}
static const u_char *
-do_rrset(msg, cp, cnt, pflag, file, hs)
- int cnt, pflag;
+do_rrset(msg, len, cp, cnt, pflag, file, hs)
+ int cnt, pflag, len;
const u_char *cp, *msg;
const char *hs;
FILE *file;
@@ -222,7 +227,7 @@ do_rrset(msg, cp, cnt, pflag, file, hs)
cp += INT16SZ;
cp += dlen;
}
- if ((cp - msg) > PACKETSZ)
+ if ((cp - msg) > len)
return (NULL);
}
if ((!_res.pfcode) ||
@@ -285,6 +290,9 @@ __fp_nquery(msg, len, file)
register const HEADER *hp;
register int n;
+ if ((_res.options & RES_INIT) == 0 && res_init() == -1)
+ return;
+
#define TruncTest(x) if (x >= endMark) goto trunc
#define ErrorTest(x) if (x == NULL) goto error
@@ -314,8 +322,6 @@ __fp_nquery(msg, len, file)
fprintf(file, " rd");
if (hp->ra)
fprintf(file, " ra");
- if (hp->pr)
- fprintf(file, " pr");
}
if ((!_res.pfcode) || (_res.pfcode & RES_PRF_HEAD1)) {
fprintf(file, "; Ques: %d", ntohs(hp->qdcount));
@@ -336,7 +342,7 @@ __fp_nquery(msg, len, file)
while (--n >= 0) {
fprintf(file, ";;\t");
TruncTest(cp);
- cp = p_cdname(cp, msg, file);
+ cp = p_cdnname(cp, msg, len, file);
ErrorTest(cp);
TruncTest(cp);
if ((!_res.pfcode) || (_res.pfcode & RES_PRF_QUES))
@@ -355,7 +361,7 @@ __fp_nquery(msg, len, file)
* Print authoritative answer records
*/
TruncTest(cp);
- cp = do_rrset(msg, cp, hp->ancount, RES_PRF_ANS, file,
+ cp = do_rrset(msg, len, cp, hp->ancount, RES_PRF_ANS, file,
";; ANSWERS:\n");
ErrorTest(cp);
@@ -363,7 +369,7 @@ __fp_nquery(msg, len, file)
* print name server records
*/
TruncTest(cp);
- cp = do_rrset(msg, cp, hp->nscount, RES_PRF_AUTH, file,
+ cp = do_rrset(msg, len, cp, hp->nscount, RES_PRF_AUTH, file,
";; AUTHORITY RECORDS:\n");
ErrorTest(cp);
@@ -371,7 +377,7 @@ __fp_nquery(msg, len, file)
/*
* print additional records
*/
- cp = do_rrset(msg, cp, hp->arcount, RES_PRF_ADD, file,
+ cp = do_rrset(msg, len, cp, hp->arcount, RES_PRF_ADD, file,
";; ADDITIONAL RECORDS:\n");
ErrorTest(cp);
return;
@@ -425,7 +431,7 @@ __p_fqname(cp, msg, file)
FILE *file;
{
char name[MAXDNAME];
- int n, len;
+ int n;
if ((n = dn_expand(msg, cp + MAXCDNAME, cp, name, sizeof name)) < 0)
return (NULL);
@@ -453,6 +459,10 @@ __p_rr(cp, msg, file)
u_int32_t tmpttl, t;
int lcnt;
+ if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
+ h_errno = NETDB_INTERNAL;
+ return (NULL);
+ }
if ((cp = p_fqname(cp, msg, file)) == NULL)
return (NULL); /* compression error */
type = _getshort((u_char*)cp);
@@ -465,7 +475,7 @@ __p_rr(cp, msg, file)
cp += INT16SZ;
cp1 = cp;
if ((!_res.pfcode) || (_res.pfcode & RES_PRF_TTLID))
- fprintf(file, "\t%lu", tmpttl);
+ fprintf(file, "\t%lu", (u_long)tmpttl);
if ((!_res.pfcode) || (_res.pfcode & RES_PRF_CLASS))
fprintf(file, "\t%s", __p_class(class));
fprintf(file, "\t%s", __p_type(type));
@@ -534,15 +544,19 @@ __p_rr(cp, msg, file)
return (NULL);
fputs(" (\n", file);
t = _getlong((u_char*)cp); cp += INT32SZ;
- fprintf(file, "\t\t\t%lu\t; serial\n", t);
+ fprintf(file, "\t\t\t%lu\t; serial\n", (u_long)t);
t = _getlong((u_char*)cp); cp += INT32SZ;
- fprintf(file, "\t\t\t%lu\t; refresh (%s)\n", t, __p_time(t));
+ fprintf(file, "\t\t\t%lu\t; refresh (%s)\n",
+ (u_long)t, __p_time(t));
t = _getlong((u_char*)cp); cp += INT32SZ;
- fprintf(file, "\t\t\t%lu\t; retry (%s)\n", t, __p_time(t));
+ fprintf(file, "\t\t\t%lu\t; retry (%s)\n",
+ (u_long)t, __p_time(t));
t = _getlong((u_char*)cp); cp += INT32SZ;
- fprintf(file, "\t\t\t%lu\t; expire (%s)\n", t, __p_time(t));
+ fprintf(file, "\t\t\t%lu\t; expire (%s)\n",
+ (u_long)t, __p_time(t));
t = _getlong((u_char*)cp); cp += INT32SZ;
- fprintf(file, "\t\t\t%lu )\t; minimum (%s)", t, __p_time(t));
+ fprintf(file, "\t\t\t%lu )\t; minimum (%s)",
+ (u_long)t, __p_time(t));
break;
case T_MX:
@@ -673,8 +687,6 @@ __p_rr(cp, msg, file)
return (cp);
}
-static char nbuf[40];
-
/*
* Return a string for the type
*/
@@ -682,6 +694,8 @@ const char *
__p_type(type)
int type;
{
+ static char nbuf[20];
+
switch (type) {
case T_A: return "A";
case T_NS: return "NS";
@@ -731,6 +745,8 @@ const char *
__p_class(class)
int class;
{
+ static char nbuf[20];
+
switch (class) {
case C_IN: return "IN";
case C_HS: return "HS";
@@ -746,12 +762,14 @@ const char *
__p_option(option)
u_long option;
{
+ static char nbuf[40];
+
switch (option) {
case RES_INIT: return "init";
case RES_DEBUG: return "debug";
- case RES_AAONLY: return "aaonly";
+ case RES_AAONLY: return "aaonly(unimpl)";
case RES_USEVC: return "usevc";
- case RES_PRIMARY: return "primry";
+ case RES_PRIMARY: return "primry(unimpl)";
case RES_IGNTC: return "igntc";
case RES_RECURSE: return "recurs";
case RES_DEFNAMES: return "defnam";
@@ -759,7 +777,8 @@ __p_option(option)
case RES_DNSRCH: return "dnsrch";
case RES_INSECURE1: return "insecure1";
case RES_INSECURE2: return "insecure2";
- default: sprintf(nbuf, "?0x%x?", option); return (nbuf);
+ default: sprintf(nbuf, "?0x%lx?", (u_long)option);
+ return (nbuf);
}
}
@@ -770,6 +789,7 @@ char *
__p_time(value)
u_int32_t value;
{
+ static char nbuf[40];
int secs, mins, hours, days;
register char *p;
diff --git a/resolv/res_init.c b/resolv/res_init.c
index 98807ff..42c7c2e 100644
--- a/resolv/res_init.c
+++ b/resolv/res_init.c
@@ -60,6 +60,7 @@ static char rcsid[] = "$Id$";
#include <sys/param.h>
#include <sys/socket.h>
+#include <sys/time.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <arpa/nameser.h>
@@ -75,7 +76,7 @@ static char rcsid[] = "$Id$";
# include "../conf/portability.h"
#endif
-/*
+/*-------------------------------------- info about "sortlist" --------------
* Marc Majka 1994/04/16
* Allan Nathanson 1994/10/29 (BIND 4.9.3.x)
*
@@ -93,10 +94,9 @@ static char rcsid[] = "$Id$";
* "search" property.
* - The sortlist comprised of IP address netmask pairs are stored as
* values of the "sortlist" property. The IP address and optional netmask
- * should be seperated by a slash (/) character.
+ * should be seperated by a slash (/) or ampersand (&) character.
* - Internal resolver variables can be set from the value of the "options"
* property.
- *
*/
#if defined(NeXT)
# include <netinfo/ni.h>
@@ -112,6 +112,8 @@ static int netinfo_res_init __P((int *haveenv, int *havesearch));
static void res_setoptions __P((char *, char *));
#ifdef RESOLVSORT
+static const char sort_mask[] = "/&";
+#define ISSORTMASK(ch) (strchr(sort_mask, ch) != NULL)
static u_int32_t net_mask __P((struct in_addr));
#endif
@@ -146,11 +148,12 @@ struct __res_state _res;
*
* Return 0 if completes successfully, -1 on error
*/
+int
res_init()
{
register FILE *fp;
register char *cp, **pp;
- register int n, dots;
+ register int n;
char buf[BUFSIZ];
int nserv = 0; /* number of nameserver records read from file */
int haveenv = 0;
@@ -159,6 +162,9 @@ res_init()
int nsort = 0;
char *net;
#endif
+#ifndef RFC1535
+ int dots;
+#endif
/*
* These three fields used to be statically initialized. This made
@@ -172,13 +178,26 @@ res_init()
* will follow. Zero for any of these fields would make no sense,
* so one can safely assume that the applications were already getting
* unexpected results.
+ *
+ * _res.options is tricky since some apps were known to diddle the bits
+ * before res_init() was first called. We can't replicate that semantic
+ * with dynamic initialization (they may have turned bits off that are
+ * set in RES_DEFAULT). Our solution is to declare such applications
+ * "broken". They could fool us by setting RES_INIT but none do (yet).
*/
if (!_res.retrans)
_res.retrans = RES_TIMEOUT;
if (!_res.retry)
_res.retry = 4;
if (!(_res.options & RES_INIT))
- _res.options |= RES_DEFAULT;
+ _res.options = RES_DEFAULT;
+
+ /*
+ * This one used to initialize implicitly to zero, so unless the app
+ * has set it to something in particular, we can randomize it now.
+ */
+ if (!_res.id)
+ _res.id = res_randomid();
#ifdef USELOOPBACK
_res.nsaddr.sin_addr = inet_makeaddr(IN_LOOPBACKNET, 1);
@@ -317,17 +336,18 @@ res_init()
if (*cp == '\0' || *cp == '\n' || *cp == ';')
break;
net = cp;
- while (*cp && *cp != '/' &&
+ while (*cp && !ISSORTMASK(*cp) && *cp != ';' &&
isascii(*cp) && !isspace(*cp))
cp++;
n = *cp;
*cp = 0;
if (inet_aton(net, &a)) {
_res.sort_list[nsort].addr = a;
- if (n == '/') {
+ if (ISSORTMASK(n)) {
*cp++ = n;
net = cp;
- while (*cp && isascii(*cp) && !isspace(*cp))
+ while (*cp && *cp != ';' &&
+ isascii(*cp) && !isspace(*cp))
cp++;
n = *cp;
*cp = 0;
@@ -343,7 +363,7 @@ res_init()
}
nsort++;
}
- *cp++ = n;
+ *cp = n;
}
continue;
}
@@ -448,6 +468,7 @@ res_setoptions(options, source)
}
#ifdef RESOLVSORT
+/* XXX - should really support CIDR which means explicit masks always. */
static u_int32_t
net_mask(in) /* XXX - should really use system's version of this */
struct in_addr in;
@@ -556,17 +577,26 @@ netinfo_res_init(haveenv, havesearch)
n++) {
char ch;
char *cp;
+ const char *sp;
struct in_addr a;
- cp = strchr(nl.ni_namelist_val[n], '/');
+ cp = NULL;
+ for (sp = sort_mask; *sp; sp++) {
+ char *cp1;
+ cp1 = strchr(nl.ni_namelist_val[n], *sp);
+ if (cp && cp1)
+ cp = (cp < cp1)? cp : cp1;
+ else if (cp1)
+ cp = cp1;
+ }
if (cp != NULL) {
- ch = *cp;
- *cp = '\0';
+ ch = *cp;
+ *cp = '\0';
+ break;
}
-
if (inet_aton(nl.ni_namelist_val[n], &a)) {
_res.sort_list[nsort].addr = a;
- if (*cp && ch == '/') {
+ if (*cp && ISSORTMASK(ch)) {
*cp++ = ch;
if (inet_aton(cp, &a)) {
_res.sort_list[nsort].mask = a.s_addr;
@@ -607,3 +637,12 @@ netinfo_res_init(haveenv, havesearch)
return(0); /* if not using DNS configuration from NetInfo */
}
#endif /* NeXT */
+
+u_int16_t
+res_randomid()
+{
+ struct timeval now;
+
+ gettimeofday(&now, NULL);
+ return (0xffff & (now.tv_sec ^ now.tv_usec ^ getpid()));
+}
diff --git a/resolv/res_mkquery.c b/resolv/res_mkquery.c
index 0695670..33f788e 100644
--- a/resolv/res_mkquery.c
+++ b/resolv/res_mkquery.c
@@ -63,6 +63,7 @@ static char rcsid[] = "$Id$";
#include <arpa/nameser.h>
#include <stdio.h>
+#include <netdb.h>
#include <resolv.h>
#if defined(BSD) && (BSD >= 199103)
# include <string.h>
@@ -92,18 +93,20 @@ res_mkquery(op, dname, class, type, data, datalen, newrr_in, buf, buflen)
register HEADER *hp;
register u_char *cp;
register int n;
+#ifdef ALLOW_UPDATES
struct rrec *newrr = (struct rrec *) newrr_in;
+#endif
u_char *dnptrs[20], **dpp, **lastdnptr;
+ if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
+ h_errno = NETDB_INTERNAL;
+ return (-1);
+ }
#ifdef DEBUG
if (_res.options & RES_DEBUG)
printf(";; res_mkquery(%d, %s, %d, %d)\n",
op, dname, class, type);
#endif
- if (!(_res.options & RES_INIT)) {
- if (res_init() == -1)
- return (-1);
- }
/*
* Initialize header fields.
*/
@@ -113,7 +116,6 @@ res_mkquery(op, dname, class, type, data, datalen, newrr_in, buf, buflen)
hp = (HEADER *) buf;
hp->id = htons(++_res.id);
hp->opcode = op;
- hp->pr = (_res.options & RES_PRIMARY) != 0;
hp->rd = (_res.options & RES_RECURSE) != 0;
hp->rcode = NOERROR;
cp = buf + HFIXEDSZ;
diff --git a/resolv/res_query.c b/resolv/res_query.c
index 0d11889..eb0301f 100644
--- a/resolv/res_query.c
+++ b/resolv/res_query.c
@@ -324,6 +324,10 @@ res_querydomain(name, domain, class, type, answer, anslen)
const char *longname = nbuf;
int n;
+ if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
+ h_errno = NETDB_INTERNAL;
+ return (-1);
+ }
#ifdef DEBUG
if (_res.options & RES_DEBUG)
printf(";; res_querydomain(%s, %s, %d, %d)\n",
@@ -356,9 +360,12 @@ __hostalias(name)
char buf[BUFSIZ];
static char abuf[MAXDNAME];
+ if (_res.options & RES_NOALIASES)
+ return (NULL);
file = getenv("HOSTALIASES");
if (file == NULL || (fp = fopen(file, "r")) == NULL)
return (NULL);
+ setbuf(fp, NULL);
buf[sizeof(buf) - 1] = '\0';
while (fgets(buf, sizeof(buf), fp)) {
for (cp1 = buf; *cp1 && !isspace(*cp1); ++cp1)
diff --git a/resolv/res_send.c b/resolv/res_send.c
index 03055d3..4ee52b4 100644
--- a/resolv/res_send.c
+++ b/resolv/res_send.c
@@ -78,11 +78,13 @@ static char rcsid[] = "$Id$";
#include <arpa/inet.h>
#include <stdio.h>
+#include <netdb.h>
#include <errno.h>
#include <resolv.h>
#if defined(BSD) && (BSD >= 199306)
# include <stdlib.h>
# include <string.h>
+# include <unistd.h>
#else
# include "../conf/portability.h"
#endif
@@ -109,14 +111,14 @@ static int vc = 0; /* is the socket a virtual ciruit? */
#ifndef DEBUG
# define Dprint(cond, args) /*empty*/
-# define DprintQ(cond, args, query) /*empty*/
+# define DprintQ(cond, args, query, size) /*empty*/
# define Aerror(file, string, error, address) /*empty*/
# define Perror(file, string, error) /*empty*/
#else
# define Dprint(cond, args) if (cond) {fprintf args;} else {}
-# define DprintQ(cond, args, query) if (cond) {\
+# define DprintQ(cond, args, query, size) if (cond) {\
fprintf args;\
- __p_query(query);\
+ __fp_nquery(query, size, stdout);\
} else {}
static void
Aerror(file, string, error, address)
@@ -230,7 +232,7 @@ res_nameinquery(name, type, class, buf, eom)
if (n < 0)
return (-1);
cp += n;
- ttype = _getshort(cp); cp += INT16SZ;
+ ttype = _getshort(cp); cp += INT16SZ;
tclass = _getshort(cp); cp += INT16SZ;
if (ttype == type &&
tclass == class &&
@@ -290,10 +292,12 @@ res_send(buf, buflen, ans, anssiz)
register int n;
u_int badns; /* XXX NSMAX can't exceed #/bits in this var */
- DprintQ((_res.options & RES_DEBUG) || (_res.pfcode & RES_PRF_QUERY),
- (stdout, ";; res_send()\n"), buf);
- if (!(_res.options & RES_INIT) && res_init() == -1)
+ if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
+ /* errno should have been set by res_init() in this case. */
return (-1);
+ }
+ DprintQ((_res.options & RES_DEBUG) || (_res.pfcode & RES_PRF_QUERY),
+ (stdout, ";; res_send()\n"), buf, buflen);
v_circuit = (_res.options & RES_USEVC) || buflen > PACKETSZ;
gotsomewhere = 0;
connreset = 0;
@@ -362,12 +366,13 @@ res_send(buf, buflen, ans, anssiz)
if (s >= 0)
_res_close();
- s = socket(AF_INET, SOCK_STREAM, PF_UNSPEC);
+ s = socket(PF_INET, SOCK_STREAM, 0);
if (s < 0) {
terrno = errno;
Perror(stderr, "socket(vc)", errno);
return (-1);
}
+ errno = 0;
if (connect(s, (struct sockaddr *)nsap,
sizeof(struct sockaddr)) < 0) {
terrno = errno;
@@ -477,9 +482,12 @@ res_send(buf, buflen, ans, anssiz)
if ((s < 0) || vc) {
if (vc)
_res_close();
- s = socket(AF_INET, SOCK_DGRAM, PF_UNSPEC);
+ s = socket(PF_INET, SOCK_DGRAM, 0);
if (s < 0) {
- bad_dg_sock: terrno = errno;
+#if !defined(BSD) || (BSD < 199103)
+ bad_dg_sock:
+#endif
+ terrno = errno;
Perror(stderr, "socket(dg)", errno);
return (-1);
}
@@ -541,8 +549,7 @@ res_send(buf, buflen, ans, anssiz)
&no_addr,
sizeof(no_addr));
#else
- int s1 = socket(AF_INET, SOCK_DGRAM,
- PF_UNSPEC);
+ int s1 = socket(PF_INET, SOCK_DGRAM,0);
if (s1 < 0)
goto bad_dg_sock;
(void) dup2(s1, s);
@@ -593,6 +600,7 @@ res_send(buf, buflen, ans, anssiz)
_res_close();
goto next_ns;
}
+ errno = 0;
fromlen = sizeof(struct sockaddr_in);
resplen = recvfrom(s, (char*)ans, anssiz, 0,
(struct sockaddr *)&from, &fromlen);
@@ -611,7 +619,7 @@ res_send(buf, buflen, ans, anssiz)
DprintQ((_res.options & RES_DEBUG) ||
(_res.pfcode & RES_PRF_REPLY),
(stdout, ";; old answer:\n"),
- ans);
+ ans, resplen);
goto wait;
}
#if CHECK_SRVR_ADDR
@@ -625,7 +633,7 @@ res_send(buf, buflen, ans, anssiz)
DprintQ((_res.options & RES_DEBUG) ||
(_res.pfcode & RES_PRF_REPLY),
(stdout, ";; not our server:\n"),
- ans);
+ ans, resplen);
goto wait;
}
#endif
@@ -640,7 +648,7 @@ res_send(buf, buflen, ans, anssiz)
DprintQ((_res.options & RES_DEBUG) ||
(_res.pfcode & RES_PRF_REPLY),
(stdout, ";; wrong query name:\n"),
- ans);
+ ans, resplen);
goto wait;
}
if (anhp->rcode == SERVFAIL ||
@@ -648,7 +656,7 @@ res_send(buf, buflen, ans, anssiz)
anhp->rcode == REFUSED) {
DprintQ(_res.options & RES_DEBUG,
(stdout, "server rejected query:\n"),
- ans);
+ ans, resplen);
badns |= (1 << ns);
_res_close();
/* don't retry if called from dig */
@@ -670,7 +678,7 @@ res_send(buf, buflen, ans, anssiz)
DprintQ((_res.options & RES_DEBUG) ||
(_res.pfcode & RES_PRF_REPLY),
(stdout, ";; got answer:\n"),
- ans);
+ ans, resplen);
/*
* If using virtual circuits, we assume that the first server
* is preferred over the rest (i.e. it is on the local
diff --git a/resolv/resolv.h b/resolv/resolv.h
index d62bdf8..af92be4 100644
--- a/resolv/resolv.h
+++ b/resolv/resolv.h
@@ -78,7 +78,7 @@
* is new enough to contain a certain feature.
*/
-#define __RES 19941130
+#define __RES 19950621
/*
* Resolver configuration file.
@@ -128,9 +128,9 @@ struct __res_state {
*/
#define RES_INIT 0x00000001 /* address initialized */
#define RES_DEBUG 0x00000002 /* print debug messages */
-#define RES_AAONLY 0x00000004 /* authoritative answers only */
+#define RES_AAONLY 0x00000004 /* authoritative answers only (!IMPL)*/
#define RES_USEVC 0x00000008 /* use virtual circuit */
-#define RES_PRIMARY 0x00000010 /* query primary server only */
+#define RES_PRIMARY 0x00000010 /* query primary server only (!IMPL) */
#define RES_IGNTC 0x00000020 /* ignore trucation errors */
#define RES_RECURSE 0x00000040 /* recursion desired */
#define RES_DEFNAMES 0x00000080 /* use default domain name */
@@ -138,6 +138,7 @@ struct __res_state {
#define RES_DNSRCH 0x00000200 /* search up local domain tree */
#define RES_INSECURE1 0x00000400 /* type 1 security disabled */
#define RES_INSECURE2 0x00000800 /* type 2 security disabled */
+#define RES_NOALIASES 0x00001000 /* shuts off HOSTALIASES feature */
#define RES_DEFAULT (RES_RECURSE | RES_DEFNAMES | RES_DNSRCH)
@@ -196,6 +197,7 @@ extern struct __res_state _res;
#define p_fqname __p_fqname
#define p_rr __p_rr
#define p_option __p_option
+#define res_randomid __res_randomid
#define res_isourserver __res_isourserver
#define res_nameinquery __res_nameinquery
#define res_queriesmatch __res_queriesmatch
@@ -220,6 +222,7 @@ int dn_comp __P((const char *, u_char *, int, u_char **, u_char **));
int dn_expand __P((const u_char *, const u_char *, const u_char *,
char *, int));
int res_init __P((void));
+u_int16_t res_randomid __P((void));
int res_query __P((const char *, int, int, u_char *, int));
int res_search __P((const char *, int, int, u_char *, int));
int res_querydomain __P((const char *, const char *, int, int,
diff --git a/resolv/sethostent.c b/resolv/sethostent.c
index 709b518..e7a59dd 100644
--- a/resolv/sethostent.c
+++ b/resolv/sethostent.c
@@ -1,9 +1,7 @@
/*
- * ++Copyright++ 1985, 1993
- * -
* Copyright (c) 1985, 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:
@@ -14,12 +12,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
@@ -31,26 +29,6 @@
* 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)
@@ -64,10 +42,14 @@ static char rcsid[] = "$Id$";
#include <netdb.h>
#include <resolv.h>
+void _res_close __P((void));
+
void
sethostent(stayopen)
int stayopen;
{
+ if ((_res.options & RES_INIT) == 0 && res_init() == -1)
+ return;
if (stayopen)
_res.options |= RES_STAYOPEN | RES_USEVC;
}