2 * Copyright (C) 2004-2014 Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (C) 2000-2003 Internet Software Consortium.
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
10 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
12 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
14 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15 * PERFORMANCE OF THIS SOFTWARE.
18 /* $Id: dig.c,v 1.245 2011/12/07 17:23:28 each Exp $ */
28 #include <isc/netaddr.h>
29 #include <isc/parseint.h>
30 #include <isc/print.h>
31 #include <isc/string.h>
35 #include <dns/byaddr.h>
36 #include <dns/fixedname.h>
37 #include <dns/masterdump.h>
38 #include <dns/message.h>
40 #include <dns/rdata.h>
41 #include <dns/rdataset.h>
42 #include <dns/rdatatype.h>
43 #include <dns/rdataclass.h>
44 #include <dns/result.h>
49 #define ADD_STRING(b, s) { \
50 if (strlen(s) >= isc_buffer_availablelength(b)) \
51 return (ISC_R_NOSPACE); \
53 isc_buffer_putstr(b, s); \
56 #define DIG_MAX_ADDRESSES 20
58 dig_lookup_t *default_lookup = NULL;
60 static char *batchname = NULL;
61 static FILE *batchfp = NULL;
63 static int addresscount = 0;
65 static char domainopt[DNS_NAME_MAXTEXT];
67 static isc_boolean_t short_form = ISC_FALSE, printcmd = ISC_TRUE,
68 ip6_int = ISC_FALSE, plusquest = ISC_FALSE, pluscomm = ISC_FALSE,
69 multiline = ISC_FALSE, nottl = ISC_FALSE, noclass = ISC_FALSE,
70 onesoa = ISC_FALSE, rrcomments = ISC_FALSE;
71 static isc_uint32_t splitwidth = 0xffffffff;
74 static const char * const opcodetext[] = {
93 /*% return code text */
94 static const char * const rcodetext[] = {
114 /*% safe rcodetext[] */
116 rcode_totext(dns_rcode_t rcode)
118 static char buf[sizeof("?65535")];
120 const char *consttext;
124 if (rcode >= (sizeof(rcodetext)/sizeof(rcodetext[0]))) {
125 snprintf(buf, sizeof(buf), "?%u", rcode);
126 totext.deconsttext = buf;
128 totext.consttext = rcodetext[rcode];
129 return totext.deconsttext;
134 print_usage(FILE *fp) {
136 "Usage: dig [@global-server] [domain] [q-type] [q-class] {q-opt}\n"
137 " {global-d-opt} host [@local-server] {local-d-opt}\n"
138 " [ host [@local-server] {local-d-opt} [...]]\n", fp);
141 ISC_PLATFORM_NORETURN_PRE static void
142 usage(void) ISC_PLATFORM_NORETURN_POST;
147 fputs("\nUse \"dig -h\" (or \"dig -h | more\") "
148 "for complete list of options\n", stderr);
155 fputs("DiG " VERSION "\n", stderr);
163 "Where: domain is in the Domain Name System\n"
164 " q-class is one of (in,hs,ch,...) [default: in]\n"
165 " q-type is one of (a,any,mx,ns,soa,hinfo,axfr,txt,...) [default:a]\n"
166 " (Use ixfr=version for type ixfr)\n"
167 " q-opt is one of:\n"
168 " -x dot-notation (shortcut for reverse lookups)\n"
169 " -i (use IP6.INT for IPv6 reverse lookups)\n"
170 " -f filename (batch mode)\n"
171 " -b address[#port] (bind to source address/port)\n"
172 " -p port (specify port number)\n"
173 " -q name (specify query name)\n"
174 " -t type (specify query type)\n"
175 " -c class (specify query class)\n"
176 " -k keyfile (specify tsig key file)\n"
177 " -y [hmac:]name:key (specify named base64 tsig key)\n"
178 " -4 (use IPv4 query transport only)\n"
179 " -6 (use IPv6 query transport only)\n"
180 " -m (enable memory usage debugging)\n"
181 " d-opt is of the form +keyword[=value], where keyword is:\n"
182 " +[no]vc (TCP mode)\n"
183 " +[no]tcp (TCP mode, alternate syntax)\n"
184 " +time=### (Set query timeout) [5]\n"
185 " +tries=### (Set number of UDP attempts) [3]\n"
186 " +retry=### (Set number of UDP retries) [2]\n"
187 " +domain=### (Set default domainname)\n"
188 " +bufsize=### (Set EDNS0 Max UDP packet size)\n"
189 " +ndots=### (Set NDOTS value)\n"
190 " +[no]edns[=###] (Set EDNS version) [0]\n"
191 " +[no]search (Set whether to use searchlist)\n"
192 " +[no]showsearch (Search with intermediate results)\n"
193 " +[no]defname (Ditto)\n"
194 " +[no]recurse (Recursive mode)\n"
195 " +[no]ignore (Don't revert to TCP for TC responses.)"
197 " +[no]fail (Don't try next server on SERVFAIL)\n"
198 " +[no]besteffort (Try to parse even illegal messages)\n"
199 " +[no]aaonly (Set AA flag in query (+[no]aaflag))\n"
200 " +[no]adflag (Set AD flag in query)\n"
201 " +[no]cdflag (Set CD flag in query)\n"
202 " +[no]cl (Control display of class in records)\n"
203 " +[no]cmd (Control display of command line)\n"
204 " +[no]comments (Control display of comment lines)\n"
205 " +[no]rrcomments (Control display of per-record "
207 " +[no]question (Control display of question)\n"
208 " +[no]answer (Control display of answer)\n"
209 " +[no]authority (Control display of authority)\n"
210 " +[no]additional (Control display of additional)\n"
211 " +[no]stats (Control display of statistics)\n"
212 " +[no]short (Disable everything except short\n"
214 " +[no]ttlid (Control display of ttls in records)\n"
215 " +[no]all (Set or clear all display flags)\n"
216 " +[no]qr (Print question before sending)\n"
217 " +[no]nssearch (Search all authoritative nameservers)\n"
218 " +[no]identify (ID responders in short answers)\n"
219 " +[no]trace (Trace delegation down from root [+dnssec])\n"
220 " +[no]dnssec (Request DNSSEC records)\n"
221 " +[no]nsid (Request Name Server ID)\n"
223 " +[no]sigchase (Chase DNSSEC signatures)\n"
224 " +trusted-key=#### (Trusted Key when chasing DNSSEC sigs)\n"
226 " +[no]topdown (Do DNSSEC validation top down mode)\n"
229 " +[no]split=## (Split hex/base64 fields into chunks)\n"
230 " +[no]multiline (Print records in an expanded format)\n"
231 " +[no]onesoa (AXFR prints only one soa record)\n"
232 " +[no]keepopen (Keep the TCP socket open between queries)\n"
233 " global d-opts and servers (before host name) affect all queries.\n"
234 " local d-opts and servers (after host name) affect only that lookup.\n"
235 " -h (print help and exit)\n"
236 " -v (print version and exit)\n",
241 * Callback from dighost.c to print the received message.
244 received(int bytes, isc_sockaddr_t *from, dig_query_t *query) {
249 char fromtext[ISC_SOCKADDR_FORMATSIZE];
251 isc_sockaddr_format(from, fromtext, sizeof(fromtext));
253 if (query->lookup->stats && !short_form) {
254 diff = isc_time_microdiff(&query->time_recv, &query->time_sent);
255 printf(";; Query time: %ld msec\n", (long int)diff/1000);
256 printf(";; SERVER: %s(%s)\n", fromtext, query->servname);
258 tmnow = *localtime(&tnow);
259 if (strftime(time_str, sizeof(time_str),
260 "%a %b %d %H:%M:%S %Z %Y", &tmnow) > 0U)
261 printf(";; WHEN: %s\n", time_str);
262 if (query->lookup->doing_xfr) {
263 printf(";; XFR size: %u records (messages %u, "
264 "bytes %" ISC_PRINT_QUADFORMAT "u)\n",
265 query->rr_count, query->msg_count,
268 printf(";; MSG SIZE rcvd: %u\n", bytes);
272 puts(";; WARNING -- Some TSIG could not "
275 if ((key == NULL) && (keysecret[0] != 0)) {
276 puts(";; WARNING -- TSIG key was not used.");
279 } else if (query->lookup->identify && !short_form) {
280 diff = isc_time_microdiff(&query->time_recv, &query->time_sent);
281 printf(";; Received %" ISC_PRINT_QUADFORMAT "u bytes "
282 "from %s(%s) in %d ms\n\n",
283 query->lookup->doing_xfr ?
284 query->byte_count : (isc_uint64_t)bytes,
285 fromtext, query->userarg,
291 * Callback from dighost.c to print that it is trying a server.
296 trying(char *frm, dig_lookup_t *lookup) {
302 * Internal print routine used to print short form replies.
305 say_message(dns_rdata_t *rdata, dig_query_t *query, isc_buffer_t *buf) {
308 char store[sizeof("12345678901234567890")];
310 if (query->lookup->trace || query->lookup->ns_search_only) {
311 result = dns_rdatatype_totext(rdata->type, buf);
312 if (result != ISC_R_SUCCESS)
314 ADD_STRING(buf, " ");
316 result = dns_rdata_totext(rdata, NULL, buf);
317 if (result == ISC_R_NOSPACE)
319 check_result(result, "dns_rdata_totext");
320 if (query->lookup->identify) {
321 diff = isc_time_microdiff(&query->time_recv, &query->time_sent);
322 ADD_STRING(buf, " from server ");
323 ADD_STRING(buf, query->servname);
324 snprintf(store, 19, " in %d ms.", (int)diff/1000);
325 ADD_STRING(buf, store);
327 ADD_STRING(buf, "\n");
328 return (ISC_R_SUCCESS);
332 * short_form message print handler. Calls above say_message()
335 short_answer(dns_message_t *msg, dns_messagetextflag_t flags,
336 isc_buffer_t *buf, dig_query_t *query)
339 dns_rdataset_t *rdataset;
340 isc_result_t result, loopresult;
341 dns_name_t empty_name;
342 dns_rdata_t rdata = DNS_RDATA_INIT;
346 dns_name_init(&empty_name, NULL);
347 result = dns_message_firstname(msg, DNS_SECTION_ANSWER);
348 if (result == ISC_R_NOMORE)
349 return (ISC_R_SUCCESS);
350 else if (result != ISC_R_SUCCESS)
355 dns_message_currentname(msg, DNS_SECTION_ANSWER, &name);
357 for (rdataset = ISC_LIST_HEAD(name->list);
359 rdataset = ISC_LIST_NEXT(rdataset, link)) {
360 loopresult = dns_rdataset_first(rdataset);
361 while (loopresult == ISC_R_SUCCESS) {
362 dns_rdataset_current(rdataset, &rdata);
363 result = say_message(&rdata, query,
365 if (result == ISC_R_NOSPACE)
367 check_result(result, "say_message");
368 loopresult = dns_rdataset_next(rdataset);
369 dns_rdata_reset(&rdata);
372 result = dns_message_nextname(msg, DNS_SECTION_ANSWER);
373 if (result == ISC_R_NOMORE)
375 else if (result != ISC_R_SUCCESS)
379 return (ISC_R_SUCCESS);
383 printrdataset(dns_name_t *owner_name, dns_rdataset_t *rdataset,
384 isc_buffer_t *target)
387 dns_master_style_t *style = NULL;
388 unsigned int styleflags = 0;
390 if (rdataset == NULL || owner_name == NULL || target == NULL)
393 styleflags |= DNS_STYLEFLAG_REL_OWNER;
395 styleflags |= DNS_STYLEFLAG_NO_TTL;
397 styleflags |= DNS_STYLEFLAG_NO_CLASS;
399 styleflags |= DNS_STYLEFLAG_RRCOMMENT;
401 styleflags |= DNS_STYLEFLAG_OMIT_OWNER;
402 styleflags |= DNS_STYLEFLAG_OMIT_CLASS;
403 styleflags |= DNS_STYLEFLAG_REL_DATA;
404 styleflags |= DNS_STYLEFLAG_OMIT_TTL;
405 styleflags |= DNS_STYLEFLAG_TTL;
406 styleflags |= DNS_STYLEFLAG_MULTILINE;
407 styleflags |= DNS_STYLEFLAG_COMMENT;
408 styleflags |= DNS_STYLEFLAG_RRCOMMENT;
411 if (multiline || (nottl && noclass))
412 result = dns_master_stylecreate2(&style, styleflags,
413 24, 24, 24, 32, 80, 8,
415 else if (nottl || noclass)
416 result = dns_master_stylecreate2(&style, styleflags,
417 24, 24, 32, 40, 80, 8,
420 result = dns_master_stylecreate2(&style, styleflags,
421 24, 32, 40, 48, 80, 8,
423 check_result(result, "dns_master_stylecreate");
425 result = dns_master_rdatasettotext(owner_name, rdataset, style, target);
428 dns_master_styledestroy(&style, mctx);
435 * Callback from dighost.c to print the reply from a server
438 printmessage(dig_query_t *query, dns_message_t *msg, isc_boolean_t headers) {
440 dns_messagetextflag_t flags;
441 isc_buffer_t *buf = NULL;
442 unsigned int len = OUTPUTBUF;
443 dns_master_style_t *style = NULL;
444 unsigned int styleflags = 0;
446 styleflags |= DNS_STYLEFLAG_REL_OWNER;
447 if (query->lookup->comments)
448 styleflags |= DNS_STYLEFLAG_COMMENT;
450 styleflags |= DNS_STYLEFLAG_RRCOMMENT;
452 styleflags |= DNS_STYLEFLAG_NO_TTL;
454 styleflags |= DNS_STYLEFLAG_NO_CLASS;
456 styleflags |= DNS_STYLEFLAG_OMIT_OWNER;
457 styleflags |= DNS_STYLEFLAG_OMIT_CLASS;
458 styleflags |= DNS_STYLEFLAG_REL_DATA;
459 styleflags |= DNS_STYLEFLAG_OMIT_TTL;
460 styleflags |= DNS_STYLEFLAG_TTL;
461 styleflags |= DNS_STYLEFLAG_MULTILINE;
462 styleflags |= DNS_STYLEFLAG_RRCOMMENT;
464 if (multiline || (nottl && noclass))
465 result = dns_master_stylecreate2(&style, styleflags,
466 24, 24, 24, 32, 80, 8,
468 else if (nottl || noclass)
469 result = dns_master_stylecreate2(&style, styleflags,
470 24, 24, 32, 40, 80, 8,
473 result = dns_master_stylecreate2(&style, styleflags,
474 24, 32, 40, 48, 80, 8,
476 check_result(result, "dns_master_stylecreate");
478 if (query->lookup->cmdline[0] != 0) {
480 fputs(query->lookup->cmdline, stdout);
481 query->lookup->cmdline[0]=0;
483 debug("printmessage(%s %s %s)", headers ? "headers" : "noheaders",
484 query->lookup->comments ? "comments" : "nocomments",
485 short_form ? "short_form" : "long_form");
489 flags |= DNS_MESSAGETEXTFLAG_NOHEADERS;
490 flags |= DNS_MESSAGETEXTFLAG_NOCOMMENTS;
492 if (onesoa && query->lookup->rdtype == dns_rdatatype_axfr)
493 flags |= (query->msg_count == 0) ? DNS_MESSAGETEXTFLAG_ONESOA :
494 DNS_MESSAGETEXTFLAG_OMITSOA;
495 if (!query->lookup->comments)
496 flags |= DNS_MESSAGETEXTFLAG_NOCOMMENTS;
498 result = isc_buffer_allocate(mctx, &buf, len);
499 check_result(result, "isc_buffer_allocate");
501 if (query->lookup->comments && !short_form) {
502 if (query->lookup->cmdline[0] != 0)
503 printf("; %s\n", query->lookup->cmdline);
504 if (msg == query->lookup->sendmsg)
505 printf(";; Sending:\n");
507 printf(";; Got answer:\n");
510 printf(";; ->>HEADER<<- opcode: %s, status: %s, "
512 opcodetext[msg->opcode],
513 rcode_totext(msg->rcode),
516 if ((msg->flags & DNS_MESSAGEFLAG_QR) != 0)
518 if ((msg->flags & DNS_MESSAGEFLAG_AA) != 0)
520 if ((msg->flags & DNS_MESSAGEFLAG_TC) != 0)
522 if ((msg->flags & DNS_MESSAGEFLAG_RD) != 0)
524 if ((msg->flags & DNS_MESSAGEFLAG_RA) != 0)
526 if ((msg->flags & DNS_MESSAGEFLAG_AD) != 0)
528 if ((msg->flags & DNS_MESSAGEFLAG_CD) != 0)
530 if ((msg->flags & 0x0040U) != 0)
531 printf("; MBZ: 0x4");
533 printf("; QUERY: %u, ANSWER: %u, "
534 "AUTHORITY: %u, ADDITIONAL: %u\n",
535 msg->counts[DNS_SECTION_QUESTION],
536 msg->counts[DNS_SECTION_ANSWER],
537 msg->counts[DNS_SECTION_AUTHORITY],
538 msg->counts[DNS_SECTION_ADDITIONAL]);
540 if (msg != query->lookup->sendmsg &&
541 (msg->flags & DNS_MESSAGEFLAG_RD) != 0 &&
542 (msg->flags & DNS_MESSAGEFLAG_RA) == 0)
543 printf(";; WARNING: recursion requested "
544 "but not available\n");
546 if (msg != query->lookup->sendmsg &&
547 query->lookup->edns != -1 && msg->opt == NULL &&
548 (msg->rcode == dns_rcode_formerr ||
549 msg->rcode == dns_rcode_notimp))
550 printf("\n;; WARNING: EDNS query returned status "
551 "%s - retry with '%s+noedns'\n",
552 rcode_totext(msg->rcode),
553 query->lookup->dnssec ? "+nodnssec ": "");
554 if (msg != query->lookup->sendmsg && extrabytes != 0U)
555 printf(";; WARNING: Message has %u extra byte%s at "
556 "end\n", extrabytes, extrabytes != 0 ? "s" : "");
561 if (query->lookup->comments && headers && !short_form) {
562 result = dns_message_pseudosectiontotext(msg,
563 DNS_PSEUDOSECTION_OPT,
565 if (result == ISC_R_NOSPACE) {
568 isc_buffer_free(&buf);
569 result = isc_buffer_allocate(mctx, &buf, len);
570 if (result == ISC_R_SUCCESS)
571 goto repopulate_buffer;
576 "dns_message_pseudosectiontotext");
579 if (query->lookup->section_question && headers) {
581 result = dns_message_sectiontotext(msg,
582 DNS_SECTION_QUESTION,
584 if (result == ISC_R_NOSPACE)
586 check_result(result, "dns_message_sectiontotext");
589 if (query->lookup->section_answer) {
591 result = dns_message_sectiontotext(msg,
594 if (result == ISC_R_NOSPACE)
596 check_result(result, "dns_message_sectiontotext");
598 result = short_answer(msg, flags, buf, query);
599 if (result == ISC_R_NOSPACE)
601 check_result(result, "short_answer");
604 if (query->lookup->section_authority) {
606 result = dns_message_sectiontotext(msg,
607 DNS_SECTION_AUTHORITY,
609 if (result == ISC_R_NOSPACE)
611 check_result(result, "dns_message_sectiontotext");
614 if (query->lookup->section_additional) {
616 result = dns_message_sectiontotext(msg,
617 DNS_SECTION_ADDITIONAL,
619 if (result == ISC_R_NOSPACE)
621 check_result(result, "dns_message_sectiontotext");
623 * Only print the signature on the first record.
626 result = dns_message_pseudosectiontotext(
628 DNS_PSEUDOSECTION_TSIG,
630 if (result == ISC_R_NOSPACE)
633 "dns_message_pseudosectiontotext");
634 result = dns_message_pseudosectiontotext(
636 DNS_PSEUDOSECTION_SIG0,
638 if (result == ISC_R_NOSPACE)
641 "dns_message_pseudosectiontotext");
646 if (headers && query->lookup->comments && !short_form)
649 printf("%.*s", (int)isc_buffer_usedlength(buf),
650 (char *)isc_buffer_base(buf));
651 isc_buffer_free(&buf);
655 dns_master_styledestroy(&style, mctx);
660 * print the greeting message when the program first starts up.
663 printgreeting(int argc, char **argv, dig_lookup_t *lookup) {
666 static isc_boolean_t first = ISC_TRUE;
670 lookup->cmdline[sizeof(lookup->cmdline) - 1] = 0;
671 snprintf(lookup->cmdline, sizeof(lookup->cmdline),
672 "%s; <<>> DiG " VERSION " <<>>",
676 snprintf(append, sizeof(append), " %s", argv[i++]);
677 remaining = sizeof(lookup->cmdline) -
678 strlen(lookup->cmdline) - 1;
679 strncat(lookup->cmdline, append, remaining);
681 remaining = sizeof(lookup->cmdline) -
682 strlen(lookup->cmdline) - 1;
683 strncat(lookup->cmdline, "\n", remaining);
684 if (first && addresscount != 0) {
685 snprintf(append, sizeof(append),
686 "; (%d server%s found)\n",
688 addresscount > 1 ? "s" : "");
689 remaining = sizeof(lookup->cmdline) -
690 strlen(lookup->cmdline) - 1;
691 strncat(lookup->cmdline, append, remaining);
694 snprintf(append, sizeof(append),
695 ";; global options:%s%s\n",
696 short_form ? " +short" : "",
697 printcmd ? " +cmd" : "");
699 remaining = sizeof(lookup->cmdline) -
700 strlen(lookup->cmdline) - 1;
701 strncat(lookup->cmdline, append, remaining);
707 * We're not using isc_commandline_parse() here since the command line
708 * syntax of dig is quite a bit different from that which can be described
714 plus_option(char *option, isc_boolean_t is_batchfile,
715 dig_lookup_t *lookup)
718 char option_store[256];
719 char *cmd, *value, *ptr;
721 isc_boolean_t state = ISC_TRUE;
726 strncpy(option_store, option, sizeof(option_store));
727 option_store[sizeof(option_store)-1]=0;
729 cmd = next_token(&ptr,"=");
731 printf(";; Invalid option %s\n", option_store);
735 if (strncasecmp(cmd, "no", 2)==0) {
740 #define FULLCHECK(A) \
742 size_t _l = strlen(cmd); \
743 if (_l >= sizeof(A) || strncasecmp(cmd, A, _l) != 0) \
744 goto invalid_option; \
746 #define FULLCHECK2(A, B) \
748 size_t _l = strlen(cmd); \
749 if ((_l >= sizeof(A) || strncasecmp(cmd, A, _l) != 0) && \
750 (_l >= sizeof(B) || strncasecmp(cmd, B, _l) != 0)) \
751 goto invalid_option; \
757 case 'a': /* aaonly / aaflag */
758 FULLCHECK2("aaonly", "aaflag");
759 lookup->aaonly = state;
763 case 'd': /* additional */
764 FULLCHECK("additional");
765 lookup->section_additional = state;
767 case 'f': /* adflag */
768 case '\0': /* +ad is a synonym for +adflag */
770 lookup->adflag = state;
778 lookup->section_question = state;
779 lookup->section_authority = state;
780 lookup->section_answer = state;
781 lookup->section_additional = state;
782 lookup->comments = state;
784 lookup->stats = state;
787 case 'n': /* answer */
789 lookup->section_answer = state;
791 case 'u': /* authority */
792 FULLCHECK("authority");
793 lookup->section_authority = state;
801 case 'e':/* besteffort */
802 FULLCHECK("besteffort");
803 lookup->besteffort = state;
805 case 'u':/* bufsize */
806 FULLCHECK("bufsize");
811 result = parse_uint(&num, value, COMMSIZE,
813 if (result != ISC_R_SUCCESS)
814 fatal("Couldn't parse buffer size");
815 lookup->udpsize = num;
823 case 'd':/* cdflag */
825 case 'f': /* cdflag */
826 case '\0': /* +cd is a synonym for +cdflag */
828 lookup->cdflag = state;
836 noclass = ISC_TF(!state);
842 case 'o': /* comments */
843 FULLCHECK("comments");
844 lookup->comments = state;
845 if (lookup == default_lookup)
854 case 'e': /* defname */
855 FULLCHECK("defname");
856 if (!lookup->trace) {
860 case 'n': /* dnssec */
862 if (state && lookup->edns == -1)
864 lookup->dnssec = state;
866 case 'o': /* domain */
872 strncpy(domainopt, value, sizeof(domainopt));
873 domainopt[sizeof(domainopt)-1] = '\0';
889 result = parse_uint(&num, value, 255, "edns");
890 if (result != ISC_R_SUCCESS)
891 fatal("Couldn't parse edns");
896 lookup->servfail_stops = state;
900 case 'd': /* identify */
901 FULLCHECK("identify");
902 lookup->identify = state;
904 case 'g': /* ignore */
905 default: /* Inherits default for compatibility */
907 lookup->ignore = ISC_TRUE;
911 FULLCHECK("keepopen");
914 case 'm': /* multiline */
915 FULLCHECK("multiline");
920 case 'd': /* ndots */
926 result = parse_uint(&num, value, MAXNDOTS, "ndots");
927 if (result != ISC_R_SUCCESS)
928 fatal("Couldn't parse ndots");
935 if (state && lookup->edns == -1)
937 lookup->nsid = state;
939 case 's': /* nssearch */
940 FULLCHECK("nssearch");
941 lookup->ns_search_only = state;
943 lookup->trace_root = ISC_TRUE;
944 lookup->recurse = ISC_TRUE;
945 lookup->identify = ISC_TRUE;
946 lookup->stats = ISC_FALSE;
947 lookup->comments = ISC_FALSE;
948 rrcomments = ISC_FALSE;
949 lookup->section_additional = ISC_FALSE;
950 lookup->section_authority = ISC_FALSE;
951 lookup->section_question = ISC_FALSE;
952 lookup->rdtype = dns_rdatatype_ns;
953 lookup->rdtypeset = ISC_TRUE;
954 short_form = ISC_TRUE;
975 case 'u': /* question */
976 FULLCHECK("question");
977 lookup->section_question = state;
978 if (lookup == default_lookup)
989 case 'c': /* recurse */
990 FULLCHECK("recurse");
991 lookup->recurse = state;
993 case 't': /* retry / retries */
994 FULLCHECK2("retry", "retries");
999 result = parse_uint(&lookup->retries, value,
1000 MAXTRIES - 1, "retries");
1001 if (result != ISC_R_SUCCESS)
1002 fatal("Couldn't parse retries");
1006 goto invalid_option;
1009 case 'r': /* rrcomments */
1010 FULLCHECK("rrcomments");
1014 goto invalid_option;
1019 case 'e': /* search */
1020 FULLCHECK("search");
1021 if (!lookup->trace) {
1027 goto invalid_option;
1029 case 'r': /* short */
1033 printcmd = ISC_FALSE;
1034 lookup->section_additional = ISC_FALSE;
1035 lookup->section_answer = ISC_TRUE;
1036 lookup->section_authority = ISC_FALSE;
1037 lookup->section_question = ISC_FALSE;
1038 lookup->comments = ISC_FALSE;
1039 rrcomments = ISC_FALSE;
1040 lookup->stats = ISC_FALSE;
1043 case 'w': /* showsearch */
1044 FULLCHECK("showsearch");
1045 if (!lookup->trace) {
1051 goto invalid_option;
1055 case 'i': /* sigchase */
1056 FULLCHECK("sigchase");
1057 lookup->sigchase = state;
1058 if (lookup->sigchase)
1059 lookup->dnssec = ISC_TRUE;
1062 case 'p': /* split */
1064 if (value != NULL && !state)
1065 goto invalid_option;
1069 } else if (value == NULL)
1072 result = parse_uint(&splitwidth, value,
1074 if (splitwidth % 4 != 0) {
1075 splitwidth = ((splitwidth + 3) / 4) * 4;
1076 fprintf(stderr, ";; Warning, split must be "
1077 "a multiple of 4; adjusting "
1078 "to %d\n", splitwidth);
1081 * There is an adjustment done in the
1082 * totext_<rrtype>() functions which causes
1083 * splitwidth to shrink. This is okay when we're
1084 * using the default width but incorrect in this
1085 * case, so we correct for it
1089 if (result != ISC_R_SUCCESS)
1090 fatal("Couldn't parse split");
1092 case 't': /* stats */
1094 lookup->stats = state;
1097 goto invalid_option;
1104 if (!is_batchfile) {
1105 lookup->tcp_mode = state;
1106 lookup->tcp_mode_set = ISC_TRUE;
1109 case 'i': /* timeout */
1110 FULLCHECK("timeout");
1114 goto invalid_option;
1115 result = parse_uint(&timeout, value, MAXTIMEOUT,
1117 if (result != ISC_R_SUCCESS)
1118 fatal("Couldn't parse timeout");
1123 case 'o': /* topdown */
1124 FULLCHECK("topdown");
1125 lookup->do_topdown = state;
1130 case 'a': /* trace */
1132 lookup->trace = state;
1133 lookup->trace_root = state;
1135 lookup->recurse = ISC_FALSE;
1136 lookup->identify = ISC_TRUE;
1137 lookup->comments = ISC_FALSE;
1138 rrcomments = ISC_FALSE;
1139 lookup->stats = ISC_FALSE;
1140 lookup->section_additional = ISC_FALSE;
1141 lookup->section_authority = ISC_TRUE;
1142 lookup->section_question = ISC_FALSE;
1143 lookup->dnssec = ISC_TRUE;
1144 usesearch = ISC_FALSE;
1147 case 'i': /* tries */
1152 goto invalid_option;
1153 result = parse_uint(&lookup->retries, value,
1155 if (result != ISC_R_SUCCESS)
1156 fatal("Couldn't parse tries");
1157 if (lookup->retries == 0)
1158 lookup->retries = 1;
1161 case 'u': /* trusted-key */
1162 FULLCHECK("trusted-key");
1166 goto invalid_option;
1167 n = strlcpy(trustedkey, ptr,
1168 sizeof(trustedkey));
1169 if (n >= sizeof(trustedkey))
1170 fatal("trusted key too large");
1174 goto invalid_option;
1177 case 't': /* ttlid */
1179 nottl = ISC_TF(!state);
1182 goto invalid_option;
1187 if (!is_batchfile) {
1188 lookup->tcp_mode = state;
1189 lookup->tcp_mode_set = ISC_TRUE;
1195 fprintf(stderr, "Invalid option: +%s\n",
1203 * #ISC_TRUE returned if value was used
1205 static const char *single_dash_opts = "46dhimnv";
1206 static const char *dash_opts = "46bcdfhikmnptvyx";
1207 static isc_boolean_t
1208 dash_option(char *option, char *next, dig_lookup_t **lookup,
1209 isc_boolean_t *open_type_class, isc_boolean_t *need_clone,
1210 isc_boolean_t config_only, int argc, char **argv,
1211 isc_boolean_t *firstarg)
1213 char opt, *value, *ptr, *ptr2, *ptr3;
1214 isc_result_t result;
1215 isc_boolean_t value_from_next;
1216 isc_textregion_t tr;
1217 dns_rdatatype_t rdtype;
1218 dns_rdataclass_t rdclass;
1219 char textname[MXNAME];
1221 struct in6_addr in6;
1226 while (strpbrk(option, single_dash_opts) == &option[0]) {
1228 * Since the -[46dhimnv] options do not take an argument,
1229 * account for them (in any number and/or combination)
1230 * if they appear as the first character(s) of a q-opt.
1236 isc_net_disableipv6();
1237 have_ipv6 = ISC_FALSE;
1239 fatal("can't find IPv4 networking");
1246 isc_net_disableipv4();
1247 have_ipv4 = ISC_FALSE;
1249 fatal("can't find IPv6 networking");
1255 ptr = strpbrk(&option[1], dash_opts);
1256 if (ptr != &option[1]) {
1259 debugging = ISC_TRUE;
1262 debugging = ISC_TRUE;
1271 case 'm': /* memdebug */
1272 /* memdebug is handled in preparse_args() */
1282 if (strlen(option) > 1U)
1283 option = &option[1];
1288 if (strlen(option) > 1U) {
1289 value_from_next = ISC_FALSE;
1292 value_from_next = ISC_TRUE;
1296 goto invalid_option;
1299 hash = strchr(value, '#');
1301 result = parse_uint(&num, hash + 1, MAXPORT,
1303 if (result != ISC_R_SUCCESS)
1304 fatal("Couldn't parse port number");
1309 if (have_ipv6 && inet_pton(AF_INET6, value, &in6) == 1) {
1310 isc_sockaddr_fromin6(&bind_address, &in6, srcport);
1311 isc_net_disableipv4();
1312 } else if (have_ipv4 && inet_pton(AF_INET, value, &in4) == 1) {
1313 isc_sockaddr_fromin(&bind_address, &in4, srcport);
1314 isc_net_disableipv6();
1318 fatal("invalid address %s", value);
1322 specified_source = ISC_TRUE;
1323 return (value_from_next);
1325 if ((*lookup)->rdclassset) {
1326 fprintf(stderr, ";; Warning, extra class option\n");
1328 *open_type_class = ISC_FALSE;
1330 tr.length = strlen(value);
1331 result = dns_rdataclass_fromtext(&rdclass,
1332 (isc_textregion_t *)&tr);
1333 if (result == ISC_R_SUCCESS) {
1334 (*lookup)->rdclass = rdclass;
1335 (*lookup)->rdclassset = ISC_TRUE;
1337 fprintf(stderr, ";; Warning, ignoring "
1338 "invalid class %s\n",
1340 return (value_from_next);
1343 return (value_from_next);
1345 strncpy(keyfile, value, sizeof(keyfile));
1346 keyfile[sizeof(keyfile)-1]=0;
1347 return (value_from_next);
1349 result = parse_uint(&num, value, MAXPORT, "port number");
1350 if (result != ISC_R_SUCCESS)
1351 fatal("Couldn't parse port number");
1353 return (value_from_next);
1357 (*lookup) = clone_lookup(default_lookup,
1359 *need_clone = ISC_TRUE;
1360 strncpy((*lookup)->textname, value,
1361 sizeof((*lookup)->textname));
1362 (*lookup)->textname[sizeof((*lookup)->textname)-1]=0;
1363 (*lookup)->trace_root = ISC_TF((*lookup)->trace ||
1364 (*lookup)->ns_search_only);
1365 (*lookup)->new_search = ISC_TRUE;
1367 printgreeting(argc, argv, *lookup);
1368 *firstarg = ISC_FALSE;
1370 ISC_LIST_APPEND(lookup_list, (*lookup), link);
1371 debug("looking up %s", (*lookup)->textname);
1373 return (value_from_next);
1375 *open_type_class = ISC_FALSE;
1376 if (strncasecmp(value, "ixfr=", 5) == 0) {
1377 rdtype = dns_rdatatype_ixfr;
1378 result = ISC_R_SUCCESS;
1381 tr.length = strlen(value);
1382 result = dns_rdatatype_fromtext(&rdtype,
1383 (isc_textregion_t *)&tr);
1384 if (result == ISC_R_SUCCESS &&
1385 rdtype == dns_rdatatype_ixfr) {
1386 result = DNS_R_UNKNOWN;
1389 if (result == ISC_R_SUCCESS) {
1390 if ((*lookup)->rdtypeset) {
1391 fprintf(stderr, ";; Warning, "
1392 "extra type option\n");
1394 if (rdtype == dns_rdatatype_ixfr) {
1395 isc_uint32_t serial;
1396 (*lookup)->rdtype = dns_rdatatype_ixfr;
1397 (*lookup)->rdtypeset = ISC_TRUE;
1398 result = parse_uint(&serial, &value[5],
1399 MAXSERIAL, "serial number");
1400 if (result != ISC_R_SUCCESS)
1401 fatal("Couldn't parse serial number");
1402 (*lookup)->ixfr_serial = serial;
1403 (*lookup)->section_question = plusquest;
1404 (*lookup)->comments = pluscomm;
1405 if (!(*lookup)->tcp_mode_set)
1406 (*lookup)->tcp_mode = ISC_TRUE;
1408 (*lookup)->rdtype = rdtype;
1410 (*lookup)->rdtypeset = ISC_TRUE;
1411 if (rdtype == dns_rdatatype_axfr) {
1412 (*lookup)->section_question = plusquest;
1413 (*lookup)->comments = pluscomm;
1415 (*lookup)->ixfr_serial = ISC_FALSE;
1418 fprintf(stderr, ";; Warning, ignoring "
1419 "invalid type %s\n",
1421 return (value_from_next);
1423 ptr = next_token(&value,":"); /* hmac type or name */
1427 ptr2 = next_token(&value, ":"); /* name or secret */
1430 ptr3 = next_token(&value,":"); /* secret or NULL */
1436 hmacname = DNS_TSIG_HMACMD5_NAME;
1439 strncpy(keynametext, ptr, sizeof(keynametext));
1440 keynametext[sizeof(keynametext)-1]=0;
1441 strncpy(keysecret, ptr2, sizeof(keysecret));
1442 keysecret[sizeof(keysecret)-1]=0;
1443 return (value_from_next);
1446 *lookup = clone_lookup(default_lookup, ISC_TRUE);
1447 *need_clone = ISC_TRUE;
1448 if (get_reverse(textname, sizeof(textname), value,
1449 ip6_int, ISC_FALSE) == ISC_R_SUCCESS) {
1450 strncpy((*lookup)->textname, textname,
1451 sizeof((*lookup)->textname));
1452 (*lookup)->textname[sizeof((*lookup)->textname)-1] = 0;
1453 debug("looking up %s", (*lookup)->textname);
1454 (*lookup)->trace_root = ISC_TF((*lookup)->trace ||
1455 (*lookup)->ns_search_only);
1456 (*lookup)->ip6_int = ip6_int;
1457 if (!(*lookup)->rdtypeset)
1458 (*lookup)->rdtype = dns_rdatatype_ptr;
1459 if (!(*lookup)->rdclassset)
1460 (*lookup)->rdclass = dns_rdataclass_in;
1461 (*lookup)->new_search = ISC_TRUE;
1463 printgreeting(argc, argv, *lookup);
1464 *firstarg = ISC_FALSE;
1466 ISC_LIST_APPEND(lookup_list, *lookup, link);
1468 fprintf(stderr, "Invalid IP address %s\n", value);
1471 return (value_from_next);
1474 fprintf(stderr, "Invalid option: -%s\n", option);
1482 * Because we may be trying to do memory allocation recording, we're going
1483 * to need to parse the arguments for the -m *before* we start the main
1484 * argument parsing routine.
1486 * I'd prefer not to have to do this, but I am not quite sure how else to
1487 * fix the problem. Argument parsing in dig involves memory allocation
1488 * by its nature, so it can't be done in the main argument parser.
1491 preparse_args(int argc, char **argv) {
1498 for (rc--, rv++; rc > 0; rc--, rv++) {
1499 if (rv[0][0] != '-')
1502 while (strpbrk(option, single_dash_opts) == &option[0]) {
1503 if (option[0] == 'm') {
1504 memdebugging = ISC_TRUE;
1505 isc_mem_debugging = ISC_MEM_DEBUGTRACE |
1506 ISC_MEM_DEBUGRECORD;
1509 option = &option[1];
1515 parse_args(isc_boolean_t is_batchfile, isc_boolean_t config_only,
1516 int argc, char **argv)
1518 isc_result_t result;
1519 isc_textregion_t tr;
1520 isc_boolean_t firstarg = ISC_TRUE;
1521 dig_lookup_t *lookup = NULL;
1522 dns_rdatatype_t rdtype;
1523 dns_rdataclass_t rdclass;
1524 isc_boolean_t open_type_class = ISC_TRUE;
1525 char batchline[MXNAME];
1536 isc_boolean_t need_clone = ISC_TRUE;
1539 * The semantics for parsing the args is a bit complex; if
1540 * we don't have a host yet, make the arg apply globally,
1541 * otherwise make it apply to the latest host. This is
1542 * a bit different than the previous versions, but should
1543 * form a consistent user interface.
1545 * First, create a "default lookup" which won't actually be used
1546 * anywhere, except for cloning into new lookups
1549 debug("parse_args()");
1550 if (!is_batchfile) {
1551 debug("making new lookup");
1552 default_lookup = make_empty_lookup();
1553 default_lookup->adflag = ISC_TRUE;
1554 default_lookup->edns = 0;
1558 * Treat ${HOME}/.digrc as a special batchfile
1560 INSIST(batchfp == NULL);
1561 homedir = getenv("HOME");
1562 if (homedir != NULL) {
1564 n = snprintf(rcfile, sizeof(rcfile), "%s/.digrc",
1566 if (n < sizeof(rcfile))
1567 batchfp = fopen(rcfile, "r");
1569 if (batchfp != NULL) {
1570 while (fgets(batchline, sizeof(batchline),
1572 debug("config line %s", batchline);
1575 bargv[bargc] = next_token(&input, " \t\r\n");
1576 while ((bargv[bargc] != NULL) &&
1580 next_token(&input, " \t\r\n");
1586 for(i = 0; i < bargc; i++)
1587 debug(".digrc argv %d: %s",
1589 parse_args(ISC_TRUE, ISC_TRUE, bargc,
1597 if (is_batchfile && !config_only) {
1598 /* Processing '-f batchfile'. */
1599 lookup = clone_lookup(default_lookup, ISC_TRUE);
1600 need_clone = ISC_FALSE;
1602 lookup = default_lookup;
1606 for (rc--, rv++; rc > 0; rc--, rv++) {
1607 debug("main parsing %s", rv[0]);
1608 if (strncmp(rv[0], "%", 1) == 0)
1610 if (rv[0][0] == '@') {
1612 if (is_batchfile && !config_only) {
1613 addresscount = getaddresses(lookup, &rv[0][1],
1615 if (result != ISC_R_SUCCESS) {
1616 fprintf(stderr, "couldn't get address "
1617 "for '%s': %s: skipping "
1618 "lookup\n", &rv[0][1],
1619 isc_result_totext(result));
1620 if (ISC_LINK_LINKED(lookup, link))
1621 ISC_LIST_DEQUEUE(lookup_list,
1623 destroy_lookup(lookup);
1627 addresscount = getaddresses(lookup, &rv[0][1],
1629 } else if (rv[0][0] == '+') {
1630 plus_option(&rv[0][1], is_batchfile,
1632 } else if (rv[0][0] == '-') {
1634 if (dash_option(&rv[0][1], NULL,
1635 &lookup, &open_type_class,
1636 &need_clone, config_only,
1637 argc, argv, &firstarg)) {
1642 if (dash_option(&rv[0][1], rv[1],
1643 &lookup, &open_type_class,
1644 &need_clone, config_only,
1645 argc, argv, &firstarg)) {
1652 * Anything which isn't an option
1654 if (open_type_class) {
1655 if (strncasecmp(rv[0], "ixfr=", 5) == 0) {
1656 rdtype = dns_rdatatype_ixfr;
1657 result = ISC_R_SUCCESS;
1660 tr.length = strlen(rv[0]);
1661 result = dns_rdatatype_fromtext(&rdtype,
1662 (isc_textregion_t *)&tr);
1663 if (result == ISC_R_SUCCESS &&
1664 rdtype == dns_rdatatype_ixfr) {
1665 fprintf(stderr, ";; Warning, "
1671 if (result == ISC_R_SUCCESS) {
1672 if (lookup->rdtypeset) {
1673 fprintf(stderr, ";; Warning, "
1674 "extra type option\n");
1676 if (rdtype == dns_rdatatype_ixfr) {
1677 isc_uint32_t serial;
1680 lookup->rdtypeset = ISC_TRUE;
1681 result = parse_uint(&serial,
1685 if (result != ISC_R_SUCCESS)
1686 fatal("Couldn't parse "
1688 lookup->ixfr_serial = serial;
1689 lookup->section_question =
1691 lookup->comments = pluscomm;
1692 if (!lookup->tcp_mode_set)
1693 lookup->tcp_mode = ISC_TRUE;
1695 lookup->rdtype = rdtype;
1696 lookup->rdtypeset = ISC_TRUE;
1698 dns_rdatatype_axfr) {
1699 lookup->section_question =
1701 lookup->comments = pluscomm;
1703 lookup->ixfr_serial = ISC_FALSE;
1707 result = dns_rdataclass_fromtext(&rdclass,
1708 (isc_textregion_t *)&tr);
1709 if (result == ISC_R_SUCCESS) {
1710 if (lookup->rdclassset) {
1711 fprintf(stderr, ";; Warning, "
1712 "extra class option\n");
1714 lookup->rdclass = rdclass;
1715 lookup->rdclassset = ISC_TRUE;
1722 lookup = clone_lookup(default_lookup,
1724 need_clone = ISC_TRUE;
1725 strncpy(lookup->textname, rv[0],
1726 sizeof(lookup->textname));
1727 lookup->textname[sizeof(lookup->textname)-1]=0;
1728 lookup->trace_root = ISC_TF(lookup->trace ||
1729 lookup->ns_search_only);
1730 lookup->new_search = ISC_TRUE;
1732 printgreeting(argc, argv, lookup);
1733 firstarg = ISC_FALSE;
1735 ISC_LIST_APPEND(lookup_list, lookup, link);
1736 debug("looking up %s", lookup->textname);
1738 /* XXX Error message */
1743 * If we have a batchfile, seed the lookup list with the
1744 * first entry, then trust the callback in dighost_shutdown
1747 if ((batchname != NULL) && !(is_batchfile)) {
1748 if (strcmp(batchname, "-") == 0)
1751 batchfp = fopen(batchname, "r");
1752 if (batchfp == NULL) {
1756 fatal("couldn't open specified batch file");
1758 /* XXX Remove code dup from shutdown code */
1760 if (fgets(batchline, sizeof(batchline), batchfp) != 0) {
1762 debug("batch line %s", batchline);
1763 if (batchline[0] == '\r' || batchline[0] == '\n'
1764 || batchline[0] == '#' || batchline[0] == ';')
1767 bargv[bargc] = next_token(&input, " \t\r\n");
1768 while ((bargv[bargc] != NULL) && (bargc < 14)) {
1770 bargv[bargc] = next_token(&input, " \t\r\n");
1776 for(i = 0; i < bargc; i++)
1777 debug("batch argv %d: %s", i, bargv[i]);
1778 parse_args(ISC_TRUE, ISC_FALSE, bargc, (char **)bargv);
1784 * If no lookup specified, search for root
1786 if ((lookup_list.head == NULL) && !config_only) {
1788 lookup = clone_lookup(default_lookup, ISC_TRUE);
1789 need_clone = ISC_TRUE;
1790 lookup->trace_root = ISC_TF(lookup->trace ||
1791 lookup->ns_search_only);
1792 lookup->new_search = ISC_TRUE;
1793 strcpy(lookup->textname, ".");
1794 lookup->rdtype = dns_rdatatype_ns;
1795 lookup->rdtypeset = ISC_TRUE;
1797 printgreeting(argc, argv, lookup);
1798 firstarg = ISC_FALSE;
1800 ISC_LIST_APPEND(lookup_list, lookup, link);
1803 destroy_lookup(lookup);
1807 * Callback from dighost.c to allow program-specific shutdown code.
1808 * Here, we're possibly reading from a batch file, then shutting down
1809 * for real if there's nothing in the batch file to read.
1812 dighost_shutdown(void) {
1813 char batchline[MXNAME];
1819 if (batchname == NULL) {
1825 if (feof(batchfp)) {
1828 if (batchfp != stdin)
1833 if (fgets(batchline, sizeof(batchline), batchfp) != 0) {
1834 debug("batch line %s", batchline);
1837 bargv[bargc] = next_token(&input, " \t\r\n");
1838 while ((bargv[bargc] != NULL) && (bargc < 14)) {
1840 bargv[bargc] = next_token(&input, " \t\r\n");
1845 for(i = 0; i < bargc; i++)
1846 debug("batch argv %d: %s", i, bargv[i]);
1847 parse_args(ISC_TRUE, ISC_FALSE, bargc, (char **)bargv);
1851 if (batchfp != stdin)
1858 /*% Main processing routine for dig */
1860 main(int argc, char **argv) {
1861 isc_result_t result;
1863 ISC_LIST_INIT(lookup_list);
1864 ISC_LIST_INIT(server_list);
1865 ISC_LIST_INIT(search_list);
1868 preparse_args(argc, argv);
1870 result = isc_app_start();
1871 check_result(result, "isc_app_start");
1873 parse_args(ISC_FALSE, ISC_FALSE, argc, argv);
1875 if (domainopt[0] != '\0') {
1876 set_search_domain(domainopt);
1877 usesearch = ISC_TRUE;
1879 result = isc_app_onrun(mctx, global_task, onrun_callback, NULL);
1880 check_result(result, "isc_app_onrun");
1882 destroy_lookup(default_lookup);
1883 if (batchname != NULL) {
1884 if (batchfp != stdin)