📄 dig.c
字号:
#ifndef lintstatic char rcsid[] = "$Id: dig.c,v 4.9.1.9 1993/11/04 09:04:03 vixie Exp $";#endif/* * ++Copyright++ 1989 * - * 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: * 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-- *//*********************** Notes for the BIND 4.9 release (Paul Vixie, DEC) * dig 2.0 was written by copying sections of libresolv.a and nslookup * and modifying them to be more useful for a general lookup utility. * as of BIND 4.9, the changes needed to support dig have mostly been * incorporated into libresolv.a and nslookup; dig now links against * some of nslookup's .o files rather than #including them or maintaining * local copies of them. in some sense, dig belongs in the nslookup * subdirectory rather than up here in "tools", but that's for arc@sgi.com * (owner of nslookup) to decide. * * while merging dig back into the BIND release, i made a number of * structural changes. for one thing, i put all of dig's private * library routines into this file rather than maintaining them in * separate, #included, files. i don't like to #include ".c" files. * i removed all calls to "bcopy", replacing them with structure * assignments. i removed all "extern"'s of standard functions, * replacing them with #include's of standard header files. this * version of dig is probably as portable as the rest of BIND. * * i had to remove the query-time and packet-count statistics since * the current libresolv.a is a lot harder to modify to maintain these * than the 4.8 one (used in the original dig) was. for consolation, * i added a "usage" message with extensive help text. * * to save my (limited, albeit) sanity, i ran "indent" over the source. * i also added the standard berkeley/DEC copyrights, since this file now * contains a fair amount of non-USC code. note that the berkeley and * DEC copyrights do not prohibit redistribution, with or without fee; * we add them only to protect ourselves (you have to claim copyright * in order to disclaim liability and warranty). * * Paul Vixie, Palo Alto, CA, April 1993 **************************************************************************** /******************************************************************* ** DiG -- Domain Information Groper ** ** ** ** dig.c - Version 2.0 (9/1/90) ** ** ** ** Developed by: Steve Hotz & Paul Mockapetris ** ** USC Information Sciences Institute (USC-ISI) ** ** Marina del Rey, California ** ** 1989 ** ** ** ** dig.c - ** ** Version 2.0 (9/1/90) ** ** o renamed difftime() difftv() to avoid ** ** clash with ANSI C ** ** o fixed incorrect # args to strcmp,gettimeofday ** ** o incorrect length specified to strncmp ** ** o fixed broken -sticky -envsa -envset functions ** ** o print options/flags redefined & modified ** ** ** ** Version 2.0.beta (5/9/90) ** ** o output format - helpful to `doc` ** ** o minor cleanup ** ** o release to beta testers ** ** ** ** Version 1.1.beta (10/26/89) ** ** o hanging zone transer (when REFUSED) fixed ** ** o trailing dot added to domain names in RDATA ** ** o ISI internal ** ** ** ** Version 1.0.tmp (8/27/89) ** ** o Error in prnttime() fixed ** ** o no longer dumps core on large pkts ** ** o zone transfer (axfr) added ** ** o -x added for inverse queries ** ** (i.e. "dig -x 128.9.0.32") ** ** o give address of default server ** ** o accept broadcast to server @255.255.255.255 ** ** ** ** Version 1.0 (3/27/89) ** ** o original release ** ** ** ** DiG is Public Domain, and may be used for any purpose as ** ** long as this notice is not removed. ** **** **** **** NOTE: Version 2.0.beta is not for public distribution **** **** **** *******************************************************************/#define VERSION 20#define VSTRING "2.0"#include <sys/types.h>#include <sys/param.h>#include <sys/file.h>#include <sys/stat.h>#include <sys/socket.h>#include <sys/time.h>#include <netinet/in.h>#include <arpa/inet.h>#include <arpa/nameser.h>#include <netdb.h>#include <stdio.h>#include <resolv.h>#include <ctype.h> #include <errno.h>#include <string.h>#include <setjmp.h>#include <fcntl.h>#include "nslookup/res.h"#include "../conf/portability.h"#define PRF_DEF 0x2ff9#define PRF_MIN 0xA930#define PRF_ZONE 0x24f9#ifndef MAXHOSTNAMELEN#define MAXHOSTNAMELEN 256#endifint eecode = 0;FILE *qfp;int sockFD;#define SAVEENV "DiG.env"char *defsrv, *srvmsg;char defbuf[40] = "default -- ";char srvbuf[60];static void Usage();static int SetOption(), printZone(), printRR();/* stuff for nslookup modules */FILE *filePtr;jmp_buf env;HostInfo *defaultPtr = NULL;HostInfo curHostInfo, defaultRec;int curHostValid = FALSE;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;void yyrestart(f) { }#endifchar *pager = NULL;/* end of nslookup stuff */ /* ** Take arguments appearing in simple string (from file) ** place in char**. */stackarg(y,l) char *l; char **y;{ int done=0; while (!done) { switch (*l) { case '\t': case ' ': l++; break; case NULL: case '\n': done++; *y = NULL; break; default: *y++=l; while (!isspace(*l)) l++; if (*l == '\n') done++; *l++ = '\0'; *y = NULL; } }}char myhostname[MAXHOSTNAMELEN];main(argc, argv) int argc; char **argv;{ struct hostent *hp; short port = htons(NAMESERVER_PORT); char packet[PACKETSZ]; char answer[PACKETSZ]; int n; char doping[90]; char pingstr[50]; char *afile; char revaddr[10][10]; int addri, addrj; char *addrc; struct timeval exectime, tv1,tv2; char *srv; int anyflag = 0; int sticky = 0; int tmp; int qtype = 1, qclass = 1; int addrflag = 0; int zone = 0; int bytes_out, bytes_in; char cmd[256]; char domain[MAXDNAME]; char msg[120], *msgptr; char **vtmp; char *args[30]; char **ax; char **ay; int once = 1, dofile=0; /* batch -vs- interactive control */ char fileq[100]; char *qptr; int fp; int wait=0, delay; int envset=0, envsave=0; struct __res_state res_x, res_t; char *pp; res_init(); _res.pfcode = PRF_DEF; gethostname(myhostname, (sizeof myhostname)); defsrv = strcat(defbuf, inet_ntoa(_res.nsaddr.sin_addr)); res_x = _res; /* ** If LOCALDEF in environment, should point to file ** containing local favourite defaults. Also look for file ** DiG.env (i.e. SAVEENV) in local directory. */ if ((((afile = (char *) getenv("LOCALDEF")) != (char *) NULL) && ((fp = open(afile, O_RDONLY)) > 0)) || ((fp = open(SAVEENV, O_RDONLY)) > 0)) { read(fp, &res_x, (sizeof res_x)); close(fp); _res = res_x; } /* ** check for batch-mode DiG; also pre-scan for 'help' */ if (argc <= 1) { Usage(); exit(0); } vtmp = argv; ax=args; while (*vtmp != NULL) { if (strcmp(*vtmp, "-h") == 0 || strcmp(*vtmp, "-help") == 0 || strcmp(*vtmp, "-usage") == 0 || strcmp(*vtmp, "help") == 0) { Usage(); exit(0); } if (strcmp(*vtmp,"-f") == 0) { dofile++; once=0; if ((qfp = fopen(*++vtmp,"r")) == NULL) { fflush(stdout); perror("file open"); fflush(stderr); exit(10); } } else { *ax++ = *vtmp; } vtmp++; } _res.id = 1; gettimeofday(&tv1, NULL); /* ** Main section: once if cmd-line query ** while !EOF if batch mode */ *fileq = '\0'; while ((dofile && (fgets(fileq,100,qfp) !=NULL)) || ((!dofile) && (once--))) { if ((*fileq=='\n') || (*fileq=='#') || (*fileq==';')) { continue; /* ignore blank lines & comments */ }/* * "sticky" requests that before current parsing args * return to current "working" environment (X******) */ if (sticky) { printf(";; (using sticky settings)\n"); _res = res_x; }/* concat cmd-line and file args */ ay = ax; qptr = fileq; stackarg(ay, qptr); /* defaults */ qtype = qclass = 1; zone = 0; *pingstr = 0; srv = NULL; sprintf(cmd,"\n; <<>> DiG %s <<>> ",VSTRING); argv = args; argc = ax - args;/* * More cmd-line options than anyone should ever have to * deal with .... */ while (*(++argv) != NULL) { strcat(cmd,*argv); strcat(cmd," "); if (**argv == '@') { srv = (*argv+1); continue; } if (**argv == '%') continue; if (**argv == '+') { SetOption(*argv+1); continue; } if (strncmp(*argv,"-nost",5) == 0) { sticky = 0; continue;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -