Merge the 4.9.3-rel code into the res_* parts. The gethostXXXbyYYY

parts are not quite so simple..
This commit is contained in:
Peter Wemm 1996-01-07 09:15:02 +00:00
parent 0c83bb499c
commit ab83cd2d54
7 changed files with 159 additions and 181 deletions

View File

@ -9,8 +9,8 @@ SRCS+= gethostbydns.c gethostbyht.c gethostbynis.c gethostnamadr.c \
getservbyport.c getservent.c herror.c inet_addr.c inet_lnaof.c \ getservbyport.c getservent.c herror.c inet_addr.c inet_lnaof.c \
inet_makeaddr.c inet_netof.c inet_network.c inet_ntoa.c \ inet_makeaddr.c inet_netof.c inet_network.c inet_ntoa.c \
iso_addr.c linkaddr.c ns_addr.c ns_ntoa.c rcmd.c recv.c res_comp.c \ iso_addr.c linkaddr.c ns_addr.c ns_ntoa.c rcmd.c recv.c res_comp.c \
res_debug.c res_init.c res_mkquery.c res_query.c res_send.c \ res_data.c res_debug.c res_init.c res_mkquery.c res_query.c \
send.c ether_addr.c res_send.c send.c ether_addr.c
# machine-dependent net sources # machine-dependent net sources
.include "${.CURDIR}/${MACHINE}/net/Makefile.inc" .include "${.CURDIR}/${MACHINE}/net/Makefile.inc"

View File

@ -53,7 +53,7 @@
#if defined(LIBC_SCCS) && !defined(lint) #if defined(LIBC_SCCS) && !defined(lint)
static char sccsid[] = "@(#)res_comp.c 8.1 (Berkeley) 6/4/93"; static char sccsid[] = "@(#)res_comp.c 8.1 (Berkeley) 6/4/93";
static char rcsid[] = "$Id: res_comp.c,v 1.2 1994/09/25 02:12:32 pst Exp $"; static char rcsid[] = "$Id: res_comp.c,v 1.3 1995/05/30 05:40:54 rgrimes Exp $";
#endif /* LIBC_SCCS and not lint */ #endif /* LIBC_SCCS and not lint */
#include <sys/param.h> #include <sys/param.h>
@ -95,7 +95,7 @@ dn_expand(msg, eomorig, comp_dn, exp_dn, length)
/* /*
* fetch next label in domain name * fetch next label in domain name
*/ */
while ((n = *cp++)) { while (n = *cp++) {
/* /*
* Check for indirection * Check for indirection
*/ */
@ -110,14 +110,14 @@ dn_expand(msg, eomorig, comp_dn, exp_dn, length)
return (-1); return (-1);
checked += n + 1; checked += n + 1;
while (--n >= 0) { while (--n >= 0) {
if ((c = *cp++) == '.') { if (((c = *cp++) == '.') || (c == '\\')) {
if (dn + n + 2 >= eom) if (dn + n + 2 >= eom)
return (-1); return (-1);
*dn++ = '\\'; *dn++ = '\\';
} }
*dn++ = c; *dn++ = c;
if (cp >= eomorig) /* out of range */ if (cp >= eomorig) /* out of range */
return(-1); return (-1);
} }
break; break;
@ -126,7 +126,7 @@ dn_expand(msg, eomorig, comp_dn, exp_dn, length)
len = cp - comp_dn + 1; len = cp - comp_dn + 1;
cp = msg + (((n & 0x3f) << 8) | (*cp & 0xff)); cp = msg + (((n & 0x3f) << 8) | (*cp & 0xff));
if (cp < msg || cp >= eomorig) /* out of range */ if (cp < msg || cp >= eomorig) /* out of range */
return(-1); return (-1);
checked += 2; checked += 2;
/* /*
* Check for loops in the compressed name; * Check for loops in the compressed name;
@ -262,12 +262,12 @@ __dn_skipname(comp_dn, eom)
cp++; cp++;
break; break;
default: /* illegal type */ default: /* illegal type */
return -1; return (-1);
} }
break; break;
} }
if (cp > eom) if (cp > eom)
return -1; return (-1);
return (cp - comp_dn); return (cp - comp_dn);
} }
@ -298,7 +298,7 @@ dn_find(exp_dn, msg, dnptrs, lastdnptr)
for (cpp = dnptrs; cpp < lastdnptr; cpp++) { for (cpp = dnptrs; cpp < lastdnptr; cpp++) {
dn = exp_dn; dn = exp_dn;
sp = cp = *cpp; sp = cp = *cpp;
while ((n = *cp++)) { while (n = *cp++) {
/* /*
* check for indirection * check for indirection
*/ */
@ -318,11 +318,12 @@ dn_find(exp_dn, msg, dnptrs, lastdnptr)
continue; continue;
goto next; goto next;
default: /* illegal type */
return (-1);
case INDIR_MASK: /* indirection */ case INDIR_MASK: /* indirection */
cp = msg + (((n & 0x3f) << 8) | *cp); cp = msg + (((n & 0x3f) << 8) | *cp);
break;
default: /* illegal type */
return (-1);
} }
} }
if (*dn == '\0') if (*dn == '\0')
@ -333,11 +334,7 @@ dn_find(exp_dn, msg, dnptrs, lastdnptr)
} }
/* /*
* Routines to insert/extract short/long's. Must account for byte * Routines to insert/extract short/long's.
* order and non-alignment problems. This code at least has the
* advantage of being portable.
*
* used by sendmail.
*/ */
u_int16_t u_int16_t

