dig.c revision fed846067d265db1037483d81d01f3651c8a3f28
5fa46bc91672ef5737aee6f99763161511566c24Tinderbox User * Copyright (C) 2000, 2001 Internet Software Consortium.
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * Permission to use, copy, modify, and distribute this software for any
ec5347e2c775f027573ce5648b910361aa926c01Automatic Updater * purpose with or without fee is hereby granted, provided that the above
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * copyright notice and this permission notice appear in all copies.
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
dafcb997e390efa4423883dafd100c975c4095d6Mark Andrews * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
28a8f5b0de57d269cf2845c69cb6abe18cbd3b3aMark Andrews/* $Id: dig.c,v 1.147 2001/06/29 06:06:00 bwelling Exp $ */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonextern ISC_LIST(dig_searchlist_t) search_list;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#define ADD_STRING(b, s) { \
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (strlen(s) >= isc_buffer_availablelength(b)) \
e2fd12f3a020ca8c5de168a44fb72e339cdaa3e9Brian Wellingtonextern isc_boolean_t have_ipv4, have_ipv6, specified_source,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonextern unsigned int timeout;
229ce407c359b0b641759ba1fc4a5fa2054a44daBrian Wellingtonextern isc_boolean_t debugging, memdebugging;
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtonisc_boolean_t short_form = ISC_FALSE, printcmd = ISC_TRUE,
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington nibble = ISC_FALSE, plusquest = ISC_FALSE, pluscomm = ISC_FALSE,
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtonstatic const char *opcodetext[] = {
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein "RESERVED8",
571688b02f955f6304649866e768b1f81739cbedBrian Wellington "RESERVED10",
571688b02f955f6304649866e768b1f81739cbedBrian Wellington "RESERVED11",
571688b02f955f6304649866e768b1f81739cbedBrian Wellington "RESERVED12",
571688b02f955f6304649866e768b1f81739cbedBrian Wellington "RESERVED13",
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington "RESERVED14",
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonstatic const char *rcodetext[] = {
557bcc2092642b2d4668c9b08872c9f2bb88bddbMark Andrews "RESERVED11",
557bcc2092642b2d4668c9b08872c9f2bb88bddbMark Andrews "RESERVED12",
23f64ea0dcd7f5b7094ae6ade2a002fb7dde1466Brian Wellington "RESERVED13",
23f64ea0dcd7f5b7094ae6ade2a002fb7dde1466Brian Wellington "RESERVED14",
23f64ea0dcd7f5b7094ae6ade2a002fb7dde1466Brian Wellington "RESERVED15",
e2fd12f3a020ca8c5de168a44fb72e339cdaa3e9Brian Wellington"Usage: dig [@global-server] [domain] [q-type] [q-class] {q-opt}\n"
23f64ea0dcd7f5b7094ae6ade2a002fb7dde1466Brian Wellington" {global-d-opt} host [@local-server] {local-d-opt}\n"
557bcc2092642b2d4668c9b08872c9f2bb88bddbMark Andrews" [ host [@local-server] {local-d-opt} [...]]\n", fp);
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington fputs("\nUse \"dig -h\" (or \"dig -h | more\") "
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington"Where: domain are in the Domain Name System\n"
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington" q-class is one of (in,hs,ch,...) [default: in]\n"
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington" q-type is one of (a,any,mx,ns,soa,hinfo,axfr,txt,...) [default:a]\n"
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington" (Use ixfr=version for type ixfr)\n"
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington" q-opt is one of:\n"
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington" -x dot-notation (shortcut for in-addr lookups)\n"
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington" -n (nibble form for reverse IPv6 lookups)\n"
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington" -f filename (batch mode)\n"
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington" -p port (specify port number)\n"
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington" -t type (specify query type)\n"
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington" -c class (specify query class)\n"
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington" -y name:key (specify named base64 tsig key)\n"
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington" d-opt is of the form +keyword[=value], where keyword is:\n"
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington" +[no]vc (TCP mode)\n"
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington" +[no]tcp (TCP mode, alternate syntax)\n"
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington" +time=### (Set query timeout) [5]\n"
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington" +tries=### (Set number of UDP attempts) [3]\n"
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington" +domain=### (Set default domainname)\n"
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington" +bufsize=### (Set EDNS0 Max UDP packet size)\n"
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington" +[no]search (Set whether to use searchlist)\n"
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington" +[no]defname (Ditto)\n"
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington" +[no]recursive (Recursive mode)\n"
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington" +[no]ignore (Don't revert to TCP for TC responses.)"
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington" +[no]fail (Don't try next server on SERVFAIL)\n"
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington" +[no]besteffort (Try to parse even illegal messages)\n"
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington" +[no]aaonly (Set AA flag in query)\n"
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington" +[no]adflag (Set AD flag in query)\n"
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington" +[no]cdflag (Set CD flag in query)\n"
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington" +ndots=### (Set NDOTS value)\n"
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington" +[no]cmd (Control display of command line)\n"
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington" +[no]comments (Control display of comment lines)\n"
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington" +[no]question (Control display of question)\n"
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington" +[no]answer (Control display of answer)\n"
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington" +[no]authority (Control display of authority)\n"
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington" +[no]additional (Control display of additional)\n"
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington" +[no]short (Disable everything except short\n"
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington" form of answer)\n"
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington" +[no]all (Set or clear all display flags)\n"
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington" +qr (Print question before sending)\n"
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington" +[no]nssearch (Search all authoritative nameservers)\n"
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington" +[no]identify (ID responders in short answers)\n"
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington" +[no]trace (Trace delegation down from root)\n"
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington" +[no]dnssec (Request DNSSEC records)\n"
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington" +[no]multiline (Print records in an expanded format)\n"
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington" global d-opts and servers (before host name) affect all queries.\n"
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington" local d-opts and servers (after host name) affect only that lookup.\n",
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * Callback from dighost.c to print the received message.
75e1e12f48012505699f504cfa364260cb2bc1afBrian Wellingtonreceived(int bytes, isc_sockaddr_t *from, dig_query_t *query) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_sockaddr_format(from, fromtext, sizeof(fromtext));
23f64ea0dcd7f5b7094ae6ade2a002fb7dde1466Brian Wellington diff = isc_time_microdiff(&now, &query->time_sent);
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews printf(";; Query time: %ld msec\n", (long int)diff/1000);
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews printf(";; SERVER: %s(%s)\n", fromtext, query->servname);
e2fd12f3a020ca8c5de168a44fb72e339cdaa3e9Brian Wellington "be validated");
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington if ((key == NULL) && (keysecret[0] != 0)) {
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington puts(";; WARNING -- TSIG key was not used.");
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington } else if (query->lookup->identify && !short_form) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington diff = isc_time_microdiff(&now, &query->time_sent);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington printf(";; Received %u bytes from %s(%s) in %d ms\n\n",
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * Callback from dighost.c to print that it is trying a server.
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * Not used in dig.
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * XXX print_trying
77ac297199fc44809d9628558223627c10ae3f31Brian Wellingtontrying(int frmsize, char *frm, dig_lookup_t *lookup) {
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington * Internal print routine used to print short form replies.
77ac297199fc44809d9628558223627c10ae3f31Brian Wellingtonsay_message(dns_rdata_t *rdata, dig_query_t *query, isc_buffer_t *buf) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington char store[sizeof("12345678901234567890")];
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson if (query->lookup->trace || query->lookup->ns_search_only) {
de32cbd34e78bdd276e69cff239846760d4ee16eBrian Wellington result = dns_rdatatype_totext(rdata->type, buf);
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews diff = isc_time_microdiff(&now, &query->time_sent);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington snprintf(store, 19, " in %d ms.", (int)diff/1000);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * short_form message print handler. Calls above say_message()
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonshort_answer(dns_message_t *msg, dns_messagetextflag_t flags,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington char t[4096];
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington result = dns_message_firstname(msg, DNS_SECTION_ANSWER);
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson dns_message_currentname(msg, DNS_SECTION_ANSWER, &name);
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson for (rdataset = ISC_LIST_HEAD(name->list);
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson rdataset = ISC_LIST_NEXT(rdataset, link)) {
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson loopresult = dns_rdataset_first(rdataset);
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson loopresult = dns_rdataset_next(rdataset);
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson result = dns_message_nextname(msg, DNS_SECTION_ANSWER);
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson * Callback from dighost.c to print the reply from a server
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafssonprintmessage(dig_query_t *query, dns_message_t *msg, isc_boolean_t headers) {
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson debug("printmessage(%s %s %s)", headers ? "headers" : "noheaders",
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington query->lookup->comments ? "comments" : "nocomments",
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson check_result(result, "isc_buffer_allocate");
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (query->lookup->comments && !short_form) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington printf(";; ->>HEADER<<- opcode: %s, status: %s, "
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson opcodetext[msg->opcode], rcodetext[msg->rcode],
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson if ((msg->flags & DNS_MESSAGEFLAG_QR) != 0) {
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson if ((msg->flags & DNS_MESSAGEFLAG_AA) != 0) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if ((msg->flags & DNS_MESSAGEFLAG_RA) != 0) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if ((msg->flags & DNS_MESSAGEFLAG_AD) != 0) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if ((msg->flags & DNS_MESSAGEFLAG_CD) != 0) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington "AUTHORITY: %u, ADDITIONAL: %u\n",
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington if (query->lookup->comments && headers && !short_form)
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington result = dns_message_pseudosectiontotext(msg,
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington result = isc_buffer_allocate(mctx, &buf, len);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington "dns_message_pseudosectiontotext");
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington if (query->lookup->section_question && headers) {
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington check_result(result, "dns_message_sectiontotext");
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington check_result(result, "dns_message_sectiontotext");
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington result = short_answer(msg, flags, buf, query);
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson check_result(result, "dns_message_sectiontotext");
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson check_result(result, "dns_message_sectiontotext");
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson * Only print the signature on the first record.
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson result = dns_message_pseudosectiontotext(
307ba34fa07db768c3a899844f248a2c1d7dcc7fAndreas Gustafsson "dns_message_pseudosectiontotext");
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington "dns_message_pseudosectiontotext");
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (headers && query->lookup->comments && !short_form)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington printf("%.*s", (int)isc_buffer_usedlength(buf),
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * print the greeting message when the program first starts up.
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonprintgreeting(int argc, char **argv, dig_lookup_t *lookup) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington lookup->cmdline[sizeof(lookup->cmdline) - 1] = 0;
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington snprintf(lookup->cmdline, sizeof(lookup->cmdline),
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington while (i < argc) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington snprintf(append, sizeof(append), " %s", argv[i++]);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington strncat(lookup->cmdline, append, remaining);
e2fd12f3a020ca8c5de168a44fb72e339cdaa3e9Brian Wellington ";; global options: %s %s\n",
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington strncat(lookup->cmdline, append, remaining);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * Reorder an argument list so that server names all come at the end.
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * This is a bit of a hack, to allow batch-mode processing to properly
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * handle the server options.
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington debug("moving %s to end, %d", ptr, end - 1);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonparse_int(char *arg, const char *desc, isc_uint32_t max) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * We're not using isc_commandline_parse() here since the command line
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * syntax of dig is quite a bit different from that which can be described
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * by that routine.
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * XXX doc options
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellingtonplus_option(char *option, isc_boolean_t is_batchfile,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington strncpy(option_store, option, sizeof(option_store));
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington printf(";; Invalid option %s\n",option_store);
c0d2891f6e08fcf5379dfb9a1bf8fbbb63f1952aMark Andrews switch (cmd[0]) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington lookup->udpsize = parse_int(value, "buffer size",
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington strncpy(domainopt, value, sizeof(domainopt));
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington default: /* Inherets default for compatibility */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington timeout = parse_int(value, "timeout", MAXTIMEOUT);
75582adac73202213d936dc0850f1c9cf47d6cbeMark Andrews#endif /* DNS_OPT_NEWCODES_LIVE */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington#endif /* DNS_OPT_NEWCODES_LIVE */
c302b021cc65cc9a358a9a1cbe48de12364f4cb6Brian Wellington * ISC_TRUE returned if value was used
ab381c1e22e0ed732170428937d20d13146d863aAutomatic Updaterdash_option(char *option, char *next, dig_lookup_t **lookup,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington /* memdebug is handled in preparse_args() */
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (have_ipv6 && inet_pton(AF_INET6, value, &in6) == 1)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_sockaddr_fromin6(&bind_address, &in6, 0);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington else if (have_ipv4 && inet_pton(AF_INET, value, &in4) == 1)
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington isc_sockaddr_fromin(&bind_address, &in4, 0);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington fprintf(stderr, ";; Warning, extra class option\n");
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington "invalid class %s\n",
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington port = parse_int(value, "port number", MAXPORT);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington "extra type option\n");
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington "invalid type %s\n",
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington strncpy(keynametext, ptr, sizeof(keynametext));
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington strncpy(keysecret, ptr, sizeof(keysecret));
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington *lookup = clone_lookup(default_lookup, ISC_TRUE);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (get_reverse(textname, value, nibble) == ISC_R_SUCCESS) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington debug("looking up %s", (*lookup)->textname);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington (*lookup)->trace_root = ISC_TF((*lookup)->trace ||
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington ISC_LIST_APPEND(lookup_list, *lookup, link);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington fprintf(stderr, "Invalid IP address %s\n", value);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington fprintf(stderr, "Invalid option: -%s\n", option);
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington * Because we may be trying to do memory allocation recording, we're going
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellington * to need to parse the arguments for the -m *before* we start the main
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews * argument parsing routine.
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews * I'd prefer not to have to do this, but I am not quite sure how else to
6e2871232f7ede047799480370aff444be1f5a13Automatic Updater * fix the problem. Argument parsing in dig involves memory allocation
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews * by its nature, so it can't be done in the main argument parser.
60b90a37f41ab7607762d0e9791e79bd19eae4f4Brian Wellingtonparse_args(isc_boolean_t is_batchfile, isc_boolean_t config_only,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * The semantics for parsing the args is a bit complex; if
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * we don't have a host yet, make the arg apply globally,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * otherwise make it apply to the latest host. This is
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * a bit different than the previous versions, but should
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * form a consistent user interface.
93d6dfaf66258337985427c86181f01fc51f0bb4Mark Andrews * First, create a "default lookup" which won't actually be used
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * anywhere, except for cloning into new lookups
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * Treat .digrc as a special batchfile
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington snprintf(rcfile, sizeof(rcfile), "%s/.digrc", homedir);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington bargv[bargc] = next_token(&input, " \t\r\n");
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington bargv[bargc] = next_token(&input, " \t\r\n");
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * Anything which isn't an option
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington "ixfr requires a "
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington "serial number\n");
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington "extra type option\n");
4a30ede93d59137009db734661cde17612e8ffbeMark Andrews "serial number",
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington "extra class option\n");
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington lookup->textname[sizeof(lookup->textname)-1]=0;
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt /* XXX Error message */
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt * If we have a batchfile, seed the lookup list with the
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt * first entry, then trust the callback in dighost_shutdown
793814f80703afdd69b59ade91e63efa81ae4178Evan Hunt * to get the rest
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington fatal("Couldn't open specified batch file");
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington /* XXX Remove code dup from shutdown code */
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington if (fgets(batchline, sizeof(batchline), batchfp) != 0) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if (batchline[0] == '\r' || batchline[0] == '\n'
77ac297199fc44809d9628558223627c10ae3f31Brian Wellington || batchline[0] == '#' || batchline[0] == ';')
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington bargv[bargc] = next_token(&input, " \t\r\n");
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington while ((bargv[bargc] != NULL) && (bargc < 14)) {
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington bargv[bargc] = next_token(&input, " \t\r\n");
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington parse_args(ISC_TRUE, ISC_FALSE, bargc, (char **)bargv);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * If no lookup specified, search for root
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington if ((lookup_list.head == NULL) && !config_only) {
18d0b5e54be891a1aa938c165b6d439859121ec8Mark Andrews lookup = clone_lookup(default_lookup, ISC_TRUE);
f24c135e09214c3843a49fd32ebef2f6a436ba8eBrian Wellington lookup->trace_root = ISC_TF(lookup->trace ||
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington ISC_LIST_APPEND(lookup_list, lookup, link);
f24c135e09214c3843a49fd32ebef2f6a436ba8eBrian Wellington * Callback from dighost.c to allow program-specific shutdown code. Here,
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington * Here, we're possibly reading from a batch file, then shutting down for
f24c135e09214c3843a49fd32ebef2f6a436ba8eBrian Wellington * real if there's nothing in the batch file to read.
f24c135e09214c3843a49fd32ebef2f6a436ba8eBrian Wellington if (fgets(batchline, sizeof(batchline), batchfp) != 0) {
f24c135e09214c3843a49fd32ebef2f6a436ba8eBrian Wellington bargv[bargc] = next_token(&input, " \t\r\n");
f24c135e09214c3843a49fd32ebef2f6a436ba8eBrian Wellington while ((bargv[bargc] != NULL) && (bargc < 14)) {
f24c135e09214c3843a49fd32ebef2f6a436ba8eBrian Wellington bargv[bargc] = next_token(&input, " \t\r\n");
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington parse_args(ISC_TRUE, ISC_FALSE, bargc, (char **)bargv);
033ba09d6df0ac92a736a480b9c3b164b61dccb2Brian Wellington parse_args(ISC_FALSE, ISC_FALSE, argc, argv);
d0eb2cc33c5db3366a16b1cb0abcca6ec7c8ee3cTatuya JINMEI 神明達哉 result = isc_app_onrun(mctx, global_task, onrun_callback, NULL);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews s = ISC_LIST_HEAD(default_lookup->my_server_list);
6098d364b690cb9dabf96e9664c4689c8559bd2eMark Andrews while (s != NULL) {