summaryrefslogtreecommitdiffstats
path: root/usr.bin/dig
diff options
context:
space:
mode:
Diffstat (limited to 'usr.bin/dig')
-rw-r--r--usr.bin/dig/Makefile11
-rw-r--r--usr.bin/dig/dig.112
-rw-r--r--usr.bin/dig/dig.c131
3 files changed, 74 insertions, 80 deletions
diff --git a/usr.bin/dig/Makefile b/usr.bin/dig/Makefile
new file mode 100644
index 0000000..dd4044d
--- /dev/null
+++ b/usr.bin/dig/Makefile
@@ -0,0 +1,11 @@
+# @(#)Makefile 8.1 (Berkeley) 6/6/93
+
+PROG= dig
+MAN1= dig.1
+SRCS= dig.c debug.c list.c send.c subr.c
+
+NSLOOKUP=${.CURDIR}/../../usr.sbin/nslookup
+CFLAGS+=-I${NSLOOKUP}
+.PATH: ${NSLOOKUP}
+
+.include <bsd.prog.mk>
diff --git a/usr.bin/dig/dig.1 b/usr.bin/dig/dig.1
index 3f97311..71e4374 100644
--- a/usr.bin/dig/dig.1
+++ b/usr.bin/dig/dig.1
@@ -1,4 +1,4 @@
-.\" $Id: dig.1,v 4.9.1.2 1993/09/08 00:00:49 vixie Exp $
+.\" $Id: dig.1,v 1.1.1.1 1994/09/22 21:33:31 pst Exp $
.\"
.\" ++Copyright++ 1993
.\" -
@@ -61,7 +61,7 @@
.\" Man page reformatted for this release by Andrew Cherenson
.\" (arc@sgi.com)
.\"
-.TH DIG @CMD_EXT_U@ "August 30, 1990"
+.TH DIG 1 "August 30, 1990"
.SH NAME
dig \- send domain name query packets to name servers
.SH SYNOPSIS
@@ -99,7 +99,7 @@ at your disposal somewhere, all that is required is that
/etc/resolv.conf be present and indicate where the default
name servers reside, so that \fIserver\fP itself can be
resolved. See
-.IR resolver (@FORMAT_EXT@)
+.IR resolver (5)
for information on /etc/resolv.conf.
(WARNING: Changing /etc/resolv.conf will affect
the standard resolver library and potentially several
@@ -324,7 +324,7 @@ end
(Note: \fIdig\fP always uses a value of 1 for num_servers.)
.SH DETAILS
\fIDig\fP once required a slightly modified version of the BIND
-.IR resolver (@LIB_NETWORK_EXT@)
+.IR resolver (3)
library. BIND's resolver has (as of BIND 4.9) been augmented to work
properly with \fIDig\fP. Essentially, \fIDig\fP is a straight-forward
(albeit not pretty) effort of parsing arguments and setting appropriate
@@ -345,7 +345,7 @@ Steve Hotz
hotz@isi.edu
.SH ACKNOWLEDGMENTS
\fIDig\fP uses functions from
-.IR nslookup (@SYS_OPS_EXT@)
+.IR nslookup (8)
authored by Andrew Cherenson.
.SH BUGS
\fIDig\fP has a serious case of "creeping featurism" -- the result of
@@ -361,4 +361,4 @@ batch mode. If it exits abnormally (and is not caught), the entire
batch aborts; when such an event is trapped, \fIdig\fP simply
continues with the next query.
.SH SEE ALSO
-@INDOT@named(@SYS_OPS_EXT@), resolver(@LIB_NETWORK_EXT@), resolver(@FORMAT_EXT@), nslookup(@SYS_OPS_EXT@)
+named(8), resolver(3), resolver(5), nslookup(8)
diff --git a/usr.bin/dig/dig.c b/usr.bin/dig/dig.c
index e6978a5..e88b5d5 100644
--- a/usr.bin/dig/dig.c
+++ b/usr.bin/dig/dig.c
@@ -1,5 +1,5 @@
#ifndef lint
-static char rcsid[] = "$Id: dig.c,v 8.4 1995/06/19 08:35:06 vixie Exp $";
+static char rcsid[] = "$Id: dig.c,v 1.3 1995/05/09 13:13:21 rgrimes Exp $";
#endif
/*
@@ -7,7 +7,7 @@ static char rcsid[] = "$Id: dig.c,v 8.4 1995/06/19 08:35:06 vixie Exp $";
* -
* Copyright (c) 1989
* 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:
@@ -23,7 +23,7 @@ static char rcsid[] = "$Id: dig.c,v 8.4 1995/06/19 08:35:06 vixie Exp $";
* 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
@@ -37,14 +37,14 @@ static char rcsid[] = "$Id: dig.c,v 8.4 1995/06/19 08:35:06 vixie Exp $";
* 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
@@ -89,7 +89,7 @@ static char rcsid[] = "$Id: dig.c,v 8.4 1995/06/19 08:35:06 vixie Exp $";
* in order to disclaim liability and warranty).
*
* Paul Vixie, Palo Alto, CA, April 1993
- ****************************************************************************
+ ****************************************************************************/
/*******************************************************************
** DiG -- Domain Information Groper **
@@ -157,14 +157,14 @@ static char rcsid[] = "$Id: dig.c,v 8.4 1995/06/19 08:35:06 vixie Exp $";
#include <netdb.h>
#include <stdio.h>
#include <resolv.h>
-#include <ctype.h>
+#include <ctype.h>
#include <errno.h>
#include <string.h>
#include <setjmp.h>
#include <fcntl.h>
+#include <stdlib.h>
-#include "nslookup/res.h"
-#include "../conf/portability.h"
+#include "../../usr.sbin/nslookup/res.h"
#define PRF_DEF 0x2ff9
#define PRF_MIN 0xA930
@@ -197,7 +197,8 @@ jmp_buf env;
HostInfo *defaultPtr = NULL;
HostInfo curHostInfo, defaultRec;
int curHostValid = FALSE;
-int queryType, queryClass;
+int queryType = T_A;
+int queryClass = C_IN;
extern int StringToClass(), StringToType(); /* subr.c */
#if defined(BSD) && BSD >= 199006 && !defined(RISCOS_BSD)
FILE *yyin = NULL;
@@ -220,7 +221,7 @@ stackarg(y, l)
case '\t':
case ' ':
l++; break;
- case '\0':
+ case NULL:
case '\n':
done++;
*y = NULL;
@@ -245,12 +246,7 @@ main(argc, argv)
{
struct hostent *hp;
short port = htons(NAMESERVER_PORT);
- /* Wierd stuff for SPARC alignment, hurts nothing else. */
- union {
- HEADER header_;
- u_char packet_[PACKETSZ];
- } packet_;
-#define packet (packet_.packet_)
+ u_char packet[PACKETSZ];
u_char answer[8*1024];
int n;
char doping[90];
@@ -263,8 +259,8 @@ main(argc, argv)
char *srv;
int anyflag = 0;
int sticky = 0;
- int tmp;
- int qtypeSet;
+ int tmp;
+ int qtype = 1, qclass = 1;
int addrflag = 0;
int zone = 0;
int bytes_out, bytes_in;
@@ -287,7 +283,6 @@ main(argc, argv)
res_init();
_res.pfcode = PRF_DEF;
- qtypeSet = 0;
gethostname(myhostname, (sizeof myhostname));
defsrv = strcat(defbuf, inet_ntoa(_res.nsaddr.sin_addr));
res_x = _res;
@@ -301,7 +296,7 @@ main(argc, argv)
if ((((afile = (char *) getenv("LOCALDEF")) != (char *) NULL) &&
((fp = open(afile, O_RDONLY)) > 0)) ||
((fp = open(SAVEENV, O_RDONLY)) > 0)) {
- read(fp, (char *)&res_x, (sizeof res_x));
+ read(fp, &res_x, (sizeof res_x));
close(fp);
_res = res_x;
}
@@ -345,8 +340,8 @@ main(argc, argv)
** while !EOF if batch mode
*/
*fileq = '\0';
- while ((dofile && (fgets(fileq,100,qfp) != NULL)) ||
- ((!dofile) && (once--)))
+ while ((dofile && (fgets(fileq,100,qfp) != NULL)) ||
+ ((!dofile) && (once--)))
{
if ((*fileq=='\n') || (*fileq=='#') || (*fileq==';')) {
continue; /* ignore blank lines & comments */
@@ -367,8 +362,7 @@ main(argc, argv)
stackarg(ay, qptr);
/* defaults */
- queryType = T_NS;
- queryClass = C_IN;
+ qtype = qclass = 1;
zone = 0;
*pingstr = 0;
srv = NULL;
@@ -380,7 +374,7 @@ main(argc, argv)
* More cmd-line options than anyone should ever have to
* deal with ....
*/
- while (*(++argv) != NULL && **argv != '\0') {
+ while (*(++argv) != NULL && **argv != '\0') {
strcat(cmd,*argv); strcat(cmd," ");
if (**argv == '@') {
srv = (*argv+1);
@@ -392,7 +386,7 @@ main(argc, argv)
SetOption(*argv+1);
continue;
}
-
+
if (strncmp(*argv,"-nost",5) == 0) {
sticky = 0;
continue;
@@ -408,33 +402,31 @@ main(argc, argv)
}
if (**argv == '-') {
- switch (argv[0][1]) {
+ switch (argv[0][1]) {
case 'T': wait = atoi(*++argv);
break;
- case 'c':
+ case 'c':
if ((tmp = atoi(*++argv))
|| *argv[0]=='0') {
- queryClass = tmp;
+ qclass = tmp;
} else if (tmp = StringToClass(*argv,
0, NULL)
) {
- queryClass = tmp;
+ qclass = tmp;
} else {
printf(
"; invalid class specified\n"
);
}
break;
- case 't':
+ case 't':
if ((tmp = atoi(*++argv))
|| *argv[0]=='0') {
- queryType = tmp;
- qtypeSet++;
+ qtype = tmp;
} else if (tmp = StringToType(*argv,
0, NULL)
) {
- queryType = tmp;
- qtypeSet++;
+ qtype = tmp;
} else {
printf(
"; invalid type specified\n"
@@ -442,10 +434,8 @@ main(argc, argv)
}
break;
case 'x':
- if (!qtypeSet) {
- queryType = T_ANY;
- qtypeSet++;
- }
+ if (qtype == T_A)
+ qtype = T_ANY;
if (!(addrc = *++argv)) {
printf(
"; no arg for -x?\n"
@@ -480,21 +470,20 @@ main(argc, argv)
continue;
} /* if '-' */
- if ((tmp = StringToType(*argv, -1, NULL)) != -1) {
- if ((T_ANY == tmp) && anyflag++) {
- queryClass = C_ANY;
- continue;
+ if ((tmp = StringToType(*argv, -1, NULL)) != -1) {
+ if ((T_ANY == tmp) && anyflag++) {
+ qclass = C_ANY;
+ continue;
}
if (T_AXFR == tmp) {
_res.pfcode = PRF_ZONE;
zone++;
} else {
- queryType = tmp;
- qtypeSet++;
+ qtype = tmp;
}
} else if ((tmp = StringToClass(*argv, -1, NULL))
- != -1) {
- queryClass = tmp;
+ != -1) {
+ qclass = tmp;
} else {
bzero(domain, (sizeof domain));
sprintf(domain,"%s",*argv);
@@ -504,7 +493,7 @@ main(argc, argv)
if (_res.pfcode & 0x80000)
printf("; pfcode: %08x, options: %08x\n",
_res.pfcode, _res.options);
-
+
/*
* Current env. (after this parse) is to become the
* new "working environmnet. Used in conj. with sticky.
@@ -529,7 +518,7 @@ main(argc, argv)
((fp = open(SAVEENV,
O_WRONLY|O_CREAT|O_TRUNC,
S_IREAD|S_IWRITE)) > 0)) {
- write(fp, (char *)&_res, (sizeof _res));
+ write(fp, &_res, (sizeof _res));
close(fp);
}
envsave = 0;
@@ -542,7 +531,7 @@ main(argc, argv)
/*
* Find address of server to query. If not dot-notation, then
- * try to resolve domain-name (if so, save and turn off print
+ * try to resolve domain-name (if so, save and turn off print
* options, this domain-query is not the one we want. Restore
* user options when done.
* Things get a bit wierd since we need to use resolver to be
@@ -633,13 +622,7 @@ main(argc, argv)
continue;
}
- if (*domain && !qtypeSet) {
- queryType = T_A;
- qtypeSet++;
- }
-
- bytes_out = n = res_mkquery(QUERY, domain,
- queryClass, queryType,
+ bytes_out = n = res_mkquery(QUERY, domain, qclass, qtype,
NULL, 0, NULL,
packet, sizeof(packet));
if (n < 0) {
@@ -682,7 +665,7 @@ main(argc, argv)
printf(";; MSG SIZE sent: %d rcvd: %d\n",
bytes_out, bytes_in);
}
-
+
fflush(stdout);
/*
* Argh ... not particularly elegant. Should put in *real* ping code.
@@ -758,8 +741,8 @@ SetOption(string)
if (i != 1) {
fprintf(stderr, ";*** Invalid option: %s\n", option);
return(ERROR);
- }
-
+ }
+
if (strncmp(option, "aa", 2) == 0) { /* aaonly */
_res.options |= RES_AAONLY;
} else if (strncmp(option, "noaa", 4) == 0) {
@@ -842,47 +825,47 @@ SetOption(string)
_res.pfcode &= ~RES_PRF_ANS;
} else if (strncmp(option, "qu", 2) == 0) { /* question section */
_res.pfcode |= RES_PRF_QUES;
- } else if (strncmp(option, "noqu", 4) == 0) {
+ } else if (strncmp(option, "noqu", 4) == 0) {
_res.pfcode &= ~RES_PRF_QUES;
} else if (strncmp(option, "au", 2) == 0) { /* authority section */
_res.pfcode |= RES_PRF_AUTH;
- } else if (strncmp(option, "noau", 4) == 0) {
+ } else if (strncmp(option, "noau", 4) == 0) {
_res.pfcode &= ~RES_PRF_AUTH;
} else if (strncmp(option, "ad", 2) == 0) { /* addition section */
_res.pfcode |= RES_PRF_ADD;
- } else if (strncmp(option, "noad", 4) == 0) {
+ } else if (strncmp(option, "noad", 4) == 0) {
_res.pfcode &= ~RES_PRF_ADD;
} else if (strncmp(option, "tt", 2) == 0) { /* TTL & ID */
_res.pfcode |= RES_PRF_TTLID;
- } else if (strncmp(option, "nott", 4) == 0) {
+ } else if (strncmp(option, "nott", 4) == 0) {
_res.pfcode &= ~RES_PRF_TTLID;
} else if (strncmp(option, "he", 2) == 0) { /* head flags stats */
_res.pfcode |= RES_PRF_HEAD2;
- } else if (strncmp(option, "nohe", 4) == 0) {
+ } else if (strncmp(option, "nohe", 4) == 0) {
_res.pfcode &= ~RES_PRF_HEAD2;
} else if (strncmp(option, "H", 1) == 0) { /* header all */
_res.pfcode |= RES_PRF_HEADX;
- } else if (strncmp(option, "noH", 3) == 0) {
+ } else if (strncmp(option, "noH", 3) == 0) {
_res.pfcode &= ~(RES_PRF_HEADX);
} else if (strncmp(option, "qr", 2) == 0) { /* query */
_res.pfcode |= RES_PRF_QUERY;
- } else if (strncmp(option, "noqr", 4) == 0) {
+ } else if (strncmp(option, "noqr", 4) == 0) {
_res.pfcode &= ~RES_PRF_QUERY;
} else if (strncmp(option, "rep", 3) == 0) { /* reply */
_res.pfcode |= RES_PRF_REPLY;
- } else if (strncmp(option, "norep", 5) == 0) {
+ } else if (strncmp(option, "norep", 5) == 0) {
_res.pfcode &= ~RES_PRF_REPLY;
} else if (strncmp(option, "cm", 2) == 0) { /* command line */
_res.pfcode |= RES_PRF_CMD;
- } else if (strncmp(option, "nocm", 4) == 0) {
+ } else if (strncmp(option, "nocm", 4) == 0) {
_res.pfcode &= ~RES_PRF_CMD;
} else if (strncmp(option, "cl", 2) == 0) { /* class mnemonic */
_res.pfcode |= RES_PRF_CLASS;
- } else if (strncmp(option, "nocl", 4) == 0) {
+ } else if (strncmp(option, "nocl", 4) == 0) {
_res.pfcode &= ~RES_PRF_CLASS;
} else if (strncmp(option, "st", 2) == 0) { /* stats*/
_res.pfcode |= RES_PRF_STATS;
- } else if (strncmp(option, "nost", 4) == 0) {
+ } else if (strncmp(option, "nost", 4) == 0) {
_res.pfcode &= ~RES_PRF_STATS;
} else {
fprintf(stderr, "; *** Invalid option: %s\n", option);
@@ -1028,7 +1011,7 @@ printZone(zone, sin)
__putshort(msglen, (u_char *)&len);
if (write(sockFD, (char *)&len, INT16SZ) != INT16SZ ||
- write(sockFD, (char *)&buf, msglen) != msglen) {
+ write(sockFD, (char *) &buf, msglen) != msglen) {
int e = errno;
perror(";; write");
(void) close(sockFD);
@@ -1063,7 +1046,7 @@ printZone(zone, sin)
* The server sent too much data to fit the existing buffer --
* allocate a new one.
*/
- if (len > (u_int)answerLen) {
+ if (len > answerLen) {
if (answerLen != 0) {
free(answer);
}
OpenPOWER on IntegriCloud