View File

@ -53,7 +53,7 @@
#if defined(LIBC_SCCS) && !defined(lint) #if defined(LIBC_SCCS) && !defined(lint)
static char sccsid[] = "@(#)res_debug.c 8.1 (Berkeley) 6/4/93"; static char sccsid[] = "@(#)res_debug.c 8.1 (Berkeley) 6/4/93";
static char rcsid[] = "$Id: res_debug.c,v 1.4 1995/08/20 20:02:48 peter Exp $"; static char rcsid[] = "$Id: res_debug.c,v 1.5 1995/08/21 09:15:34 bde Exp $";
#endif /* LIBC_SCCS and not lint */ #endif /* LIBC_SCCS and not lint */
#include <sys/param.h> #include <sys/param.h>
@ -63,49 +63,14 @@ static char rcsid[] = "$Id: res_debug.c,v 1.4 1995/08/20 20:02:48 peter Exp $";
#include <arpa/nameser.h> #include <arpa/nameser.h>
#include <stdio.h> #include <stdio.h>
#include <netdb.h>
#include <resolv.h> #include <resolv.h>
#include <string.h> #include <string.h>
#include <netdb.h>
#include "res_config.h" #include "res_config.h"
const char *_res_opcodes[] = { extern const char *_res_opcodes[];
"QUERY", extern const char *_res_resultcodes[];
"IQUERY",
"CQUERYM",
"CQUERYU", /* experimental */
"NOTIFY", /* experimental */
"5",
"6",
"7",
"8",
"UPDATEA",
"UPDATED",
"UPDATEDA",
"UPDATEM",
"UPDATEMA",
"ZONEINIT",
"ZONEREF",
};
const char *_res_resultcodes[] = {
"NOERROR",
"FORMERR",
"SERVFAIL",
"NXDOMAIN",
"NOTIMP",
"REFUSED",
"6",
"7",
"8",
"9",
"10",
"11",
"12",
"13",
"14",
"NOCHANGE",
};
/* XXX: we should use getservbyport() instead. */ /* XXX: we should use getservbyport() instead. */
static const char * static const char *
@ -203,13 +168,13 @@ do_rrset(msg, len, cp, cnt, pflag, file, hs)
* Print answer records. * Print answer records.
*/ */
sflag = (_res.pfcode & pflag); sflag = (_res.pfcode & pflag);
if ((n = ntohs(cnt))) { if (n = ntohs(cnt)) {
if ((!_res.pfcode) || if ((!_res.pfcode) ||
((sflag) && (_res.pfcode & RES_PRF_HEAD1))) ((sflag) && (_res.pfcode & RES_PRF_HEAD1)))
fprintf(file, hs); fprintf(file, hs);
while (--n >= 0) { while (--n >= 0) {
if ((!_res.pfcode) || sflag) { if ((!_res.pfcode) || sflag) {
cp = p_rr(cp, msg, file); cp = p_rr(cp, msg, file);
} else { } else {
unsigned int dlen; unsigned int dlen;
cp += __dn_skipname(cp, cp + MAXCDNAME); cp += __dn_skipname(cp, cp + MAXCDNAME);
@ -290,9 +255,10 @@ __fp_nquery(msg, len, file)
ntohs(hp->id)); ntohs(hp->id));
putc('\n', file); putc('\n', file);
} }
putc(';', file); if ((!_res.pfcode) || (_res.pfcode & RES_PRF_HEADX))
putc(';', file);
if ((!_res.pfcode) || (_res.pfcode & RES_PRF_HEAD2)) { if ((!_res.pfcode) || (_res.pfcode & RES_PRF_HEAD2)) {
fprintf(file,"; flags:"); fprintf(file, "; flags:");
if (hp->qr) if (hp->qr)
fprintf(file, " qr"); fprintf(file, " qr");
if (hp->aa) if (hp->aa)
@ -310,7 +276,7 @@ __fp_nquery(msg, len, file)
fprintf(file, ", Auth: %d", ntohs(hp->nscount)); fprintf(file, ", Auth: %d", ntohs(hp->nscount));
fprintf(file, ", Addit: %d", ntohs(hp->arcount)); fprintf(file, ", Addit: %d", ntohs(hp->arcount));
} }
if ((!_res.pfcode) || (_res.pfcode & if ((!_res.pfcode) || (_res.pfcode &
(RES_PRF_HEADX | RES_PRF_HEAD2 | RES_PRF_HEAD1))) { (RES_PRF_HEADX | RES_PRF_HEAD2 | RES_PRF_HEAD1))) {
putc('\n',file); putc('\n',file);
} }
@ -319,11 +285,23 @@ __fp_nquery(msg, len, file)
*/ */
if (n = ntohs(hp->qdcount)) { if (n = ntohs(hp->qdcount)) {
if ((!_res.pfcode) || (_res.pfcode & RES_PRF_QUES)) if ((!_res.pfcode) || (_res.pfcode & RES_PRF_QUES))
fprintf(file,";; QUESTIONS:\n"); fprintf(file, ";; QUESTIONS:\n");
while (--n >= 0) { while (--n >= 0) {
fprintf(file,";;\t"); if ((!_res.pfcode) || (_res.pfcode & RES_PRF_QUES))
fprintf(file, ";;\t");
TruncTest(cp); TruncTest(cp);
cp = p_cdnname(cp, msg, len, file); if ((!_res.pfcode) || (_res.pfcode & RES_PRF_QUES))
cp = p_cdnname(cp, msg, len, file);
else {
int n;
char name[MAXDNAME];
if ((n = dn_expand(msg, msg+len, cp, name,
sizeof name)) < 0)
cp = NULL;
else
cp += n;
}
ErrorTest(cp); ErrorTest(cp);
TruncTest(cp); TruncTest(cp);
if ((!_res.pfcode) || (_res.pfcode & RES_PRF_QUES)) if ((!_res.pfcode) || (_res.pfcode & RES_PRF_QUES))
@ -335,7 +313,8 @@ __fp_nquery(msg, len, file)
fprintf(file, ", class = %s\n", fprintf(file, ", class = %s\n",
__p_class(_getshort((u_char*)cp))); __p_class(_getshort((u_char*)cp)));
cp += INT16SZ; cp += INT16SZ;
putc('\n', file); if ((!_res.pfcode) || (_res.pfcode & RES_PRF_QUES))
putc('\n', file);
} }
} }
/* /*
@ -471,7 +450,7 @@ __p_rr(cp, msg, file)
case C_HS: case C_HS:
bcopy(cp, (char *)&inaddr, INADDRSZ); bcopy(cp, (char *)&inaddr, INADDRSZ);
if (dlen == 4) { if (dlen == 4) {
fprintf(file,"\t%s", inet_ntoa(inaddr)); fprintf(file, "\t%s", inet_ntoa(inaddr));
cp += dlen; cp += dlen;
} else if (dlen == 7) { } else if (dlen == 7) {
char *address; char *address;
@ -507,11 +486,11 @@ __p_rr(cp, msg, file)
case T_ISDN: case T_ISDN:
cp2 = cp + dlen; cp2 = cp + dlen;
if (n = *cp++) { if (n = *cp++) {
fprintf(file,"\t%.*s", n, cp); fprintf(file, "\t%.*s", n, cp);
cp += n; cp += n;
} }
if ((cp < cp2) && (n = *cp++)) { if ((cp < cp2) && (n = *cp++)) {
fprintf(file,"\t%.*s", n, cp); fprintf(file, "\t%.*s", n, cp);
cp += n; cp += n;
} else if (type == T_HINFO) } else if (type == T_HINFO)
fprintf(file, "\n;; *** Warning *** OS-type missing"); fprintf(file, "\n;; *** Warning *** OS-type missing");
@ -544,7 +523,7 @@ __p_rr(cp, msg, file)
case T_MX: case T_MX:
case T_AFSDB: case T_AFSDB:
case T_RT: case T_RT:
fprintf(file,"\t%d ", _getshort((u_char*)cp)); fprintf(file, "\t%d ", _getshort((u_char*)cp));
cp += INT16SZ; cp += INT16SZ;
if ((cp = p_fqname(cp, msg, file)) == NULL) if ((cp = p_fqname(cp, msg, file)) == NULL)
return (NULL); return (NULL);
@ -560,7 +539,7 @@ __p_rr(cp, msg, file)
return (NULL); return (NULL);
break; break;
case T_TXT: case T_TXT:
case T_X25: case T_X25:
(void) fputs("\t\"", file); (void) fputs("\t\"", file);
cp2 = cp1 + dlen; cp2 = cp1 + dlen;
@ -575,7 +554,7 @@ __p_rr(cp, msg, file)
} }
} }
putc('"', file); putc('"', file);
break; break;
case T_NSAP: case T_NSAP:
isoa.isoa_len = dlen; isoa.isoa_len = dlen;
@ -605,7 +584,7 @@ __p_rr(cp, msg, file)
case T_UID: case T_UID:
case T_GID: case T_GID:
if (dlen == 4) { if (dlen == 4) {
fprintf(file,"\t%u", _getlong((u_char*)cp)); fprintf(file, "\t%u", _getlong((u_char*)cp));
cp += INT32SZ; cp += INT32SZ;
} }
break; break;
@ -624,7 +603,7 @@ __p_rr(cp, msg, file)
while (cp < cp1 + dlen) { while (cp < cp1 + dlen) {
c = *cp++; c = *cp++;
do { do {
if (c & 0200) { if (c & 0200) {
if (lcnt == 0) { if (lcnt == 0) {
fputs("\n\t\t\t", file); fputs("\n\t\t\t", file);
lcnt = 5; lcnt = 5;
@ -633,7 +612,7 @@ __p_rr(cp, msg, file)
putc(' ', file); putc(' ', file);
lcnt--; lcnt--;
} }
c <<= 1; c <<= 1;
} while (++n & 07); } while (++n & 07);
} }
putc(')', file); putc(')', file);
@ -657,7 +636,7 @@ __p_rr(cp, msg, file)
#endif /* ALLOW_T_UNSPEC */ #endif /* ALLOW_T_UNSPEC */
default: default:
fprintf(file,"\t?%d?", type); fprintf(file, "\t?%d?", type);
cp += dlen; cp += dlen;
} }
#if 0 #if 0
@ -666,7 +645,7 @@ __p_rr(cp, msg, file)
putc('\n', file); putc('\n', file);
#endif #endif
if (cp - cp1 != dlen) { if (cp - cp1 != dlen) {
fprintf(file,";; packet size error (found %d, dlen was %d)\n", fprintf(file, ";; packet size error (found %d, dlen was %d)\n",
cp - cp1, dlen); cp - cp1, dlen);
cp = NULL; cp = NULL;
} }

