4 * Copyright (C) 2004-2009 Internet Systems Consortium, Inc. ("ISC")
5 * Copyright (C) 2000-2003 Internet Software Consortium.
7 * Permission to use, copy, modify, and/or distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
11 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
12 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
13 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
14 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
16 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17 * PERFORMANCE OF THIS SOFTWARE.
20 /* Id: dig.c,v 1.233 2009/10/03 18:03:53 each Exp */
30 #include <isc/netaddr.h>
31 #include <isc/parseint.h>
32 #include <isc/print.h>
33 #include <isc/string.h>
37 #include <dns/byaddr.h>
38 #include <dns/fixedname.h>
39 #include <dns/masterdump.h>
40 #include <dns/message.h>
42 #include <dns/rdata.h>
43 #include <dns/rdataset.h>
44 #include <dns/rdatatype.h>
45 #include <dns/rdataclass.h>
46 #include <dns/result.h>
49 #include <bind9/getaddresses.h>
53 #define ADD_STRING(b, s) { \
54 if (strlen(s) >= isc_buffer_availablelength(b)) \
55 return (ISC_R_NOSPACE); \
57 isc_buffer_putstr(b, s); \
60 #define DIG_MAX_ADDRESSES 20
62 dig_lookup_t
*default_lookup
= NULL
;
64 static char *batchname
= NULL
;
65 static FILE *batchfp
= NULL
;
67 static int addresscount
= 0;
69 static char domainopt
[DNS_NAME_MAXTEXT
];
71 static isc_boolean_t short_form
= ISC_FALSE
, printcmd
= ISC_TRUE
,
72 ip6_int
= ISC_FALSE
, plusquest
= ISC_FALSE
, pluscomm
= ISC_FALSE
,
73 multiline
= ISC_FALSE
, nottl
= ISC_FALSE
, noclass
= ISC_FALSE
;
76 static const char * const opcodetext
[] = {
95 /*% return code text */
96 static const char * const rcodetext
[] = {
116 /*% safe rcodetext[] */
118 rcode_totext(dns_rcode_t rcode
)
120 static char buf
[sizeof("?65535")];
122 const char *consttext
;
126 if (rcode
>= (sizeof(rcodetext
)/sizeof(rcodetext
[0]))) {
127 snprintf(buf
, sizeof(buf
), "?%u", rcode
);
128 totext
.deconsttext
= buf
;
130 totext
.consttext
= rcodetext
[rcode
];
131 return totext
.deconsttext
;
136 print_usage(FILE *fp
) {
138 "Usage: dig [@global-server] [domain] [q-type] [q-class] {q-opt}\n"
139 " {global-d-opt} host [@local-server] {local-d-opt}\n"
140 " [ host [@local-server] {local-d-opt} [...]]\n", fp
);
143 ISC_PLATFORM_NORETURN_PRE
static void
144 usage(void) ISC_PLATFORM_NORETURN_POST
;
149 fputs("\nUse \"dig -h\" (or \"dig -h | more\") "
150 "for complete list of options\n", stderr
);
157 fputs("DiG " VERSION
"\n", stderr
);
165 "Where: domain is in the Domain Name System\n"
166 " q-class is one of (in,hs,ch,...) [default: in]\n"
167 " q-type is one of (a,any,mx,ns,soa,hinfo,axfr,txt,...) [default:a]\n"
168 " (Use ixfr=version for type ixfr)\n"
169 " q-opt is one of:\n"
170 " -x dot-notation (shortcut for reverse lookups)\n"
171 " -i (use IP6.INT for IPv6 reverse lookups)\n"
172 " -f filename (batch mode)\n"
173 " -b address[#port] (bind to source address/port)\n"
174 " -p port (specify port number)\n"
175 " -q name (specify query name)\n"
176 " -t type (specify query type)\n"
177 " -c class (specify query class)\n"
178 " -k keyfile (specify tsig key file)\n"
179 " -y [hmac:]name:key (specify named base64 tsig key)\n"
180 " -4 (use IPv4 query transport only)\n"
181 " -6 (use IPv6 query transport only)\n"
182 " -m (enable memory usage debugging)\n"
183 " d-opt is of the form +keyword[=value], where keyword is:\n"
184 " +[no]vc (TCP mode)\n"
185 " +[no]tcp (TCP mode, alternate syntax)\n"
186 " +time=### (Set query timeout) [5]\n"
187 " +tries=### (Set number of UDP attempts) [3]\n"
188 " +retry=### (Set number of UDP retries) [2]\n"
189 " +domain=### (Set default domainname)\n"
190 " +bufsize=### (Set EDNS0 Max UDP packet size)\n"
191 " +ndots=### (Set NDOTS value)\n"
192 " +edns=### (Set EDNS version)\n"
193 " +[no]search (Set whether to use searchlist)\n"
194 " +[no]showsearch (Search with intermediate results)\n"
195 " +[no]defname (Ditto)\n"
196 " +[no]recurse (Recursive mode)\n"
197 " +[no]ignore (Don't revert to TCP for TC responses.)"
199 " +[no]fail (Don't try next server on SERVFAIL)\n"
200 " +[no]besteffort (Try to parse even illegal messages)\n"
201 " +[no]aaonly (Set AA flag in query (+[no]aaflag))\n"
202 " +[no]adflag (Set AD flag in query)\n"
203 " +[no]cdflag (Set CD flag in query)\n"
204 " +[no]cl (Control display of class in records)\n"
205 " +[no]cmd (Control display of command line)\n"
206 " +[no]comments (Control display of comment lines)\n"
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)\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]multiline (Print records in an expanded format)\n"
230 " global d-opts and servers (before host name) affect all queries.\n"
231 " local d-opts and servers (after host name) affect only that lookup.\n"
232 " -h (print help and exit)\n"
233 " -v (print version and exit)\n",
238 * Callback from dighost.c to print the received message.
241 received(int bytes
, isc_sockaddr_t
*from
, dig_query_t
*query
) {
245 char fromtext
[ISC_SOCKADDR_FORMATSIZE
];
247 isc_sockaddr_format(from
, fromtext
, sizeof(fromtext
));
251 if (query
->lookup
->stats
&& !short_form
) {
252 diff
= isc_time_microdiff(&now
, &query
->time_sent
);
253 printf(";; Query time: %ld msec\n", (long int)diff
/1000);
254 printf(";; SERVER: %s(%s)\n", fromtext
, query
->servname
);
256 printf(";; WHEN: %s", ctime(&tnow
));
257 if (query
->lookup
->doing_xfr
) {
258 printf(";; XFR size: %u records (messages %u, "
259 "bytes %" ISC_PRINT_QUADFORMAT
"u)\n",
260 query
->rr_count
, query
->msg_count
,
263 printf(";; MSG SIZE rcvd: %u\n", bytes
);
268 puts(";; WARNING -- Some TSIG could not "
271 if ((key
== NULL
) && (keysecret
[0] != 0)) {
272 puts(";; WARNING -- TSIG key was not used.");
275 } else if (query
->lookup
->identify
&& !short_form
) {
276 diff
= isc_time_microdiff(&now
, &query
->time_sent
);
277 printf(";; Received %" ISC_PRINT_QUADFORMAT
"u bytes "
278 "from %s(%s) in %d ms\n\n",
279 query
->lookup
->doing_xfr
?
280 query
->byte_count
: (isc_uint64_t
)bytes
,
281 fromtext
, query
->servname
,
287 * Callback from dighost.c to print that it is trying a server.
292 trying(char *frm
, dig_lookup_t
*lookup
) {
298 * Internal print routine used to print short form replies.
301 say_message(dns_rdata_t
*rdata
, dig_query_t
*query
, isc_buffer_t
*buf
) {
305 char store
[sizeof("12345678901234567890")];
307 if (query
->lookup
->trace
|| query
->lookup
->ns_search_only
) {
308 result
= dns_rdatatype_totext(rdata
->type
, buf
);
309 if (result
!= ISC_R_SUCCESS
)
311 ADD_STRING(buf
, " ");
313 result
= dns_rdata_totext(rdata
, NULL
, buf
);
314 check_result(result
, "dns_rdata_totext");
315 if (query
->lookup
->identify
) {
317 diff
= isc_time_microdiff(&now
, &query
->time_sent
);
318 ADD_STRING(buf
, " from server ");
319 ADD_STRING(buf
, query
->servname
);
320 snprintf(store
, 19, " in %d ms.", (int)diff
/1000);
321 ADD_STRING(buf
, store
);
323 ADD_STRING(buf
, "\n");
324 return (ISC_R_SUCCESS
);
328 * short_form message print handler. Calls above say_message()
331 short_answer(dns_message_t
*msg
, dns_messagetextflag_t flags
,
332 isc_buffer_t
*buf
, dig_query_t
*query
)
335 dns_rdataset_t
*rdataset
;
337 isc_result_t result
, loopresult
;
338 dns_name_t empty_name
;
340 dns_rdata_t rdata
= DNS_RDATA_INIT
;
344 dns_name_init(&empty_name
, NULL
);
345 result
= dns_message_firstname(msg
, DNS_SECTION_ANSWER
);
346 if (result
== ISC_R_NOMORE
)
347 return (ISC_R_SUCCESS
);
348 else if (result
!= ISC_R_SUCCESS
)
353 dns_message_currentname(msg
, DNS_SECTION_ANSWER
, &name
);
355 isc_buffer_init(&target
, t
, sizeof(t
));
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 check_result(result
, "say_message");
366 loopresult
= dns_rdataset_next(rdataset
);
367 dns_rdata_reset(&rdata
);
370 result
= dns_message_nextname(msg
, DNS_SECTION_ANSWER
);
371 if (result
== ISC_R_NOMORE
)
373 else if (result
!= ISC_R_SUCCESS
)
377 return (ISC_R_SUCCESS
);
381 printrdataset(dns_name_t
*owner_name
, dns_rdataset_t
*rdataset
,
382 isc_buffer_t
*target
)
385 dns_master_style_t
*style
= NULL
;
386 unsigned int styleflags
= 0;
388 if (rdataset
== NULL
|| owner_name
== NULL
|| target
== NULL
)
391 styleflags
|= DNS_STYLEFLAG_REL_OWNER
;
393 styleflags
|= DNS_STYLEFLAG_NO_TTL
;
395 styleflags
|= DNS_STYLEFLAG_NO_CLASS
;
397 styleflags
|= DNS_STYLEFLAG_OMIT_OWNER
;
398 styleflags
|= DNS_STYLEFLAG_OMIT_CLASS
;
399 styleflags
|= DNS_STYLEFLAG_REL_DATA
;
400 styleflags
|= DNS_STYLEFLAG_OMIT_TTL
;
401 styleflags
|= DNS_STYLEFLAG_TTL
;
402 styleflags
|= DNS_STYLEFLAG_MULTILINE
;
403 styleflags
|= DNS_STYLEFLAG_COMMENT
;
405 if (multiline
|| (nottl
&& noclass
))
406 result
= dns_master_stylecreate(&style
, styleflags
,
407 24, 24, 24, 32, 80, 8, mctx
);
408 else if (nottl
|| noclass
)
409 result
= dns_master_stylecreate(&style
, styleflags
,
410 24, 24, 32, 40, 80, 8, mctx
);
412 result
= dns_master_stylecreate(&style
, styleflags
,
413 24, 32, 40, 48, 80, 8, mctx
);
414 check_result(result
, "dns_master_stylecreate");
416 result
= dns_master_rdatasettotext(owner_name
, rdataset
, style
, target
);
419 dns_master_styledestroy(&style
, mctx
);
426 * Callback from dighost.c to print the reply from a server
429 printmessage(dig_query_t
*query
, dns_message_t
*msg
, isc_boolean_t headers
) {
431 dns_messagetextflag_t flags
;
432 isc_buffer_t
*buf
= NULL
;
433 unsigned int len
= OUTPUTBUF
;
434 dns_master_style_t
*style
= NULL
;
435 unsigned int styleflags
= 0;
437 styleflags
|= DNS_STYLEFLAG_REL_OWNER
;
439 styleflags
|= DNS_STYLEFLAG_NO_TTL
;
441 styleflags
|= DNS_STYLEFLAG_NO_CLASS
;
443 styleflags
|= DNS_STYLEFLAG_OMIT_OWNER
;
444 styleflags
|= DNS_STYLEFLAG_OMIT_CLASS
;
445 styleflags
|= DNS_STYLEFLAG_REL_DATA
;
446 styleflags
|= DNS_STYLEFLAG_OMIT_TTL
;
447 styleflags
|= DNS_STYLEFLAG_TTL
;
448 styleflags
|= DNS_STYLEFLAG_MULTILINE
;
449 styleflags
|= DNS_STYLEFLAG_COMMENT
;
451 if (multiline
|| (nottl
&& noclass
))
452 result
= dns_master_stylecreate(&style
, styleflags
,
453 24, 24, 24, 32, 80, 8, mctx
);
454 else if (nottl
|| noclass
)
455 result
= dns_master_stylecreate(&style
, styleflags
,
456 24, 24, 32, 40, 80, 8, mctx
);
458 result
= dns_master_stylecreate(&style
, styleflags
,
459 24, 32, 40, 48, 80, 8, mctx
);
460 check_result(result
, "dns_master_stylecreate");
462 if (query
->lookup
->cmdline
[0] != 0) {
464 fputs(query
->lookup
->cmdline
, stdout
);
465 query
->lookup
->cmdline
[0]=0;
467 debug("printmessage(%s %s %s)", headers
? "headers" : "noheaders",
468 query
->lookup
->comments
? "comments" : "nocomments",
469 short_form
? "short_form" : "long_form");
473 flags
|= DNS_MESSAGETEXTFLAG_NOHEADERS
;
474 flags
|= DNS_MESSAGETEXTFLAG_NOCOMMENTS
;
476 if (!query
->lookup
->comments
)
477 flags
|= DNS_MESSAGETEXTFLAG_NOCOMMENTS
;
479 result
= ISC_R_SUCCESS
;
481 result
= isc_buffer_allocate(mctx
, &buf
, len
);
482 check_result(result
, "isc_buffer_allocate");
484 if (query
->lookup
->comments
&& !short_form
) {
485 if (query
->lookup
->cmdline
[0] != 0)
486 printf("; %s\n", query
->lookup
->cmdline
);
487 if (msg
== query
->lookup
->sendmsg
)
488 printf(";; Sending:\n");
490 printf(";; Got answer:\n");
493 printf(";; ->>HEADER<<- opcode: %s, status: %s, "
495 opcodetext
[msg
->opcode
],
496 rcode_totext(msg
->rcode
),
499 if ((msg
->flags
& DNS_MESSAGEFLAG_QR
) != 0)
501 if ((msg
->flags
& DNS_MESSAGEFLAG_AA
) != 0)
503 if ((msg
->flags
& DNS_MESSAGEFLAG_TC
) != 0)
505 if ((msg
->flags
& DNS_MESSAGEFLAG_RD
) != 0)
507 if ((msg
->flags
& DNS_MESSAGEFLAG_RA
) != 0)
509 if ((msg
->flags
& DNS_MESSAGEFLAG_AD
) != 0)
511 if ((msg
->flags
& DNS_MESSAGEFLAG_CD
) != 0)
514 printf("; QUERY: %u, ANSWER: %u, "
515 "AUTHORITY: %u, ADDITIONAL: %u\n",
516 msg
->counts
[DNS_SECTION_QUESTION
],
517 msg
->counts
[DNS_SECTION_ANSWER
],
518 msg
->counts
[DNS_SECTION_AUTHORITY
],
519 msg
->counts
[DNS_SECTION_ADDITIONAL
]);
521 if (msg
!= query
->lookup
->sendmsg
&&
522 (msg
->flags
& DNS_MESSAGEFLAG_RD
) != 0 &&
523 (msg
->flags
& DNS_MESSAGEFLAG_RA
) == 0)
524 printf(";; WARNING: recursion requested "
525 "but not available\n");
527 if (msg
!= query
->lookup
->sendmsg
&& extrabytes
!= 0U)
528 printf(";; WARNING: Messages has %u extra byte%s at "
529 "end\n", extrabytes
, extrabytes
!= 0 ? "s" : "");
534 if (query
->lookup
->comments
&& headers
&& !short_form
) {
535 result
= dns_message_pseudosectiontotext(msg
,
536 DNS_PSEUDOSECTION_OPT
,
538 if (result
== ISC_R_NOSPACE
) {
541 isc_buffer_free(&buf
);
542 result
= isc_buffer_allocate(mctx
, &buf
, len
);
543 if (result
== ISC_R_SUCCESS
)
544 goto repopulate_buffer
;
549 "dns_message_pseudosectiontotext");
552 if (query
->lookup
->section_question
&& headers
) {
554 result
= dns_message_sectiontotext(msg
,
555 DNS_SECTION_QUESTION
,
557 if (result
== ISC_R_NOSPACE
)
559 check_result(result
, "dns_message_sectiontotext");
562 if (query
->lookup
->section_answer
) {
564 result
= dns_message_sectiontotext(msg
,
567 if (result
== ISC_R_NOSPACE
)
569 check_result(result
, "dns_message_sectiontotext");
571 result
= short_answer(msg
, flags
, buf
, query
);
572 if (result
== ISC_R_NOSPACE
)
574 check_result(result
, "short_answer");
577 if (query
->lookup
->section_authority
) {
579 result
= dns_message_sectiontotext(msg
,
580 DNS_SECTION_AUTHORITY
,
582 if (result
== ISC_R_NOSPACE
)
584 check_result(result
, "dns_message_sectiontotext");
587 if (query
->lookup
->section_additional
) {
589 result
= dns_message_sectiontotext(msg
,
590 DNS_SECTION_ADDITIONAL
,
592 if (result
== ISC_R_NOSPACE
)
594 check_result(result
, "dns_message_sectiontotext");
596 * Only print the signature on the first record.
599 result
= dns_message_pseudosectiontotext(
601 DNS_PSEUDOSECTION_TSIG
,
603 if (result
== ISC_R_NOSPACE
)
606 "dns_message_pseudosectiontotext");
607 result
= dns_message_pseudosectiontotext(
609 DNS_PSEUDOSECTION_SIG0
,
611 if (result
== ISC_R_NOSPACE
)
614 "dns_message_pseudosectiontotext");
619 if (headers
&& query
->lookup
->comments
&& !short_form
)
622 printf("%.*s", (int)isc_buffer_usedlength(buf
),
623 (char *)isc_buffer_base(buf
));
624 isc_buffer_free(&buf
);
628 dns_master_styledestroy(&style
, mctx
);
633 * print the greeting message when the program first starts up.
636 printgreeting(int argc
, char **argv
, dig_lookup_t
*lookup
) {
639 static isc_boolean_t first
= ISC_TRUE
;
643 lookup
->cmdline
[sizeof(lookup
->cmdline
) - 1] = 0;
644 snprintf(lookup
->cmdline
, sizeof(lookup
->cmdline
),
645 "%s; <<>> DiG " VERSION
" <<>>",
649 snprintf(append
, sizeof(append
), " %s", argv
[i
++]);
650 remaining
= sizeof(lookup
->cmdline
) -
651 strlen(lookup
->cmdline
) - 1;
652 strncat(lookup
->cmdline
, append
, remaining
);
654 remaining
= sizeof(lookup
->cmdline
) -
655 strlen(lookup
->cmdline
) - 1;
656 strncat(lookup
->cmdline
, "\n", remaining
);
657 if (first
&& addresscount
!= 0) {
658 snprintf(append
, sizeof(append
),
659 "; (%d server%s found)\n",
661 addresscount
> 1 ? "s" : "");
662 remaining
= sizeof(lookup
->cmdline
) -
663 strlen(lookup
->cmdline
) - 1;
664 strncat(lookup
->cmdline
, append
, remaining
);
667 snprintf(append
, sizeof(append
),
668 ";; global options:%s%s\n",
669 short_form
? " +short" : "",
670 printcmd
? " +cmd" : "");
672 remaining
= sizeof(lookup
->cmdline
) -
673 strlen(lookup
->cmdline
) - 1;
674 strncat(lookup
->cmdline
, append
, remaining
);
680 * We're not using isc_commandline_parse() here since the command line
681 * syntax of dig is quite a bit different from that which can be described
687 plus_option(char *option
, isc_boolean_t is_batchfile
,
688 dig_lookup_t
*lookup
)
691 char option_store
[256];
692 char *cmd
, *value
, *ptr
;
694 isc_boolean_t state
= ISC_TRUE
;
699 strncpy(option_store
, option
, sizeof(option_store
));
700 option_store
[sizeof(option_store
)-1]=0;
702 cmd
= next_token(&ptr
,"=");
704 printf(";; Invalid option %s\n", option_store
);
708 if (strncasecmp(cmd
, "no", 2)==0) {
713 #define FULLCHECK(A) \
715 size_t _l = strlen(cmd); \
716 if (_l >= sizeof(A) || strncasecmp(cmd, A, _l) != 0) \
717 goto invalid_option; \
719 #define FULLCHECK2(A, B) \
721 size_t _l = strlen(cmd); \
722 if ((_l >= sizeof(A) || strncasecmp(cmd, A, _l) != 0) && \
723 (_l >= sizeof(B) || strncasecmp(cmd, B, _l) != 0)) \
724 goto invalid_option; \
730 case 'a': /* aaonly / aaflag */
731 FULLCHECK2("aaonly", "aaflag");
732 lookup
->aaonly
= state
;
736 case 'd': /* additional */
737 FULLCHECK("additional");
738 lookup
->section_additional
= state
;
740 case 'f': /* adflag */
741 case '\0': /* +ad is a synonym for +adflag */
743 lookup
->adflag
= state
;
751 lookup
->section_question
= state
;
752 lookup
->section_authority
= state
;
753 lookup
->section_answer
= state
;
754 lookup
->section_additional
= state
;
755 lookup
->comments
= state
;
756 lookup
->stats
= state
;
759 case 'n': /* answer */
761 lookup
->section_answer
= state
;
763 case 'u': /* authority */
764 FULLCHECK("authority");
765 lookup
->section_authority
= state
;
773 case 'e':/* besteffort */
774 FULLCHECK("besteffort");
775 lookup
->besteffort
= state
;
777 case 'u':/* bufsize */
778 FULLCHECK("bufsize");
783 result
= parse_uint(&num
, value
, COMMSIZE
,
785 if (result
!= ISC_R_SUCCESS
)
786 fatal("Couldn't parse buffer size");
787 lookup
->udpsize
= num
;
795 case 'd':/* cdflag */
797 case 'f': /* cdflag */
798 case '\0': /* +cd is a synonym for +cdflag */
800 lookup
->cdflag
= state
;
808 noclass
= ISC_TF(!state
);
814 case 'o': /* comments */
815 FULLCHECK("comments");
816 lookup
->comments
= state
;
817 if (lookup
== default_lookup
)
826 case 'e': /* defname */
827 FULLCHECK("defname");
828 if (!lookup
->trace
) {
832 case 'n': /* dnssec */
834 if (state
&& lookup
->edns
== -1)
836 lookup
->dnssec
= state
;
838 case 'o': /* domain */
844 strncpy(domainopt
, value
, sizeof(domainopt
));
845 domainopt
[sizeof(domainopt
)-1] = '\0';
859 result
= parse_uint(&num
, value
, 255, "edns");
860 if (result
!= ISC_R_SUCCESS
)
861 fatal("Couldn't parse edns");
866 lookup
->servfail_stops
= state
;
870 case 'd': /* identify */
871 FULLCHECK("identify");
872 lookup
->identify
= state
;
874 case 'g': /* ignore */
875 default: /* Inherits default for compatibility */
877 lookup
->ignore
= ISC_TRUE
;
880 case 'm': /* multiline */
881 FULLCHECK("multiline");
886 case 'd': /* ndots */
892 result
= parse_uint(&num
, value
, MAXNDOTS
, "ndots");
893 if (result
!= ISC_R_SUCCESS
)
894 fatal("Couldn't parse ndots");
901 if (state
&& lookup
->edns
== -1)
903 lookup
->nsid
= state
;
905 case 's': /* nssearch */
906 FULLCHECK("nssearch");
907 lookup
->ns_search_only
= state
;
909 lookup
->trace_root
= ISC_TRUE
;
910 lookup
->recurse
= ISC_TRUE
;
911 lookup
->identify
= ISC_TRUE
;
912 lookup
->stats
= ISC_FALSE
;
913 lookup
->comments
= ISC_FALSE
;
914 lookup
->section_additional
= ISC_FALSE
;
915 lookup
->section_authority
= ISC_FALSE
;
916 lookup
->section_question
= ISC_FALSE
;
917 lookup
->rdtype
= dns_rdatatype_ns
;
918 lookup
->rdtypeset
= ISC_TRUE
;
919 short_form
= ISC_TRUE
;
936 case 'u': /* question */
937 FULLCHECK("question");
938 lookup
->section_question
= state
;
939 if (lookup
== default_lookup
)
950 case 'c': /* recurse */
951 FULLCHECK("recurse");
952 lookup
->recurse
= state
;
954 case 't': /* retry / retries */
955 FULLCHECK2("retry", "retries");
960 result
= parse_uint(&lookup
->retries
, value
,
961 MAXTRIES
- 1, "retries");
962 if (result
!= ISC_R_SUCCESS
)
963 fatal("Couldn't parse retries");
976 case 'e': /* search */
978 if (!lookup
->trace
) {
986 case 'r': /* short */
990 printcmd
= ISC_FALSE
;
991 lookup
->section_additional
= ISC_FALSE
;
992 lookup
->section_answer
= ISC_TRUE
;
993 lookup
->section_authority
= ISC_FALSE
;
994 lookup
->section_question
= ISC_FALSE
;
995 lookup
->comments
= ISC_FALSE
;
996 lookup
->stats
= ISC_FALSE
;
999 case 'w': /* showsearch */
1000 FULLCHECK("showsearch");
1001 if (!lookup
->trace
) {
1007 goto invalid_option
;
1011 case 'i': /* sigchase */
1012 FULLCHECK("sigchase");
1013 lookup
->sigchase
= state
;
1014 if (lookup
->sigchase
)
1015 lookup
->dnssec
= ISC_TRUE
;
1018 case 't': /* stats */
1020 lookup
->stats
= state
;
1023 goto invalid_option
;
1031 lookup
->tcp_mode
= state
;
1033 case 'i': /* timeout */
1034 FULLCHECK("timeout");
1038 goto invalid_option
;
1039 result
= parse_uint(&timeout
, value
, MAXTIMEOUT
,
1041 if (result
!= ISC_R_SUCCESS
)
1042 fatal("Couldn't parse timeout");
1047 case 'o': /* topdown */
1048 FULLCHECK("topdown");
1049 lookup
->do_topdown
= state
;
1054 case 'a': /* trace */
1056 lookup
->trace
= state
;
1057 lookup
->trace_root
= state
;
1059 lookup
->recurse
= ISC_FALSE
;
1060 lookup
->identify
= ISC_TRUE
;
1061 lookup
->comments
= ISC_FALSE
;
1062 lookup
->stats
= ISC_FALSE
;
1063 lookup
->section_additional
= ISC_FALSE
;
1064 lookup
->section_authority
= ISC_TRUE
;
1065 lookup
->section_question
= ISC_FALSE
;
1066 usesearch
= ISC_FALSE
;
1069 case 'i': /* tries */
1074 goto invalid_option
;
1075 result
= parse_uint(&lookup
->retries
, value
,
1077 if (result
!= ISC_R_SUCCESS
)
1078 fatal("Couldn't parse tries");
1079 if (lookup
->retries
== 0)
1080 lookup
->retries
= 1;
1083 case 'u': /* trusted-key */
1084 FULLCHECK("trusted-key");
1088 goto invalid_option
;
1089 n
= strlcpy(trustedkey
, ptr
,
1090 sizeof(trustedkey
));
1091 if (n
>= sizeof(trustedkey
))
1092 fatal("trusted key too large");
1096 goto invalid_option
;
1099 case 't': /* ttlid */
1101 nottl
= ISC_TF(!state
);
1104 goto invalid_option
;
1110 lookup
->tcp_mode
= state
;
1115 fprintf(stderr
, "Invalid option: +%s\n",
1123 * #ISC_TRUE returned if value was used
1125 static const char *single_dash_opts
= "46dhimnv";
1126 static const char *dash_opts
= "46bcdfhikmnptvyx";
1127 static isc_boolean_t
1128 dash_option(char *option
, char *next
, dig_lookup_t
**lookup
,
1129 isc_boolean_t
*open_type_class
, isc_boolean_t
*need_clone
,
1130 isc_boolean_t config_only
, int argc
, char **argv
,
1131 isc_boolean_t
*firstarg
)
1133 char opt
, *value
, *ptr
, *ptr2
, *ptr3
;
1134 isc_result_t result
;
1135 isc_boolean_t value_from_next
;
1136 isc_textregion_t tr
;
1137 dns_rdatatype_t rdtype
;
1138 dns_rdataclass_t rdclass
;
1139 char textname
[MXNAME
];
1141 struct in6_addr in6
;
1146 while (strpbrk(option
, single_dash_opts
) == &option
[0]) {
1148 * Since the -[46dhimnv] options do not take an argument,
1149 * account for them (in any number and/or combination)
1150 * if they appear as the first character(s) of a q-opt.
1156 isc_net_disableipv6();
1157 have_ipv6
= ISC_FALSE
;
1159 fatal("can't find IPv4 networking");
1166 isc_net_disableipv4();
1167 have_ipv4
= ISC_FALSE
;
1169 fatal("can't find IPv6 networking");
1175 ptr
= strpbrk(&option
[1], dash_opts
);
1176 if (ptr
!= &option
[1]) {
1179 debugging
= ISC_TRUE
;
1182 debugging
= ISC_TRUE
;
1191 case 'm': /* memdebug */
1192 /* memdebug is handled in preparse_args() */
1202 if (strlen(option
) > 1U)
1203 option
= &option
[1];
1208 if (strlen(option
) > 1U) {
1209 value_from_next
= ISC_FALSE
;
1212 value_from_next
= ISC_TRUE
;
1216 goto invalid_option
;
1219 hash
= strchr(value
, '#');
1221 result
= parse_uint(&num
, hash
+ 1, MAXPORT
,
1223 if (result
!= ISC_R_SUCCESS
)
1224 fatal("Couldn't parse port number");
1229 if (have_ipv6
&& inet_pton(AF_INET6
, value
, &in6
) == 1) {
1230 isc_sockaddr_fromin6(&bind_address
, &in6
, srcport
);
1231 isc_net_disableipv4();
1232 } else if (have_ipv4
&& inet_pton(AF_INET
, value
, &in4
) == 1) {
1233 isc_sockaddr_fromin(&bind_address
, &in4
, srcport
);
1234 isc_net_disableipv6();
1238 fatal("invalid address %s", value
);
1242 specified_source
= ISC_TRUE
;
1243 return (value_from_next
);
1245 if ((*lookup
)->rdclassset
) {
1246 fprintf(stderr
, ";; Warning, extra class option\n");
1248 *open_type_class
= ISC_FALSE
;
1250 tr
.length
= strlen(value
);
1251 result
= dns_rdataclass_fromtext(&rdclass
,
1252 (isc_textregion_t
*)&tr
);
1253 if (result
== ISC_R_SUCCESS
) {
1254 (*lookup
)->rdclass
= rdclass
;
1255 (*lookup
)->rdclassset
= ISC_TRUE
;
1257 fprintf(stderr
, ";; Warning, ignoring "
1258 "invalid class %s\n",
1260 return (value_from_next
);
1263 return (value_from_next
);
1265 strncpy(keyfile
, value
, sizeof(keyfile
));
1266 keyfile
[sizeof(keyfile
)-1]=0;
1267 return (value_from_next
);
1269 result
= parse_uint(&num
, value
, MAXPORT
, "port number");
1270 if (result
!= ISC_R_SUCCESS
)
1271 fatal("Couldn't parse port number");
1273 return (value_from_next
);
1277 (*lookup
) = clone_lookup(default_lookup
,
1279 *need_clone
= ISC_TRUE
;
1280 strncpy((*lookup
)->textname
, value
,
1281 sizeof((*lookup
)->textname
));
1282 (*lookup
)->textname
[sizeof((*lookup
)->textname
)-1]=0;
1283 (*lookup
)->trace_root
= ISC_TF((*lookup
)->trace
||
1284 (*lookup
)->ns_search_only
);
1285 (*lookup
)->new_search
= ISC_TRUE
;
1287 printgreeting(argc
, argv
, *lookup
);
1288 *firstarg
= ISC_FALSE
;
1290 ISC_LIST_APPEND(lookup_list
, (*lookup
), link
);
1291 debug("looking up %s", (*lookup
)->textname
);
1293 return (value_from_next
);
1295 *open_type_class
= ISC_FALSE
;
1296 if (strncasecmp(value
, "ixfr=", 5) == 0) {
1297 rdtype
= dns_rdatatype_ixfr
;
1298 result
= ISC_R_SUCCESS
;
1301 tr
.length
= strlen(value
);
1302 result
= dns_rdatatype_fromtext(&rdtype
,
1303 (isc_textregion_t
*)&tr
);
1304 if (result
== ISC_R_SUCCESS
&&
1305 rdtype
== dns_rdatatype_ixfr
) {
1306 result
= DNS_R_UNKNOWN
;
1309 if (result
== ISC_R_SUCCESS
) {
1310 if ((*lookup
)->rdtypeset
) {
1311 fprintf(stderr
, ";; Warning, "
1312 "extra type option\n");
1314 if (rdtype
== dns_rdatatype_ixfr
) {
1315 isc_uint32_t serial
;
1316 (*lookup
)->rdtype
= dns_rdatatype_ixfr
;
1317 (*lookup
)->rdtypeset
= ISC_TRUE
;
1318 result
= parse_uint(&serial
, &value
[5],
1319 MAXSERIAL
, "serial number");
1320 if (result
!= ISC_R_SUCCESS
)
1321 fatal("Couldn't parse serial number");
1322 (*lookup
)->ixfr_serial
= serial
;
1323 (*lookup
)->section_question
= plusquest
;
1324 (*lookup
)->comments
= pluscomm
;
1325 (*lookup
)->tcp_mode
= ISC_TRUE
;
1327 (*lookup
)->rdtype
= rdtype
;
1328 (*lookup
)->rdtypeset
= ISC_TRUE
;
1329 if (rdtype
== dns_rdatatype_axfr
) {
1330 (*lookup
)->section_question
= plusquest
;
1331 (*lookup
)->comments
= pluscomm
;
1333 (*lookup
)->ixfr_serial
= ISC_FALSE
;
1336 fprintf(stderr
, ";; Warning, ignoring "
1337 "invalid type %s\n",
1339 return (value_from_next
);
1341 ptr
= next_token(&value
,":"); /* hmac type or name */
1345 ptr2
= next_token(&value
, ":"); /* name or secret */
1348 ptr3
= next_token(&value
,":"); /* secret or NULL */
1354 hmacname
= DNS_TSIG_HMACMD5_NAME
;
1357 strncpy(keynametext
, ptr
, sizeof(keynametext
));
1358 keynametext
[sizeof(keynametext
)-1]=0;
1359 strncpy(keysecret
, ptr2
, sizeof(keysecret
));
1360 keysecret
[sizeof(keysecret
)-1]=0;
1361 return (value_from_next
);
1364 *lookup
= clone_lookup(default_lookup
, ISC_TRUE
);
1365 *need_clone
= ISC_TRUE
;
1366 if (get_reverse(textname
, sizeof(textname
), value
,
1367 ip6_int
, ISC_FALSE
) == ISC_R_SUCCESS
) {
1368 strncpy((*lookup
)->textname
, textname
,
1369 sizeof((*lookup
)->textname
));
1370 debug("looking up %s", (*lookup
)->textname
);
1371 (*lookup
)->trace_root
= ISC_TF((*lookup
)->trace
||
1372 (*lookup
)->ns_search_only
);
1373 (*lookup
)->ip6_int
= ip6_int
;
1374 if (!(*lookup
)->rdtypeset
)
1375 (*lookup
)->rdtype
= dns_rdatatype_ptr
;
1376 if (!(*lookup
)->rdclassset
)
1377 (*lookup
)->rdclass
= dns_rdataclass_in
;
1378 (*lookup
)->new_search
= ISC_TRUE
;
1380 printgreeting(argc
, argv
, *lookup
);
1381 *firstarg
= ISC_FALSE
;
1383 ISC_LIST_APPEND(lookup_list
, *lookup
, link
);
1385 fprintf(stderr
, "Invalid IP address %s\n", value
);
1388 return (value_from_next
);
1391 fprintf(stderr
, "Invalid option: -%s\n", option
);
1399 * Because we may be trying to do memory allocation recording, we're going
1400 * to need to parse the arguments for the -m *before* we start the main
1401 * argument parsing routine.
1403 * I'd prefer not to have to do this, but I am not quite sure how else to
1404 * fix the problem. Argument parsing in dig involves memory allocation
1405 * by its nature, so it can't be done in the main argument parser.
1408 preparse_args(int argc
, char **argv
) {
1415 for (rc
--, rv
++; rc
> 0; rc
--, rv
++) {
1416 if (rv
[0][0] != '-')
1419 while (strpbrk(option
, single_dash_opts
) == &option
[0]) {
1420 if (option
[0] == 'm') {
1421 memdebugging
= ISC_TRUE
;
1422 isc_mem_debugging
= ISC_MEM_DEBUGTRACE
|
1423 ISC_MEM_DEBUGRECORD
;
1426 option
= &option
[1];
1432 getaddresses(dig_lookup_t
*lookup
, const char *host
) {
1433 isc_result_t result
;
1434 isc_sockaddr_t sockaddrs
[DIG_MAX_ADDRESSES
];
1435 isc_netaddr_t netaddr
;
1438 char tmp
[ISC_NETADDR_FORMATSIZE
];
1440 result
= bind9_getaddresses(host
, 0, sockaddrs
,
1441 DIG_MAX_ADDRESSES
, &count
);
1442 if (result
!= ISC_R_SUCCESS
)
1443 fatal("couldn't get address for '%s': %s",
1444 host
, isc_result_totext(result
));
1446 for (i
= 0; i
< count
; i
++) {
1447 isc_netaddr_fromsockaddr(&netaddr
, &sockaddrs
[i
]);
1448 isc_netaddr_format(&netaddr
, tmp
, sizeof(tmp
));
1449 srv
= make_server(tmp
, host
);
1450 ISC_LIST_APPEND(lookup
->my_server_list
, srv
, link
);
1452 addresscount
= count
;
1456 parse_args(isc_boolean_t is_batchfile
, isc_boolean_t config_only
,
1457 int argc
, char **argv
) {
1458 isc_result_t result
;
1459 isc_textregion_t tr
;
1460 isc_boolean_t firstarg
= ISC_TRUE
;
1461 dig_lookup_t
*lookup
= NULL
;
1462 dns_rdatatype_t rdtype
;
1463 dns_rdataclass_t rdclass
;
1464 isc_boolean_t open_type_class
= ISC_TRUE
;
1465 char batchline
[MXNAME
];
1476 isc_boolean_t need_clone
= ISC_TRUE
;
1479 * The semantics for parsing the args is a bit complex; if
1480 * we don't have a host yet, make the arg apply globally,
1481 * otherwise make it apply to the latest host. This is
1482 * a bit different than the previous versions, but should
1483 * form a consistent user interface.
1485 * First, create a "default lookup" which won't actually be used
1486 * anywhere, except for cloning into new lookups
1489 debug("parse_args()");
1490 if (!is_batchfile
) {
1491 debug("making new lookup");
1492 default_lookup
= make_empty_lookup();
1496 * Treat ${HOME}/.digrc as a special batchfile
1498 INSIST(batchfp
== NULL
);
1499 homedir
= getenv("HOME");
1500 if (homedir
!= NULL
) {
1502 n
= snprintf(rcfile
, sizeof(rcfile
), "%s/.digrc",
1504 if (n
< sizeof(rcfile
))
1505 batchfp
= fopen(rcfile
, "r");
1507 if (batchfp
!= NULL
) {
1508 while (fgets(batchline
, sizeof(batchline
),
1510 debug("config line %s", batchline
);
1513 bargv
[bargc
] = next_token(&input
, " \t\r\n");
1514 while ((bargv
[bargc
] != NULL
) &&
1518 next_token(&input
, " \t\r\n");
1524 for(i
= 0; i
< bargc
; i
++)
1525 debug(".digrc argv %d: %s",
1527 parse_args(ISC_TRUE
, ISC_TRUE
, bargc
,
1535 if (is_batchfile
&& !config_only
) {
1536 /* Processing '-f batchfile'. */
1537 lookup
= clone_lookup(default_lookup
, ISC_TRUE
);
1538 need_clone
= ISC_FALSE
;
1540 lookup
= default_lookup
;
1544 for (rc
--, rv
++; rc
> 0; rc
--, rv
++) {
1545 debug("main parsing %s", rv
[0]);
1546 if (strncmp(rv
[0], "%", 1) == 0)
1548 if (strncmp(rv
[0], "@", 1) == 0) {
1549 getaddresses(lookup
, &rv
[0][1]);
1550 } else if (rv
[0][0] == '+') {
1551 plus_option(&rv
[0][1], is_batchfile
,
1553 } else if (rv
[0][0] == '-') {
1555 if (dash_option(&rv
[0][1], NULL
,
1556 &lookup
, &open_type_class
,
1557 &need_clone
, config_only
,
1558 argc
, argv
, &firstarg
)) {
1563 if (dash_option(&rv
[0][1], rv
[1],
1564 &lookup
, &open_type_class
,
1565 &need_clone
, config_only
,
1566 argc
, argv
, &firstarg
)) {
1573 * Anything which isn't an option
1575 if (open_type_class
) {
1576 if (strncasecmp(rv
[0], "ixfr=", 5) == 0) {
1577 rdtype
= dns_rdatatype_ixfr
;
1578 result
= ISC_R_SUCCESS
;
1581 tr
.length
= strlen(rv
[0]);
1582 result
= dns_rdatatype_fromtext(&rdtype
,
1583 (isc_textregion_t
*)&tr
);
1584 if (result
== ISC_R_SUCCESS
&&
1585 rdtype
== dns_rdatatype_ixfr
) {
1586 result
= DNS_R_UNKNOWN
;
1587 fprintf(stderr
, ";; Warning, "
1593 if (result
== ISC_R_SUCCESS
) {
1594 if (lookup
->rdtypeset
) {
1595 fprintf(stderr
, ";; Warning, "
1596 "extra type option\n");
1598 if (rdtype
== dns_rdatatype_ixfr
) {
1599 isc_uint32_t serial
;
1602 lookup
->rdtypeset
= ISC_TRUE
;
1603 result
= parse_uint(&serial
,
1607 if (result
!= ISC_R_SUCCESS
)
1608 fatal("Couldn't parse "
1610 lookup
->ixfr_serial
= serial
;
1611 lookup
->section_question
=
1613 lookup
->comments
= pluscomm
;
1614 lookup
->tcp_mode
= ISC_TRUE
;
1616 lookup
->rdtype
= rdtype
;
1617 lookup
->rdtypeset
= ISC_TRUE
;
1619 dns_rdatatype_axfr
) {
1620 lookup
->section_question
=
1622 lookup
->comments
= pluscomm
;
1624 lookup
->ixfr_serial
= ISC_FALSE
;
1628 result
= dns_rdataclass_fromtext(&rdclass
,
1629 (isc_textregion_t
*)&tr
);
1630 if (result
== ISC_R_SUCCESS
) {
1631 if (lookup
->rdclassset
) {
1632 fprintf(stderr
, ";; Warning, "
1633 "extra class option\n");
1635 lookup
->rdclass
= rdclass
;
1636 lookup
->rdclassset
= ISC_TRUE
;
1643 lookup
= clone_lookup(default_lookup
,
1645 need_clone
= ISC_TRUE
;
1646 strncpy(lookup
->textname
, rv
[0],
1647 sizeof(lookup
->textname
));
1648 lookup
->textname
[sizeof(lookup
->textname
)-1]=0;
1649 lookup
->trace_root
= ISC_TF(lookup
->trace
||
1650 lookup
->ns_search_only
);
1651 lookup
->new_search
= ISC_TRUE
;
1653 printgreeting(argc
, argv
, lookup
);
1654 firstarg
= ISC_FALSE
;
1656 ISC_LIST_APPEND(lookup_list
, lookup
, link
);
1657 debug("looking up %s", lookup
->textname
);
1659 /* XXX Error message */
1664 * If we have a batchfile, seed the lookup list with the
1665 * first entry, then trust the callback in dighost_shutdown
1668 if ((batchname
!= NULL
) && !(is_batchfile
)) {
1669 if (strcmp(batchname
, "-") == 0)
1672 batchfp
= fopen(batchname
, "r");
1673 if (batchfp
== NULL
) {
1677 fatal("couldn't open specified batch file");
1679 /* XXX Remove code dup from shutdown code */
1681 if (fgets(batchline
, sizeof(batchline
), batchfp
) != 0) {
1683 debug("batch line %s", batchline
);
1684 if (batchline
[0] == '\r' || batchline
[0] == '\n'
1685 || batchline
[0] == '#' || batchline
[0] == ';')
1688 bargv
[bargc
] = next_token(&input
, " \t\r\n");
1689 while ((bargv
[bargc
] != NULL
) && (bargc
< 14)) {
1691 bargv
[bargc
] = next_token(&input
, " \t\r\n");
1697 for(i
= 0; i
< bargc
; i
++)
1698 debug("batch argv %d: %s", i
, bargv
[i
]);
1699 parse_args(ISC_TRUE
, ISC_FALSE
, bargc
, (char **)bargv
);
1705 * If no lookup specified, search for root
1707 if ((lookup_list
.head
== NULL
) && !config_only
) {
1709 lookup
= clone_lookup(default_lookup
, ISC_TRUE
);
1710 need_clone
= ISC_TRUE
;
1711 lookup
->trace_root
= ISC_TF(lookup
->trace
||
1712 lookup
->ns_search_only
);
1713 lookup
->new_search
= ISC_TRUE
;
1714 strcpy(lookup
->textname
, ".");
1715 lookup
->rdtype
= dns_rdatatype_ns
;
1716 lookup
->rdtypeset
= ISC_TRUE
;
1718 printgreeting(argc
, argv
, lookup
);
1719 firstarg
= ISC_FALSE
;
1721 ISC_LIST_APPEND(lookup_list
, lookup
, link
);
1724 destroy_lookup(lookup
);
1728 * Callback from dighost.c to allow program-specific shutdown code.
1729 * Here, we're possibly reading from a batch file, then shutting down
1730 * for real if there's nothing in the batch file to read.
1733 dighost_shutdown(void) {
1734 char batchline
[MXNAME
];
1740 if (batchname
== NULL
) {
1746 if (feof(batchfp
)) {
1749 if (batchfp
!= stdin
)
1754 if (fgets(batchline
, sizeof(batchline
), batchfp
) != 0) {
1755 debug("batch line %s", batchline
);
1758 bargv
[bargc
] = next_token(&input
, " \t\r\n");
1759 while ((bargv
[bargc
] != NULL
) && (bargc
< 14)) {
1761 bargv
[bargc
] = next_token(&input
, " \t\r\n");
1766 for(i
= 0; i
< bargc
; i
++)
1767 debug("batch argv %d: %s", i
, bargv
[i
]);
1768 parse_args(ISC_TRUE
, ISC_FALSE
, bargc
, (char **)bargv
);
1772 if (batchfp
!= stdin
)
1779 /*% Main processing routine for dig */
1781 main(int argc
, char **argv
) {
1782 isc_result_t result
;
1784 ISC_LIST_INIT(lookup_list
);
1785 ISC_LIST_INIT(server_list
);
1786 ISC_LIST_INIT(search_list
);
1789 preparse_args(argc
, argv
);
1791 result
= isc_app_start();
1792 check_result(result
, "isc_app_start");
1794 parse_args(ISC_FALSE
, ISC_FALSE
, argc
, argv
);
1796 if (domainopt
[0] != '\0') {
1797 set_search_domain(domainopt
);
1798 usesearch
= ISC_TRUE
;
1800 result
= isc_app_onrun(mctx
, global_task
, onrun_callback
, NULL
);
1801 check_result(result
, "isc_app_onrun");
1803 destroy_lookup(default_lookup
);
1804 if (batchname
!= NULL
) {
1805 if (batchfp
!= stdin
)