dig.c revision d20b7d6bea538bebaec7d319bd90ead44e761069
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews * Copyright (C) 2000, 2001 Internet Software Consortium.
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews * Permission to use, copy, modify, and distribute this software for any
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews * purpose with or without fee is hereby granted, provided that the above
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews * copyright notice and this permission notice appear in all copies.
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
bf8267aa453e5d2a735ed732a043b77a0b355b20Mark Andrews * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews/* $Id: dig.c,v 1.157 2001/08/23 04:39:31 marka Exp $ */
89740699cd2191d9b84e67716c281b2dfeba5e56Evan Hunt#define ADD_STRING(b, s) { \
89740699cd2191d9b84e67716c281b2dfeba5e56Evan Huntextern isc_boolean_t have_ipv4, have_ipv6, specified_source,
89740699cd2191d9b84e67716c281b2dfeba5e56Evan Huntextern unsigned int timeout;
56c9fcf07580457442b80ac32bdb7c07aa0df870Evan Huntstatic char *argv0;
56c9fcf07580457442b80ac32bdb7c07aa0df870Evan Huntstatic isc_boolean_t short_form = ISC_FALSE, printcmd = ISC_TRUE,
56c9fcf07580457442b80ac32bdb7c07aa0df870Evan Hunt nibble = ISC_FALSE, plusquest = ISC_FALSE, pluscomm = ISC_FALSE,
56c9fcf07580457442b80ac32bdb7c07aa0df870Evan Huntstatic const char *opcodetext[] = {
56c9fcf07580457442b80ac32bdb7c07aa0df870Evan Hunt "RESERVED3",
56c9fcf07580457442b80ac32bdb7c07aa0df870Evan Hunt "RESERVED6",
56c9fcf07580457442b80ac32bdb7c07aa0df870Evan Hunt "RESERVED7",
56c9fcf07580457442b80ac32bdb7c07aa0df870Evan Hunt "RESERVED8",
56c9fcf07580457442b80ac32bdb7c07aa0df870Evan Hunt "RESERVED9",
56c9fcf07580457442b80ac32bdb7c07aa0df870Evan Hunt "RESERVED10",
56c9fcf07580457442b80ac32bdb7c07aa0df870Evan Hunt "RESERVED11",
6643b0dd91249ace16218ef667967c87b291992cMark Andrews "RESERVED12",
56c9fcf07580457442b80ac32bdb7c07aa0df870Evan Hunt "RESERVED13",
68116c5a5fd36fef812fc207de3b7714db2994d5Evan Hunt "RESERVED14",
56c9fcf07580457442b80ac32bdb7c07aa0df870Evan Hunt "RESERVED15"
56c9fcf07580457442b80ac32bdb7c07aa0df870Evan Huntstatic const char *rcodetext[] = {
56c9fcf07580457442b80ac32bdb7c07aa0df870Evan Hunt "RESERVED11",
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews "RESERVED12",
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews "RESERVED13",
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews "RESERVED14",
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews "RESERVED15",
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews"Usage: dig [@global-server] [domain] [q-type] [q-class] {q-opt}\n"
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews" {global-d-opt} host [@local-server] {local-d-opt}\n"
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews" [ host [@local-server] {local-d-opt} [...]]\n", fp);
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews fputs("\nUse \"dig -h\" (or \"dig -h | more\") "
66e50468dde42a9757ac489e738d8b2db8fd7f80Evan Hunt"Where: domain are in the Domain Name System\n"
56c9fcf07580457442b80ac32bdb7c07aa0df870Evan Hunt" q-class is one of (in,hs,ch,...) [default: in]\n"
66e50468dde42a9757ac489e738d8b2db8fd7f80Evan Hunt" q-type is one of (a,any,mx,ns,soa,hinfo,axfr,txt,...) [default:a]\n"
66e50468dde42a9757ac489e738d8b2db8fd7f80Evan Hunt" (Use ixfr=version for type ixfr)\n"
66e50468dde42a9757ac489e738d8b2db8fd7f80Evan Hunt" q-opt is one of:\n"
68116c5a5fd36fef812fc207de3b7714db2994d5Evan Hunt" -x dot-notation (shortcut for in-addr lookups)\n"
56c9fcf07580457442b80ac32bdb7c07aa0df870Evan Hunt" -n (nibble form for reverse IPv6 lookups)\n"
66e50468dde42a9757ac489e738d8b2db8fd7f80Evan Hunt" -f filename (batch mode)\n"
66e50468dde42a9757ac489e738d8b2db8fd7f80Evan Hunt" -p port (specify port number)\n"
66e50468dde42a9757ac489e738d8b2db8fd7f80Evan Hunt" -t type (specify query type)\n"
66e50468dde42a9757ac489e738d8b2db8fd7f80Evan Hunt" -c class (specify query class)\n"
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews" -y name:key (specify named base64 tsig key)\n"
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews" d-opt is of the form +keyword[=value], where keyword is:\n"
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews" +[no]vc (TCP mode)\n"
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews" +[no]tcp (TCP mode, alternate syntax)\n"
56c9fcf07580457442b80ac32bdb7c07aa0df870Evan Hunt" +time=### (Set query timeout) [5]\n"
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews" +tries=### (Set number of UDP attempts) [3]\n"
56c9fcf07580457442b80ac32bdb7c07aa0df870Evan Hunt" +domain=### (Set default domainname)\n"
56c9fcf07580457442b80ac32bdb7c07aa0df870Evan Hunt" +bufsize=### (Set EDNS0 Max UDP packet size)\n"
6643b0dd91249ace16218ef667967c87b291992cMark Andrews" +[no]search (Set whether to use searchlist)\n"
56c9fcf07580457442b80ac32bdb7c07aa0df870Evan Hunt" +[no]defname (Ditto)\n"
68116c5a5fd36fef812fc207de3b7714db2994d5Evan Hunt" +[no]recursive (Recursive mode)\n"
56c9fcf07580457442b80ac32bdb7c07aa0df870Evan Hunt" +[no]ignore (Don't revert to TCP for TC responses.)"
56c9fcf07580457442b80ac32bdb7c07aa0df870Evan Hunt" +[no]fail (Don't try next server on SERVFAIL)\n"
56c9fcf07580457442b80ac32bdb7c07aa0df870Evan Hunt" +[no]besteffort (Try to parse even illegal messages)\n"
56c9fcf07580457442b80ac32bdb7c07aa0df870Evan Hunt" +[no]aaonly (Set AA flag in query)\n"
6643b0dd91249ace16218ef667967c87b291992cMark Andrews" +[no]adflag (Set AD flag in query)\n"
56c9fcf07580457442b80ac32bdb7c07aa0df870Evan Hunt" +[no]cdflag (Set CD flag in query)\n"
56c9fcf07580457442b80ac32bdb7c07aa0df870Evan Hunt" +ndots=### (Set NDOTS value)\n"
56c9fcf07580457442b80ac32bdb7c07aa0df870Evan Hunt" +[no]cmd (Control display of command line)\n"
56c9fcf07580457442b80ac32bdb7c07aa0df870Evan Hunt" +[no]comments (Control display of comment lines)\n"
56c9fcf07580457442b80ac32bdb7c07aa0df870Evan Hunt" +[no]question (Control display of question)\n"
56c9fcf07580457442b80ac32bdb7c07aa0df870Evan Hunt" +[no]answer (Control display of answer)\n"
56c9fcf07580457442b80ac32bdb7c07aa0df870Evan Hunt" +[no]authority (Control display of authority)\n"
56c9fcf07580457442b80ac32bdb7c07aa0df870Evan Hunt" +[no]additional (Control display of additional)\n"
56c9fcf07580457442b80ac32bdb7c07aa0df870Evan Hunt" +[no]short (Disable everything except short\n"
56c9fcf07580457442b80ac32bdb7c07aa0df870Evan Hunt" form of answer)\n"
56c9fcf07580457442b80ac32bdb7c07aa0df870Evan Hunt" +[no]all (Set or clear all display flags)\n"
56c9fcf07580457442b80ac32bdb7c07aa0df870Evan Hunt" +qr (Print question before sending)\n"
56c9fcf07580457442b80ac32bdb7c07aa0df870Evan Hunt" +[no]nssearch (Search all authoritative nameservers)\n"
56c9fcf07580457442b80ac32bdb7c07aa0df870Evan Hunt" +[no]identify (ID responders in short answers)\n"
56c9fcf07580457442b80ac32bdb7c07aa0df870Evan Hunt" +[no]trace (Trace delegation down from root)\n"
56c9fcf07580457442b80ac32bdb7c07aa0df870Evan Hunt" +[no]dnssec (Request DNSSEC records)\n"
56c9fcf07580457442b80ac32bdb7c07aa0df870Evan Hunt" +[no]multiline (Print records in an expanded format)\n"
6643b0dd91249ace16218ef667967c87b291992cMark Andrews" global d-opts and servers (before host name) affect all queries.\n"
56c9fcf07580457442b80ac32bdb7c07aa0df870Evan Hunt" local d-opts and servers (after host name) affect only that lookup.\n",
56c9fcf07580457442b80ac32bdb7c07aa0df870Evan Hunt * Callback from dighost.c to print the received message.
56c9fcf07580457442b80ac32bdb7c07aa0df870Evan Huntreceived(int bytes, isc_sockaddr_t *from, dig_query_t *query) {
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews isc_sockaddr_format(from, fromtext, sizeof(fromtext));
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews diff = isc_time_microdiff(&now, &query->time_sent);
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews printf(";; Query time: %ld msec\n", (long int)diff/1000);
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews printf(";; SERVER: %s(%s)\n", fromtext, query->servname);
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews "be validated");
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews } else if (query->lookup->identify && !short_form) {
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews diff = isc_time_microdiff(&now, &query->time_sent);
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews printf(";; Received %u bytes from %s(%s) in %d ms\n\n",
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews * Callback from dighost.c to print that it is trying a server.
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews * Not used in dig.
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews * XXX print_trying
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews * Internal print routine used to print short form replies.
56c9fcf07580457442b80ac32bdb7c07aa0df870Evan Huntsay_message(dns_rdata_t *rdata, dig_query_t *query, isc_buffer_t *buf) {
66e50468dde42a9757ac489e738d8b2db8fd7f80Evan Hunt if (query->lookup->trace || query->lookup->ns_search_only) {
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews diff = isc_time_microdiff(&now, &query->time_sent);
56c9fcf07580457442b80ac32bdb7c07aa0df870Evan Hunt snprintf(store, 19, " in %d ms.", (int)diff/1000);
56c9fcf07580457442b80ac32bdb7c07aa0df870Evan Hunt * short_form message print handler. Calls above say_message()
56c9fcf07580457442b80ac32bdb7c07aa0df870Evan Huntshort_answer(dns_message_t *msg, dns_messagetextflag_t flags,
56c9fcf07580457442b80ac32bdb7c07aa0df870Evan Hunt char t[4096];
68116c5a5fd36fef812fc207de3b7714db2994d5Evan Hunt result = dns_message_firstname(msg, DNS_SECTION_ANSWER);
56c9fcf07580457442b80ac32bdb7c07aa0df870Evan Hunt dns_message_currentname(msg, DNS_SECTION_ANSWER, &name);
68116c5a5fd36fef812fc207de3b7714db2994d5Evan Hunt result = dns_message_nextname(msg, DNS_SECTION_ANSWER);
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews * Callback from dighost.c to print the reply from a server
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrewsprintmessage(dig_query_t *query, dns_message_t *msg, isc_boolean_t headers) {
66e50468dde42a9757ac489e738d8b2db8fd7f80Evan Hunt debug("printmessage(%s %s %s)", headers ? "headers" : "noheaders",
66e50468dde42a9757ac489e738d8b2db8fd7f80Evan Hunt query->lookup->comments ? "comments" : "nocomments",
56c9fcf07580457442b80ac32bdb7c07aa0df870Evan Hunt "AUTHORITY: %u, ADDITIONAL: %u\n",
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews if (query->lookup->comments && headers && !short_form)
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews "dns_message_pseudosectiontotext");
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews if (query->lookup->section_question && headers) {
d76ed813a51465e5c47d521ab09ea20c06f1428dMark Andrews check_result(result, "dns_message_sectiontotext");
goto buftoosmall;
goto buftoosmall;
if (!short_form) {
goto buftoosmall;
if (!short_form) {
goto buftoosmall;
if (headers) {
msg,
goto buftoosmall;
msg,
goto buftoosmall;
return (result);
int remaining;
if (printcmd) {
while (i < argc) {
if (first) {
char *ptr;
int end;
end--;
if (end == 0)
end--;
static isc_uint32_t
char *endp;
return (tmp);
switch (cmd[0]) {
goto invalid_option;
goto invalid_option;
goto need_value;
if (!state)
goto invalid_option;
goto invalid_option;
goto invalid_option;
goto need_value;
if (!state)
goto invalid_option;
goto invalid_option;
goto need_value;
if (!state)
goto invalid_option;
if (state) {
goto invalid_option;
goto invalid_option;
if (state) {
goto invalid_option;
if (!is_batchfile)
goto need_value;
if (!state)
goto invalid_option;
if (timeout == 0)
if (state) {
goto need_value;
if (!state)
goto invalid_option;
MAXTRIES);
goto invalid_option;
goto invalid_option;
#ifdef DNS_OPT_NEWCODES_LIVE
if (!is_batchfile)
#ifdef DNS_OPT_NEWCODES_LIVE
goto need_value;
if (!state)
goto invalid_option;
goto need_value;
if (!state)
goto invalid_option;
option);
usage();
static isc_boolean_t
switch (cmd) {
return (ISC_FALSE);
help();
exit(0);
return (ISC_FALSE);
return (ISC_FALSE);
goto invalid_option;
switch (cmd) {
return (value_from_next);
value);
return (value_from_next);
return (value_from_next);
return (value_from_next);
return (value_from_next);
value);
return (value_from_next);
usage();
usage();
return (value_from_next);
return (value_from_next);
usage();
return (ISC_FALSE);
int rc;
char **rv;
int bargc;
int rc;
char **rv;
#ifndef NOPOSIX
char *homedir;
char *input;
if (!is_batchfile) {
#ifndef NOPOSIX
batchfp) != 0) {
bargc++;
(char **)bargv);
lookup);
rc--;
rv++;
rc--;
rv++;
if (open_type_class) {
if (!config_only) {
ISC_TRUE);
if (firstarg) {
goto next_line;
bargc++;
if (firstarg) {
* Callback from dighost.c to allow program-specific shutdown code. Here,
dighost_shutdown(void) {
int bargc;
char *input;
bargc++;
start_lookup();
setup_libs();
setup_system();
isc_app_run();
while (s != NULL) {
s, default_lookup);
s2 = s;
cancel_all();
destroy_libs();
return (exitcode);