View File

@ -53,7 +53,7 @@
#if defined(LIBC_SCCS) && !defined(lint) #if defined(LIBC_SCCS) && !defined(lint)
static char sccsid[] = "@(#)res_init.c 8.1 (Berkeley) 6/7/93"; static char sccsid[] = "@(#)res_init.c 8.1 (Berkeley) 6/7/93";
static char rcsid[] = "$Id: res_init.c,v 1.5 1995/08/20 20:02:52 peter Exp $"; static char rcsid[] = "$Id: res_init.c,v 1.6 1995/08/21 09:15:36 bde Exp $";
#endif /* LIBC_SCCS and not lint */ #endif /* LIBC_SCCS and not lint */
#include <sys/param.h> #include <sys/param.h>
@ -96,7 +96,7 @@ struct __res_state _res;
* since it was noted that INADDR_ANY actually meant ``the first interface * since it was noted that INADDR_ANY actually meant ``the first interface
* you "ifconfig"'d at boot time'' and if this was a SLIP or PPP interface, * you "ifconfig"'d at boot time'' and if this was a SLIP or PPP interface,
* it had to be "up" in order for you to reach your own name server. It * it had to be "up" in order for you to reach your own name server. It
* was later decided that since the recommended practice is to always * was later decided that since the recommended practice is to always
* install local static routes through 127.0.0.1 for all your network * install local static routes through 127.0.0.1 for all your network
* interfaces, that we could solve this problem without a code change. * interfaces, that we could solve this problem without a code change.
* *
@ -223,8 +223,7 @@ res_init()
cp++; cp++;
if ((*cp == '\0') || (*cp == '\n')) if ((*cp == '\0') || (*cp == '\n'))
continue; continue;
(void)strncpy(_res.defdname, cp, strncpy(_res.defdname, cp, sizeof(_res.defdname) - 1);
sizeof(_res.defdname) - 1);
if ((cp = strpbrk(_res.defdname, " \t\n")) != NULL) if ((cp = strpbrk(_res.defdname, " \t\n")) != NULL)
*cp = '\0'; *cp = '\0';
havesearch = 0; havesearch = 0;
@ -239,8 +238,7 @@ res_init()
cp++; cp++;
if ((*cp == '\0') || (*cp == '\n')) if ((*cp == '\0') || (*cp == '\n'))
continue; continue;
(void)strncpy(_res.defdname, cp, strncpy(_res.defdname, cp, sizeof(_res.defdname) - 1);
sizeof(_res.defdname) - 1);
if ((cp = strchr(_res.defdname, '\n')) != NULL) if ((cp = strchr(_res.defdname, '\n')) != NULL)
*cp = '\0'; *cp = '\0';
/* /*
@ -269,7 +267,7 @@ res_init()
} }
/* read nameservers to query */ /* read nameservers to query */
if (MATCH(buf, "nameserver") && nserv < MAXNS) { if (MATCH(buf, "nameserver") && nserv < MAXNS) {
struct in_addr a; struct in_addr a;
cp = buf + sizeof("nameserver") - 1; cp = buf + sizeof("nameserver") - 1;
while (*cp == ' ' || *cp == '\t') while (*cp == ' ' || *cp == '\t')
@ -295,7 +293,7 @@ res_init()
break; break;
net = cp; net = cp;
while (*cp && !ISSORTMASK(*cp) && *cp != ';' && while (*cp && !ISSORTMASK(*cp) && *cp != ';' &&
isascii(*cp) && !isspace(*cp)) isascii(*cp) && !isspace(*cp))
cp++; cp++;
n = *cp; n = *cp;
*cp = 0; *cp = 0;
@ -312,11 +310,11 @@ res_init()
if (inet_aton(net, &a)) { if (inet_aton(net, &a)) {
_res.sort_list[nsort].mask = a.s_addr; _res.sort_list[nsort].mask = a.s_addr;
} else { } else {
_res.sort_list[nsort].mask = _res.sort_list[nsort].mask =
net_mask(_res.sort_list[nsort].addr); net_mask(_res.sort_list[nsort].addr);
} }
} else { } else {
_res.sort_list[nsort].mask = _res.sort_list[nsort].mask =
net_mask(_res.sort_list[nsort].addr); net_mask(_res.sort_list[nsort].addr);
} }
nsort++; nsort++;
@ -331,7 +329,7 @@ res_init()
continue; continue;
} }
} }
if (nserv > 1) if (nserv > 1)
_res.nscount = nserv; _res.nscount = nserv;
#ifdef RESOLVSORT #ifdef RESOLVSORT
_res.nsort = nsort; _res.nsort = nsort;
@ -351,7 +349,7 @@ res_init()
#ifndef RFC1535 #ifndef RFC1535
dots = 0; dots = 0;
for (cp = _res.defdname; *cp; cp++) for (cp = _res.defdname; *cp; cp++)
dots += (*cp == '.'); dots += (*cp == '.');
cp = _res.defdname; cp = _res.defdname;
@ -371,7 +369,7 @@ res_init()
printf(";;\t..END..\n"); printf(";;\t..END..\n");
} }
#endif /* DEBUG */ #endif /* DEBUG */
#endif /*!RFC1535*/ #endif /* !RFC1535 */
} }
if ((cp = getenv("RES_OPTIONS")) != NULL) if ((cp = getenv("RES_OPTIONS")) != NULL)
@ -397,7 +395,7 @@ res_setoptions(options, source)
while (*cp == ' ' || *cp == '\t') while (*cp == ' ' || *cp == '\t')
cp++; cp++;
/* search for and process individual options */ /* search for and process individual options */
if (!strncmp(cp, "ndots:", sizeof("ndots:")-1)) { if (!strncmp(cp, "ndots:", sizeof("ndots:") - 1)) {
i = atoi(cp + sizeof("ndots:") - 1); i = atoi(cp + sizeof("ndots:") - 1);
if (i <= RES_MAXNDOTS) if (i <= RES_MAXNDOTS)
_res.ndots = i; _res.ndots = i;
@ -407,7 +405,7 @@ res_setoptions(options, source)
if (_res.options & RES_DEBUG) if (_res.options & RES_DEBUG)
printf(";;\tndots=%d\n", _res.ndots); printf(";;\tndots=%d\n", _res.ndots);
#endif #endif
} else if (!strncmp(cp, "debug", sizeof("debug")-1)) { } else if (!strncmp(cp, "debug", sizeof("debug") - 1)) {
#ifdef DEBUG #ifdef DEBUG
if (!(_res.options & RES_DEBUG)) { if (!(_res.options & RES_DEBUG)) {
printf(";; res_setoptions(\"%s\", \"%s\")..\n", printf(";; res_setoptions(\"%s\", \"%s\")..\n",
@ -431,12 +429,12 @@ static u_int32_t
net_mask(in) /* XXX - should really use system's version of this */ net_mask(in) /* XXX - should really use system's version of this */
struct in_addr in; struct in_addr in;
{ {
register u_int32_t i = ntohl(in.s_addr); register u_int32_t i = ntohl(in.s_addr);
if (IN_CLASSA(i)) if (IN_CLASSA(i))
return (htonl(IN_CLASSA_NET)); return (htonl(IN_CLASSA_NET));
else if (IN_CLASSB(i)) else if (IN_CLASSB(i))
return (htonl(IN_CLASSB_NET)); return (htonl(IN_CLASSB_NET));
return (htonl(IN_CLASSC_NET)); return (htonl(IN_CLASSC_NET));
} }
#endif #endif

View File

@ -53,7 +53,7 @@
#if defined(LIBC_SCCS) && !defined(lint) #if defined(LIBC_SCCS) && !defined(lint)
static char sccsid[] = "@(#)res_mkquery.c 8.1 (Berkeley) 6/4/93"; static char sccsid[] = "@(#)res_mkquery.c 8.1 (Berkeley) 6/4/93";
static char rcsid[] = "$Id: res_mkquery.c,v 1.5 1995/08/20 20:02:56 peter Exp $"; static char rcsid[] = "$Id: res_mkquery.c,v 1.6 1995/08/21 09:15:37 bde Exp $";
#endif /* LIBC_SCCS and not lint */ #endif /* LIBC_SCCS and not lint */
#include <sys/param.h> #include <sys/param.h>
@ -61,9 +61,9 @@ static char rcsid[] = "$Id: res_mkquery.c,v 1.5 1995/08/20 20:02:56 peter Exp $"
#include <arpa/nameser.h> #include <arpa/nameser.h>
#include <stdio.h> #include <stdio.h>
#include <netdb.h>
#include <resolv.h> #include <resolv.h>
#include <string.h> #include <string.h>
#include <netdb.h>
#include "res_config.h" #include "res_config.h"
@ -103,7 +103,7 @@ res_mkquery(op, dname, class, type, data, datalen, newrr_in, buf, buflen)
* Initialize header fields. * Initialize header fields.
*/ */
if ((buf == NULL) || (buflen < HFIXEDSZ)) if ((buf == NULL) || (buflen < HFIXEDSZ))
return(-1); return (-1);
bzero(buf, HFIXEDSZ); bzero(buf, HFIXEDSZ);
hp = (HEADER *) buf; hp = (HEADER *) buf;
hp->id = htons(++_res.id); hp->id = htons(++_res.id);
@ -123,7 +123,7 @@ res_mkquery(op, dname, class, type, data, datalen, newrr_in, buf, buflen)
case QUERY: /*FALLTHROUGH*/ case QUERY: /*FALLTHROUGH*/
case NS_NOTIFY_OP: case NS_NOTIFY_OP:
if ((buflen -= QFIXEDSZ) < 0) if ((buflen -= QFIXEDSZ) < 0)
return(-1); return (-1);
if ((n = dn_comp(dname, cp, buflen, dnptrs, lastdnptr)) < 0) if ((n = dn_comp(dname, cp, buflen, dnptrs, lastdnptr)) < 0)
return (-1); return (-1);
cp += n; cp += n;
@ -197,13 +197,13 @@ res_mkquery(op, dname, class, type, data, datalen, newrr_in, buf, buflen)
return (-1); return (-1);
cp += n; cp += n;
__putshort(type, cp); __putshort(type, cp);
cp += INT16SZ; cp += INT16SZ;
__putshort(class, cp); __putshort(class, cp);
cp += INT16SZ; cp += INT16SZ;
__putlong(0, cp); __putlong(0, cp);
cp += INT32SZ; cp += INT32SZ;
__putshort(datalen, cp); __putshort(datalen, cp);
cp += INT16SZ; cp += INT16SZ;
if (datalen) { if (datalen) {
bcopy(data, cp, datalen); bcopy(data, cp, datalen);
cp += datalen; cp += datalen;
@ -220,13 +220,13 @@ res_mkquery(op, dname, class, type, data, datalen, newrr_in, buf, buflen)
return (-1); return (-1);
cp += n; cp += n;
__putshort(newrr->r_type, cp); __putshort(newrr->r_type, cp);
cp += INT16SZ; cp += INT16SZ;
__putshort(newrr->r_class, cp); __putshort(newrr->r_class, cp);
cp += INT16SZ; cp += INT16SZ;
__putlong(0, cp); __putlong(0, cp);
cp += INT32SZ; cp += INT32SZ;
__putshort(newrr->r_size, cp); __putshort(newrr->r_size, cp);
cp += INT16SZ; cp += INT16SZ;
if (newrr->r_size) { if (newrr->r_size) {
bcopy(newrr->r_data, cp, newrr->r_size); bcopy(newrr->r_data, cp, newrr->r_size);
cp += newrr->r_size; cp += newrr->r_size;

View File

@ -53,7 +53,7 @@
#if defined(LIBC_SCCS) && !defined(lint) #if defined(LIBC_SCCS) && !defined(lint)
static char sccsid[] = "@(#)res_query.c 8.1 (Berkeley) 6/4/93"; static char sccsid[] = "@(#)res_query.c 8.1 (Berkeley) 6/4/93";
static char rcsid[] = "$Id: res_query.c,v 1.5 1995/08/20 20:03:00 peter Exp $"; static char rcsid[] = "$Id: res_query.c,v 1.6 1995/08/21 09:15:39 bde Exp $";
#endif /* LIBC_SCCS and not lint */ #endif /* LIBC_SCCS and not lint */
#include <sys/param.h> #include <sys/param.h>
@ -139,21 +139,21 @@ res_query(name, class, type, answer, anslen)
ntohs(hp->ancount)); ntohs(hp->ancount));
#endif #endif
switch (hp->rcode) { switch (hp->rcode) {
case NXDOMAIN: case NXDOMAIN:
h_errno = HOST_NOT_FOUND; h_errno = HOST_NOT_FOUND;
break; break;
case SERVFAIL: case SERVFAIL:
h_errno = TRY_AGAIN; h_errno = TRY_AGAIN;
break; break;
case NOERROR: case NOERROR:
h_errno = NO_DATA; h_errno = NO_DATA;
break; break;
case FORMERR: case FORMERR:
case NOTIMP: case NOTIMP:
case REFUSED: case REFUSED:
default: default:
h_errno = NO_RECOVERY; h_errno = NO_RECOVERY;
break; break;
} }
return (-1); return (-1);
} }
@ -186,7 +186,7 @@ res_search(name, class, type, answer, anslen)
errno = 0; errno = 0;
h_errno = HOST_NOT_FOUND; /* default, if we never query */ h_errno = HOST_NOT_FOUND; /* default, if we never query */
dots = 0; dots = 0;
for (cp = name; *cp; cp++) for (cp = name; *cp; cp++)
dots += (*cp == '.'); dots += (*cp == '.');
trailing_dot = 0; trailing_dot = 0;
if (cp > name && *--cp == '.') if (cp > name && *--cp == '.')

View File

@ -53,7 +53,7 @@
#if defined(LIBC_SCCS) && !defined(lint) #if defined(LIBC_SCCS) && !defined(lint)
static char sccsid[] = "@(#)res_send.c 8.1 (Berkeley) 6/4/93"; static char sccsid[] = "@(#)res_send.c 8.1 (Berkeley) 6/4/93";
static char rcsid[] = "$Id: res_send.c,v 1.5 1995/08/20 20:03:06 peter Exp $"; static char rcsid[] = "$Id: res_send.c,v 1.6 1995/08/21 09:15:40 bde Exp $";
#endif /* LIBC_SCCS and not lint */ #endif /* LIBC_SCCS and not lint */
/* change this to "0" /* change this to "0"
@ -102,38 +102,38 @@ static int vc = 0; /* is the socket a virtual ciruit? */
fprintf args;\ fprintf args;\
__fp_nquery(query, size, stdout);\ __fp_nquery(query, size, stdout);\
} else {} } else {}
static void static void
Aerror(file, string, error, address) Aerror(file, string, error, address)
FILE *file; FILE *file;
char *string; char *string;
int error; int error;
struct sockaddr_in address; struct sockaddr_in address;
{ {
int save = errno; int save = errno;
if (_res.options & RES_DEBUG) { if (_res.options & RES_DEBUG) {
fprintf(file, "res_send: %s ([%s].%u): %s\n", fprintf(file, "res_send: %s ([%s].%u): %s\n",
string, string,
inet_ntoa(address.sin_addr), inet_ntoa(address.sin_addr),
ntohs(address.sin_port), ntohs(address.sin_port),
strerror(error)); strerror(error));
}
errno = save;
} }
errno = save; static void
} Perror(file, string, error)
static void FILE *file;
Perror(file, string, error) char *string;
FILE *file; int error;
char *string; {
int error; int save = errno;
{
int save = errno;
if (_res.options & RES_DEBUG) { if (_res.options & RES_DEBUG) {
fprintf(file, "res_send: %s: %s\n", fprintf(file, "res_send: %s: %s\n",
string, strerror(error)); string, strerror(error));
}
errno = save;
} }
errno = save;
}
#endif #endif
static res_send_qhook Qhook = NULL; static res_send_qhook Qhook = NULL;
@ -214,7 +214,7 @@ res_nameinquery(name, type, class, buf, eom)
if (n < 0) if (n < 0)
return (-1); return (-1);
cp += n; cp += n;
ttype = _getshort(cp); cp += INT16SZ; ttype = _getshort(cp); cp += INT16SZ;
tclass = _getshort(cp); cp += INT16SZ; tclass = _getshort(cp); cp += INT16SZ;
if (ttype == type && if (ttype == type &&
tclass == class && tclass == class &&
@ -263,20 +263,20 @@ res_queriesmatch(buf1, eom1, buf2, eom2)
int int
res_send(buf, buflen, ans, anssiz) res_send(buf, buflen, ans, anssiz)
const u_char *buf; const u_char *buf;
int buflen; int buflen;
u_char *ans; u_char *ans;
int anssiz; int anssiz;
{ {
HEADER *hp = (HEADER *) buf; HEADER *hp = (HEADER *) buf;
HEADER *anhp = (HEADER *) ans; HEADER *anhp = (HEADER *) ans;
int gotsomewhere, connreset, terrno, try, v_circuit, resplen, ns; int gotsomewhere, connreset, terrno, try, v_circuit, resplen, ns;
register int n; register int n;
u_int badns; /* XXX NSMAX can't exceed #/bits in this var */ u_int badns; /* XXX NSMAX can't exceed #/bits in this var */
if ((_res.options & RES_INIT) == 0 && res_init() == -1) { if ((_res.options & RES_INIT) == 0 && res_init() == -1) {
/* errno should have been set by res_init() in this case. */ /* errno should have been set by res_init() in this case. */
return (-1); return (-1);
} }
DprintQ((_res.options & RES_DEBUG) || (_res.pfcode & RES_PRF_QUERY), DprintQ((_res.options & RES_DEBUG) || (_res.pfcode & RES_PRF_QUERY),
(stdout, ";; res_send()\n"), buf, buflen); (stdout, ";; res_send()\n"), buf, buflen);
@ -293,7 +293,7 @@ res_send(buf, buflen, ans, anssiz)
for (ns = 0; ns < _res.nscount; ns++) { for (ns = 0; ns < _res.nscount; ns++) {
struct sockaddr_in *nsap = &_res.nsaddr_list[ns]; struct sockaddr_in *nsap = &_res.nsaddr_list[ns];
same_ns: same_ns:
if (badns & (1<<ns)) { if (badns & (1 << ns)) {
_res_close(); _res_close();
goto next_ns; goto next_ns;
} }
@ -330,13 +330,13 @@ res_send(buf, buflen, ans, anssiz)
Dprint(_res.options & RES_DEBUG, Dprint(_res.options & RES_DEBUG,
(stdout, ";; Querying server (# %d) address = %s\n", (stdout, ";; Querying server (# %d) address = %s\n",
ns+1, inet_ntoa(nsap->sin_addr))); ns + 1, inet_ntoa(nsap->sin_addr)));
if (v_circuit) { if (v_circuit) {
int truncated; int truncated;
struct iovec iov[2]; struct iovec iov[2];
u_short len; u_short len;
u_char *cp; u_char *cp;
/* /*
* Use virtual circuit; * Use virtual circuit;
@ -360,7 +360,7 @@ res_send(buf, buflen, ans, anssiz)
terrno = errno; terrno = errno;
Aerror(stderr, "connect/vc", Aerror(stderr, "connect/vc",
errno, *nsap); errno, *nsap);
badns |= (1<<ns); badns |= (1 << ns);
_res_close(); _res_close();
goto next_ns; goto next_ns;
} }
@ -377,7 +377,7 @@ res_send(buf, buflen, ans, anssiz)
if (writev(s, iov, 2) != (INT16SZ + buflen)) { if (writev(s, iov, 2) != (INT16SZ + buflen)) {
terrno = errno; terrno = errno;
Perror(stderr, "write failed", errno); Perror(stderr, "write failed", errno);
badns |= (1<<ns); badns |= (1 << ns);
_res_close(); _res_close();
goto next_ns; goto next_ns;
} }
@ -456,10 +456,10 @@ res_send(buf, buflen, ans, anssiz)
/* /*
* Use datagrams. * Use datagrams.
*/ */
struct timeval timeout; struct timeval timeout;
fd_set dsmask; fd_set dsmask;
struct sockaddr_in from; struct sockaddr_in from;
int fromlen; int fromlen;
if ((s < 0) || vc) { if ((s < 0) || vc) {
if (vc) if (vc)
@ -499,7 +499,7 @@ res_send(buf, buflen, ans, anssiz)
Aerror(stderr, Aerror(stderr,
"connect(dg)", "connect(dg)",
errno, *nsap); errno, *nsap);
badns |= (1<<ns); badns |= (1 << ns);
_res_close(); _res_close();
goto next_ns; goto next_ns;
} }
@ -507,7 +507,7 @@ res_send(buf, buflen, ans, anssiz)
} }
if (send(s, (char*)buf, buflen, 0) != buflen) { if (send(s, (char*)buf, buflen, 0) != buflen) {
Perror(stderr, "send", errno); Perror(stderr, "send", errno);
badns |= (1<<ns); badns |= (1 << ns);
_res_close(); _res_close();
goto next_ns; goto next_ns;
} }
@ -534,7 +534,7 @@ res_send(buf, buflen, ans, anssiz)
sizeof(struct sockaddr)) sizeof(struct sockaddr))
!= buflen) { != buflen) {
Aerror(stderr, "sendto", errno, *nsap); Aerror(stderr, "sendto", errno, *nsap);
badns |= (1<<ns); badns |= (1 << ns);
_res_close(); _res_close();
goto next_ns; goto next_ns;
} }
@ -608,7 +608,7 @@ res_send(buf, buflen, ans, anssiz)
#endif #endif
if (!(_res.options & RES_INSECURE2) && if (!(_res.options & RES_INSECURE2) &&
!res_queriesmatch(buf, buf + buflen, !res_queriesmatch(buf, buf + buflen,
ans, ans + anssiz)) { ans, ans + anssiz)) {
/* /*
* response contains wrong query? ignore it. * response contains wrong query? ignore it.
* XXX - potential security hazard could * XXX - potential security hazard could
@ -626,11 +626,11 @@ res_send(buf, buflen, ans, anssiz)
DprintQ(_res.options & RES_DEBUG, DprintQ(_res.options & RES_DEBUG,
(stdout, "server rejected query:\n"), (stdout, "server rejected query:\n"),
ans, resplen); ans, resplen);
badns |= (1<<ns); badns |= (1 << ns);
_res_close(); _res_close();
/* don't retry if called from dig */ /* don't retry if called from dig */
if (!_res.pfcode) if (!_res.pfcode)
goto next_ns; goto next_ns;
} }
if (!(_res.options & RES_IGNTC) && anhp->tc) { if (!(_res.options & RES_IGNTC) && anhp->tc) {
/* /*
@ -644,9 +644,13 @@ res_send(buf, buflen, ans, anssiz)
goto same_ns; goto same_ns;
} }
} /*if vc/dg*/ } /*if vc/dg*/
Dprint((_res.options & RES_DEBUG) ||
((_res.pfcode & RES_PRF_REPLY) &&
(_res.pfcode & RES_PRF_HEAD1)),
(stdout, ";; got answer:\n"));
DprintQ((_res.options & RES_DEBUG) || DprintQ((_res.options & RES_DEBUG) ||
(_res.pfcode & RES_PRF_REPLY), (_res.pfcode & RES_PRF_REPLY),
(stdout, ";; got answer:\n"), (stdout, ""),
ans, resplen); ans, resplen);
/* /*
* If using virtual circuits, we assume that the first server * If using virtual circuits, we assume that the first server