2 * Copyright (C) 2004-2012 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: nslookup.c,v 1.127.38.2 2011/02/28 01:19:58 tbox Exp $ */
25 #include <isc/buffer.h>
26 #include <isc/commandline.h>
27 #include <isc/event.h>
28 #include <isc/parseint.h>
29 #include <isc/print.h>
30 #include <isc/string.h>
31 #include <isc/timer.h>
34 #include <isc/netaddr.h>
36 #include <dns/message.h>
38 #include <dns/fixedname.h>
39 #include <dns/rdata.h>
40 #include <dns/rdataclass.h>
41 #include <dns/rdataset.h>
42 #include <dns/rdatastruct.h>
43 #include <dns/rdatatype.h>
44 #include <dns/byaddr.h>
48 static isc_boolean_t short_form = ISC_TRUE,
50 identify = ISC_FALSE, stats = ISC_TRUE,
51 comments = ISC_TRUE, section_question = ISC_TRUE,
52 section_answer = ISC_TRUE, section_authority = ISC_TRUE,
53 section_additional = ISC_TRUE, recurse = ISC_TRUE,
54 aaonly = ISC_FALSE, nofail = ISC_TRUE;
56 static isc_boolean_t in_use = ISC_FALSE;
57 static char defclass[MXRD] = "IN";
58 static char deftype[MXRD] = "A";
59 static isc_event_t *global_event = NULL;
60 static int query_error = 1, print_error = 0;
62 static char domainopt[DNS_NAME_MAXTEXT];
64 static const char *rcodetext[] = {
84 static const char *rtypetext[] = {
86 "internet address = ", /* 1 */
87 "nameserver = ", /* 2 */
90 "canonical name = ", /* 5 */
95 "rtype_10 = ", /* 10 */
96 "protocol = ", /* 11 */
100 "mail exchanger = ", /* 15 */
104 "x25 address = ", /* 19 */
105 "isdn address = ", /* 20 */
108 "nsap_ptr = ", /* 23 */
109 "signature = ", /* 24 */
113 "has AAAA address ", /* 28 */
116 "rtype_31 = ", /* 31 */
117 "rtype_32 = ", /* 32 */
118 "service = ", /* 33 */
119 "rtype_34 = ", /* 34 */
123 "v6 address = ", /* 38 */
125 "rtype_40 = ", /* 40 */
126 "optional = " /* 41 */
129 #define N_KNOWN_RRTYPES (sizeof(rtypetext) / sizeof(rtypetext[0]))
131 static void flush_lookup_list(void);
132 static void getinput(isc_task_t *task, isc_event_t *event);
135 rcode_totext(dns_rcode_t rcode)
137 static char buf[sizeof("?65535")];
139 const char *consttext;
143 if (rcode >= (sizeof(rcodetext)/sizeof(rcodetext[0]))) {
144 snprintf(buf, sizeof(buf), "?%u", rcode);
145 totext.deconsttext = buf;
147 totext.consttext = rcodetext[rcode];
148 return totext.deconsttext;
152 dighost_shutdown(void) {
153 isc_event_t *event = global_event;
156 debug("dighost_shutdown()");
163 isc_task_send(global_task, &event);
167 printsoa(dns_rdata_t *rdata) {
170 char namebuf[DNS_NAME_FORMATSIZE];
172 result = dns_rdata_tostruct(rdata, &soa, NULL);
173 check_result(result, "dns_rdata_tostruct");
175 dns_name_format(&soa.origin, namebuf, sizeof(namebuf));
176 printf("\torigin = %s\n", namebuf);
177 dns_name_format(&soa.contact, namebuf, sizeof(namebuf));
178 printf("\tmail addr = %s\n", namebuf);
179 printf("\tserial = %u\n", soa.serial);
180 printf("\trefresh = %u\n", soa.refresh);
181 printf("\tretry = %u\n", soa.retry);
182 printf("\texpire = %u\n", soa.expire);
183 printf("\tminimum = %u\n", soa.minimum);
184 dns_rdata_freestruct(&soa);
188 printa(dns_rdata_t *rdata) {
190 char text[sizeof("255.255.255.255")];
193 isc_buffer_init(&b, text, sizeof(text));
194 result = dns_rdata_totext(rdata, NULL, &b);
195 check_result(result, "dns_rdata_totext");
196 printf("Address: %.*s\n", (int)isc_buffer_usedlength(&b),
197 (char *)isc_buffer_base(&b));
200 /* Just for compatibility : not use in host program */
202 printrdataset(dns_name_t *owner_name, dns_rdataset_t *rdataset,
203 isc_buffer_t *target)
212 printrdata(dns_rdata_t *rdata) {
214 isc_buffer_t *b = NULL;
215 unsigned int size = 1024;
216 isc_boolean_t done = ISC_FALSE;
218 if (rdata->type < N_KNOWN_RRTYPES)
219 printf("%s", rtypetext[rdata->type]);
221 printf("rdata_%d = ", rdata->type);
224 result = isc_buffer_allocate(mctx, &b, size);
225 if (result != ISC_R_SUCCESS)
226 check_result(result, "isc_buffer_allocate");
227 result = dns_rdata_totext(rdata, NULL, b);
228 if (result == ISC_R_SUCCESS) {
229 printf("%.*s\n", (int)isc_buffer_usedlength(b),
230 (char *)isc_buffer_base(b));
232 } else if (result != ISC_R_NOSPACE)
233 check_result(result, "dns_rdata_totext");
240 printsection(dig_query_t *query, dns_message_t *msg, isc_boolean_t headers,
241 dns_section_t section) {
242 isc_result_t result, loopresult;
244 dns_rdataset_t *rdataset = NULL;
245 dns_rdata_t rdata = DNS_RDATA_INIT;
246 char namebuf[DNS_NAME_FORMATSIZE];
251 debug("printsection()");
253 result = dns_message_firstname(msg, section);
254 if (result == ISC_R_NOMORE)
255 return (ISC_R_SUCCESS);
256 else if (result != ISC_R_SUCCESS)
260 dns_message_currentname(msg, section,
262 for (rdataset = ISC_LIST_HEAD(name->list);
264 rdataset = ISC_LIST_NEXT(rdataset, link)) {
265 loopresult = dns_rdataset_first(rdataset);
266 while (loopresult == ISC_R_SUCCESS) {
267 dns_rdataset_current(rdataset, &rdata);
268 switch (rdata.type) {
269 case dns_rdatatype_a:
270 if (section != DNS_SECTION_ANSWER)
271 goto def_short_section;
272 dns_name_format(name, namebuf,
274 printf("Name:\t%s\n", namebuf);
277 case dns_rdatatype_soa:
278 dns_name_format(name, namebuf,
280 printf("%s\n", namebuf);
285 dns_name_format(name, namebuf,
287 printf("%s\t", namebuf);
291 dns_rdata_reset(&rdata);
292 loopresult = dns_rdataset_next(rdataset);
295 result = dns_message_nextname(msg, section);
296 if (result == ISC_R_NOMORE)
298 else if (result != ISC_R_SUCCESS) {
302 return (ISC_R_SUCCESS);
306 detailsection(dig_query_t *query, dns_message_t *msg, isc_boolean_t headers,
307 dns_section_t section) {
308 isc_result_t result, loopresult;
310 dns_rdataset_t *rdataset = NULL;
311 dns_rdata_t rdata = DNS_RDATA_INIT;
312 char namebuf[DNS_NAME_FORMATSIZE];
316 debug("detailsection()");
320 case DNS_SECTION_QUESTION:
323 case DNS_SECTION_ANSWER:
326 case DNS_SECTION_AUTHORITY:
327 puts(" AUTHORITY RECORDS:");
329 case DNS_SECTION_ADDITIONAL:
330 puts(" ADDITIONAL RECORDS:");
335 result = dns_message_firstname(msg, section);
336 if (result == ISC_R_NOMORE)
337 return (ISC_R_SUCCESS);
338 else if (result != ISC_R_SUCCESS)
342 dns_message_currentname(msg, section,
344 for (rdataset = ISC_LIST_HEAD(name->list);
346 rdataset = ISC_LIST_NEXT(rdataset, link)) {
347 if (section == DNS_SECTION_QUESTION) {
348 dns_name_format(name, namebuf,
350 printf("\t%s, ", namebuf);
351 dns_rdatatype_format(rdataset->type,
354 printf("type = %s, ", namebuf);
355 dns_rdataclass_format(rdataset->rdclass,
358 printf("class = %s\n", namebuf);
360 loopresult = dns_rdataset_first(rdataset);
361 while (loopresult == ISC_R_SUCCESS) {
362 dns_rdataset_current(rdataset, &rdata);
364 dns_name_format(name, namebuf,
366 printf(" -> %s\n", namebuf);
368 switch (rdata.type) {
369 case dns_rdatatype_soa:
376 dns_rdata_reset(&rdata);
377 printf("\tttl = %u\n", rdataset->ttl);
378 loopresult = dns_rdataset_next(rdataset);
381 result = dns_message_nextname(msg, section);
382 if (result == ISC_R_NOMORE)
384 else if (result != ISC_R_SUCCESS) {
388 return (ISC_R_SUCCESS);
392 received(int bytes, isc_sockaddr_t *from, dig_query_t *query)
400 trying(char *frm, dig_lookup_t *lookup) {
407 printmessage(dig_query_t *query, dns_message_t *msg, isc_boolean_t headers) {
408 char servtext[ISC_SOCKADDR_FORMATSIZE];
410 /* I've we've gotten this far, we've reached a server. */
413 debug("printmessage()");
415 isc_sockaddr_format(&query->sockaddr, servtext, sizeof(servtext));
416 printf("Server:\t\t%s\n", query->userarg);
417 printf("Address:\t%s\n", servtext);
422 isc_boolean_t headers = ISC_TRUE;
423 puts("------------");
424 /* detailheader(query, msg);*/
425 detailsection(query, msg, headers, DNS_SECTION_QUESTION);
426 detailsection(query, msg, headers, DNS_SECTION_ANSWER);
427 detailsection(query, msg, headers, DNS_SECTION_AUTHORITY);
428 detailsection(query, msg, headers, DNS_SECTION_ADDITIONAL);
429 puts("------------");
432 if (msg->rcode != 0) {
433 char nametext[DNS_NAME_FORMATSIZE];
434 dns_name_format(query->lookup->name,
435 nametext, sizeof(nametext));
436 printf("** server can't find %s: %s\n",
437 (msg->rcode != dns_rcode_nxdomain) ? nametext :
438 query->lookup->textname, rcode_totext(msg->rcode));
439 debug("returning with rcode == 0");
441 /* the lookup failed */
443 return (ISC_R_SUCCESS);
446 if ((msg->flags & DNS_MESSAGEFLAG_AA) == 0)
447 puts("Non-authoritative answer:");
448 if (!ISC_LIST_EMPTY(msg->sections[DNS_SECTION_ANSWER]))
449 printsection(query, msg, headers, DNS_SECTION_ANSWER);
451 printf("*** Can't find %s: No answer\n",
452 query->lookup->textname);
454 if (((msg->flags & DNS_MESSAGEFLAG_AA) == 0) &&
455 (query->lookup->rdtype != dns_rdatatype_a)) {
456 puts("\nAuthoritative answers can be found from:");
457 printsection(query, msg, headers,
458 DNS_SECTION_AUTHORITY);
459 printsection(query, msg, headers,
460 DNS_SECTION_ADDITIONAL);
462 return (ISC_R_SUCCESS);
466 show_settings(isc_boolean_t full, isc_boolean_t serv_only) {
468 isc_sockaddr_t sockaddr;
469 dig_searchlist_t *listent;
472 srv = ISC_LIST_HEAD(server_list);
474 while (srv != NULL) {
475 char sockstr[ISC_SOCKADDR_FORMATSIZE];
477 result = get_address(srv->servername, port, &sockaddr);
478 check_result(result, "get_address");
480 isc_sockaddr_format(&sockaddr, sockstr, sizeof(sockstr));
481 printf("Default server: %s\nAddress: %s\n",
482 srv->userarg, sockstr);
485 srv = ISC_LIST_NEXT(srv, link);
489 printf("\nSet options:\n");
490 printf(" %s\t\t\t%s\t\t%s\n",
491 tcpmode ? "vc" : "novc",
492 short_form ? "nodebug" : "debug",
493 debugging ? "d2" : "nod2");
494 printf(" %s\t\t%s\n",
495 usesearch ? "search" : "nosearch",
496 recurse ? "recurse" : "norecurse");
497 printf(" timeout = %d\t\tretry = %d\tport = %d\n",
498 timeout, tries, port);
499 printf(" querytype = %-8s\tclass = %s\n", deftype, defclass);
500 printf(" srchlist = ");
501 for (listent = ISC_LIST_HEAD(search_list);
503 listent = ISC_LIST_NEXT(listent, link)) {
504 printf("%s", listent->origin);
505 if (ISC_LIST_NEXT(listent, link) != NULL)
512 testtype(char *typetext) {
515 dns_rdatatype_t rdtype;
518 tr.length = strlen(typetext);
519 result = dns_rdatatype_fromtext(&rdtype, &tr);
520 if (result == ISC_R_SUCCESS)
523 printf("unknown query type: %s\n", typetext);
529 testclass(char *typetext) {
532 dns_rdataclass_t rdclass;
535 tr.length = strlen(typetext);
536 result = dns_rdataclass_fromtext(&rdclass, &tr);
537 if (result == ISC_R_SUCCESS)
540 printf("unknown query class: %s\n", typetext);
546 set_port(const char *value) {
548 isc_result_t result = parse_uint(&n, value, 65535, "port");
549 if (result == ISC_R_SUCCESS)
550 port = (isc_uint16_t) n;
554 set_timeout(const char *value) {
556 isc_result_t result = parse_uint(&n, value, UINT_MAX, "timeout");
557 if (result == ISC_R_SUCCESS)
562 set_tries(const char *value) {
564 isc_result_t result = parse_uint(&n, value, INT_MAX, "tries");
565 if (result == ISC_R_SUCCESS)
570 setoption(char *opt) {
571 if (strncasecmp(opt, "all", 4) == 0) {
572 show_settings(ISC_TRUE, ISC_FALSE);
573 } else if (strncasecmp(opt, "class=", 6) == 0) {
574 if (testclass(&opt[6]))
575 strlcpy(defclass, &opt[6], sizeof(defclass));
576 } else if (strncasecmp(opt, "cl=", 3) == 0) {
577 if (testclass(&opt[3]))
578 strlcpy(defclass, &opt[3], sizeof(defclass));
579 } else if (strncasecmp(opt, "type=", 5) == 0) {
580 if (testtype(&opt[5]))
581 strlcpy(deftype, &opt[5], sizeof(deftype));
582 } else if (strncasecmp(opt, "ty=", 3) == 0) {
583 if (testtype(&opt[3]))
584 strlcpy(deftype, &opt[3], sizeof(deftype));
585 } else if (strncasecmp(opt, "querytype=", 10) == 0) {
586 if (testtype(&opt[10]))
587 strlcpy(deftype, &opt[10], sizeof(deftype));
588 } else if (strncasecmp(opt, "query=", 6) == 0) {
589 if (testtype(&opt[6]))
590 strlcpy(deftype, &opt[6], sizeof(deftype));
591 } else if (strncasecmp(opt, "qu=", 3) == 0) {
592 if (testtype(&opt[3]))
593 strlcpy(deftype, &opt[3], sizeof(deftype));
594 } else if (strncasecmp(opt, "q=", 2) == 0) {
595 if (testtype(&opt[2]))
596 strlcpy(deftype, &opt[2], sizeof(deftype));
597 } else if (strncasecmp(opt, "domain=", 7) == 0) {
598 strlcpy(domainopt, &opt[7], sizeof(domainopt));
599 set_search_domain(domainopt);
600 usesearch = ISC_TRUE;
601 } else if (strncasecmp(opt, "do=", 3) == 0) {
602 strlcpy(domainopt, &opt[3], sizeof(domainopt));
603 set_search_domain(domainopt);
604 usesearch = ISC_TRUE;
605 } else if (strncasecmp(opt, "port=", 5) == 0) {
607 } else if (strncasecmp(opt, "po=", 3) == 0) {
609 } else if (strncasecmp(opt, "timeout=", 8) == 0) {
610 set_timeout(&opt[8]);
611 } else if (strncasecmp(opt, "t=", 2) == 0) {
612 set_timeout(&opt[2]);
613 } else if (strncasecmp(opt, "rec", 3) == 0) {
615 } else if (strncasecmp(opt, "norec", 5) == 0) {
617 } else if (strncasecmp(opt, "retry=", 6) == 0) {
619 } else if (strncasecmp(opt, "ret=", 4) == 0) {
621 } else if (strncasecmp(opt, "def", 3) == 0) {
622 usesearch = ISC_TRUE;
623 } else if (strncasecmp(opt, "nodef", 5) == 0) {
624 usesearch = ISC_FALSE;
625 } else if (strncasecmp(opt, "vc", 3) == 0) {
627 } else if (strncasecmp(opt, "novc", 5) == 0) {
629 } else if (strncasecmp(opt, "deb", 3) == 0) {
630 short_form = ISC_FALSE;
631 showsearch = ISC_TRUE;
632 } else if (strncasecmp(opt, "nodeb", 5) == 0) {
633 short_form = ISC_TRUE;
634 showsearch = ISC_FALSE;
635 } else if (strncasecmp(opt, "d2", 2) == 0) {
636 debugging = ISC_TRUE;
637 } else if (strncasecmp(opt, "nod2", 4) == 0) {
638 debugging = ISC_FALSE;
639 } else if (strncasecmp(opt, "search", 3) == 0) {
640 usesearch = ISC_TRUE;
641 } else if (strncasecmp(opt, "nosearch", 5) == 0) {
642 usesearch = ISC_FALSE;
643 } else if (strncasecmp(opt, "sil", 3) == 0) {
644 /* deprecation_msg = ISC_FALSE; */
645 } else if (strncasecmp(opt, "fail", 3) == 0) {
647 } else if (strncasecmp(opt, "nofail", 3) == 0) {
650 printf("*** Invalid option: %s\n", opt);
655 addlookup(char *opt) {
656 dig_lookup_t *lookup;
659 dns_rdatatype_t rdtype;
660 dns_rdataclass_t rdclass;
663 debug("addlookup()");
665 tr.length = strlen(deftype);
666 result = dns_rdatatype_fromtext(&rdtype, &tr);
667 if (result != ISC_R_SUCCESS) {
668 printf("unknown query type: %s\n", deftype);
669 rdclass = dns_rdatatype_a;
672 tr.length = strlen(defclass);
673 result = dns_rdataclass_fromtext(&rdclass, &tr);
674 if (result != ISC_R_SUCCESS) {
675 printf("unknown query class: %s\n", defclass);
676 rdclass = dns_rdataclass_in;
678 lookup = make_empty_lookup();
679 if (get_reverse(store, sizeof(store), opt, lookup->ip6_int, ISC_TRUE)
681 strlcpy(lookup->textname, store, sizeof(lookup->textname));
682 lookup->rdtype = dns_rdatatype_ptr;
683 lookup->rdtypeset = ISC_TRUE;
685 strlcpy(lookup->textname, opt, sizeof(lookup->textname));
686 lookup->rdtype = rdtype;
687 lookup->rdtypeset = ISC_TRUE;
689 lookup->rdclass = rdclass;
690 lookup->rdclassset = ISC_TRUE;
691 lookup->trace = ISC_FALSE;
692 lookup->trace_root = lookup->trace;
693 lookup->ns_search_only = ISC_FALSE;
694 lookup->identify = identify;
695 lookup->recurse = recurse;
696 lookup->aaonly = aaonly;
697 lookup->retries = tries;
699 lookup->comments = comments;
700 lookup->tcp_mode = tcpmode;
701 lookup->stats = stats;
702 lookup->section_question = section_question;
703 lookup->section_answer = section_answer;
704 lookup->section_authority = section_authority;
705 lookup->section_additional = section_additional;
706 lookup->new_search = ISC_TRUE;
708 lookup->servfail_stops = ISC_FALSE;
709 ISC_LIST_INIT(lookup->q);
710 ISC_LINK_INIT(lookup, link);
711 ISC_LIST_APPEND(lookup_list, lookup, link);
712 lookup->origin = NULL;
713 ISC_LIST_INIT(lookup->my_server_list);
714 debug("looking up %s", lookup->textname);
718 get_next_command(void) {
724 buf = isc_mem_allocate(mctx, COMMSIZE);
726 fatal("memory allocation failure");
730 ptr = fgets(buf, COMMSIZE, stdin);
737 ptr = next_token(&input, " \t\r\n");
740 arg = next_token(&input, " \t\r\n");
741 if ((strcasecmp(ptr, "set") == 0) &&
744 else if ((strcasecmp(ptr, "server") == 0) ||
745 (strcasecmp(ptr, "lserver") == 0)) {
748 check_ra = ISC_FALSE;
750 show_settings(ISC_TRUE, ISC_TRUE);
751 } else if (strcasecmp(ptr, "exit") == 0) {
754 } else if (strcasecmp(ptr, "help") == 0 ||
755 strcasecmp(ptr, "?") == 0) {
756 printf("The '%s' command is not yet implemented.\n", ptr);
758 } else if (strcasecmp(ptr, "finger") == 0 ||
759 strcasecmp(ptr, "root") == 0 ||
760 strcasecmp(ptr, "ls") == 0 ||
761 strcasecmp(ptr, "view") == 0) {
762 printf("The '%s' command is not implemented.\n", ptr);
767 isc_mem_free(mctx, buf);
771 parse_args(int argc, char **argv) {
772 isc_boolean_t have_lookup = ISC_FALSE;
774 usesearch = ISC_TRUE;
775 for (argc--, argv++; argc > 0; argc--, argv++) {
776 debug("main parsing %s", argv[0]);
777 if (argv[0][0] == '-') {
779 setoption(&argv[0][1]);
781 have_lookup = ISC_TRUE;
784 have_lookup = ISC_TRUE;
788 set_nameserver(argv[0]);
789 check_ra = ISC_FALSE;
796 flush_lookup_list(void) {
797 dig_lookup_t *l, *lp;
799 dig_server_t *s, *sp;
802 l = ISC_LIST_HEAD(lookup_list);
804 q = ISC_LIST_HEAD(l->q);
806 if (q->sock != NULL) {
807 isc_socket_cancel(q->sock, NULL,
809 isc_socket_detach(&q->sock);
811 if (ISC_LINK_LINKED(&q->recvbuf, link))
812 ISC_LIST_DEQUEUE(q->recvlist, &q->recvbuf,
814 if (ISC_LINK_LINKED(&q->lengthbuf, link))
815 ISC_LIST_DEQUEUE(q->lengthlist, &q->lengthbuf,
817 isc_buffer_invalidate(&q->recvbuf);
818 isc_buffer_invalidate(&q->lengthbuf);
820 q = ISC_LIST_NEXT(q, link);
821 ISC_LIST_DEQUEUE(l->q, qp, link);
822 isc_mem_free(mctx, qp);
824 s = ISC_LIST_HEAD(l->my_server_list);
827 s = ISC_LIST_NEXT(s, link);
828 ISC_LIST_DEQUEUE(l->my_server_list, sp, link);
829 isc_mem_free(mctx, sp);
832 if (l->sendmsg != NULL)
833 dns_message_destroy(&l->sendmsg);
834 if (l->timer != NULL)
835 isc_timer_detach(&l->timer);
837 l = ISC_LIST_NEXT(l, link);
838 ISC_LIST_DEQUEUE(lookup_list, lp, link);
839 isc_mem_free(mctx, lp);
844 getinput(isc_task_t *task, isc_event_t *event) {
846 if (global_event == NULL)
847 global_event = event;
850 if (ISC_LIST_HEAD(lookup_list) != NULL) {
859 main(int argc, char **argv) {
862 ISC_LIST_INIT(lookup_list);
863 ISC_LIST_INIT(server_list);
864 ISC_LIST_INIT(search_list);
868 result = isc_app_start();
869 check_result(result, "isc_app_start");
874 parse_args(argc, argv);
877 if (domainopt[0] != '\0')
878 set_search_domain(domainopt);
880 result = isc_app_onrun(mctx, global_task, onrun_callback,
883 result = isc_app_onrun(mctx, global_task, getinput, NULL);
884 check_result(result, "isc_app_onrun");
885 in_use = ISC_TF(!in_use);
890 debug("done, and starting to shut down");
891 if (global_event != NULL)
892 isc_event_free(&global_event);
897 return (query_error | print_error);