dig.c revision 368b37b616234fce3d23099eb180f1dd38e1fb62
9ffbbce6a624b6051b3d001edcbad1e02c69bd45Andreas Gustafsson * Copyright (C) 2000 Internet Software Consortium.
9ffbbce6a624b6051b3d001edcbad1e02c69bd45Andreas Gustafsson * Permission to use, copy, modify, and distribute this software for any
9ffbbce6a624b6051b3d001edcbad1e02c69bd45Andreas Gustafsson * purpose with or without fee is hereby granted, provided that the above
9ffbbce6a624b6051b3d001edcbad1e02c69bd45Andreas Gustafsson * copyright notice and this permission notice appear in all copies.
9ffbbce6a624b6051b3d001edcbad1e02c69bd45Andreas Gustafsson * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
9ffbbce6a624b6051b3d001edcbad1e02c69bd45Andreas Gustafsson * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
9ffbbce6a624b6051b3d001edcbad1e02c69bd45Andreas Gustafsson * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
9ffbbce6a624b6051b3d001edcbad1e02c69bd45Andreas Gustafsson * INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
9ffbbce6a624b6051b3d001edcbad1e02c69bd45Andreas Gustafsson * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
9ffbbce6a624b6051b3d001edcbad1e02c69bd45Andreas Gustafsson * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
9ffbbce6a624b6051b3d001edcbad1e02c69bd45Andreas Gustafsson * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
9ffbbce6a624b6051b3d001edcbad1e02c69bd45Andreas Gustafsson * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
9ffbbce6a624b6051b3d001edcbad1e02c69bd45Andreas Gustafsson/* $Id: dig.c,v 1.124 2000/10/31 03:21:35 marka Exp $ */
9ffbbce6a624b6051b3d001edcbad1e02c69bd45Andreas Gustafssonextern ISC_LIST(dig_lookup_t) lookup_list;
9ffbbce6a624b6051b3d001edcbad1e02c69bd45Andreas Gustafssonextern ISC_LIST(dig_searchlist_t) search_list;
9ffbbce6a624b6051b3d001edcbad1e02c69bd45Andreas Gustafsson#define ADD_STRING(b, s) { \
9ffbbce6a624b6051b3d001edcbad1e02c69bd45Andreas Gustafsson if (strlen(s) >= isc_buffer_availablelength(b)) \
9ffbbce6a624b6051b3d001edcbad1e02c69bd45Andreas Gustafssonextern isc_boolean_t have_ipv6, specified_source,
9ffbbce6a624b6051b3d001edcbad1e02c69bd45Andreas Gustafssonextern unsigned int timeout;
9ffbbce6a624b6051b3d001edcbad1e02c69bd45Andreas Gustafssonextern isc_boolean_t debugging, memdebugging;
9ffbbce6a624b6051b3d001edcbad1e02c69bd45Andreas Gustafssonisc_boolean_t short_form = ISC_FALSE, printcmd = ISC_TRUE,
9ffbbce6a624b6051b3d001edcbad1e02c69bd45Andreas Gustafsson nibble = ISC_FALSE, plusquest = ISC_FALSE, pluscomm = ISC_FALSE;
9ffbbce6a624b6051b3d001edcbad1e02c69bd45Andreas Gustafssonstatic const char *opcodetext[] = {
9ffbbce6a624b6051b3d001edcbad1e02c69bd45Andreas Gustafssonstatic const char *rcodetext[] = {
9ffbbce6a624b6051b3d001edcbad1e02c69bd45Andreas Gustafsson"Usage: dig [@global-server] [domain] [q-type] [q-class] {q-opt}\n"
8eea877894ea5bcf5cdd9ca124a8601ad421d753Andreas Gustafsson" {global-d-opt} host [@local-server] {local-d-opt}\n"
8eea877894ea5bcf5cdd9ca124a8601ad421d753Andreas Gustafsson" [ host [@local-server] {local-d-opt} [...]]\n"
9ffbbce6a624b6051b3d001edcbad1e02c69bd45Andreas Gustafsson"Where: domain are in the Domain Name System\n"
9ffbbce6a624b6051b3d001edcbad1e02c69bd45Andreas Gustafsson" q-class is one of (in,hs,ch,...) [default: in]\n"
9ffbbce6a624b6051b3d001edcbad1e02c69bd45Andreas Gustafsson" q-type is one of (a,any,mx,ns,soa,hinfo,axfr,txt,...) [default:a]\n"
8eea877894ea5bcf5cdd9ca124a8601ad421d753Andreas Gustafsson" (Use ixfr=version for type ixfr)\n"
8eea877894ea5bcf5cdd9ca124a8601ad421d753Andreas Gustafsson" q-opt is one of:\n"
8eea877894ea5bcf5cdd9ca124a8601ad421d753Andreas Gustafsson" -x dot-notation (shortcut for in-addr lookups)\n"
8eea877894ea5bcf5cdd9ca124a8601ad421d753Andreas Gustafsson" -n (nibble form for reverse IPv6 lookups)\n"
8eea877894ea5bcf5cdd9ca124a8601ad421d753Andreas Gustafsson" -f filename (batch mode)\n"
8eea877894ea5bcf5cdd9ca124a8601ad421d753Andreas Gustafsson" -p port (specify port number)\n"
8eea877894ea5bcf5cdd9ca124a8601ad421d753Andreas Gustafsson" -t type (specify query type)\n"
8eea877894ea5bcf5cdd9ca124a8601ad421d753Andreas Gustafsson" -c class (specify query class)\n"
9ffbbce6a624b6051b3d001edcbad1e02c69bd45Andreas Gustafsson" -y name:key (specify named base64 tsig key)\n"
9ffbbce6a624b6051b3d001edcbad1e02c69bd45Andreas Gustafsson" d-opt is of the form +keyword[=value], where keyword is:\n"
9ffbbce6a624b6051b3d001edcbad1e02c69bd45Andreas Gustafsson" +[no]vc (TCP mode)\n"
9ffbbce6a624b6051b3d001edcbad1e02c69bd45Andreas Gustafsson" +[no]tcp (TCP mode, alternate syntax)\n"
9ffbbce6a624b6051b3d001edcbad1e02c69bd45Andreas Gustafsson" +time=### (Set query timeout) [5]\n"
9ffbbce6a624b6051b3d001edcbad1e02c69bd45Andreas Gustafsson" +tries=### (Set number of UDP attempts) [3]\n"
9ffbbce6a624b6051b3d001edcbad1e02c69bd45Andreas Gustafsson" +domain=### (Set default domainname)\n"
9ffbbce6a624b6051b3d001edcbad1e02c69bd45Andreas Gustafsson" +bufsize=### (Set EDNS0 Max UDP packet size)\n"
9ffbbce6a624b6051b3d001edcbad1e02c69bd45Andreas Gustafsson" +[no]search (Set whether to use searchlist)\n"
9ffbbce6a624b6051b3d001edcbad1e02c69bd45Andreas Gustafsson" +[no]defname (Set whether to use default domain)\n"
9ffbbce6a624b6051b3d001edcbad1e02c69bd45Andreas Gustafsson" +[no]recursive (Recursive mode)\n"
9ffbbce6a624b6051b3d001edcbad1e02c69bd45Andreas Gustafsson" +[no]ignore (Don't revert to TCP for TC responses.)"
9ffbbce6a624b6051b3d001edcbad1e02c69bd45Andreas Gustafsson" +[no]fail (Don't try next server on SERVFAIL)\n"
9ffbbce6a624b6051b3d001edcbad1e02c69bd45Andreas Gustafsson" +[no]besteffort (Try to parse even illegal messages)\n"
9ffbbce6a624b6051b3d001edcbad1e02c69bd45Andreas Gustafsson" +[no]aaonly (Set AA flag in query)\n"
9ffbbce6a624b6051b3d001edcbad1e02c69bd45Andreas Gustafsson" +[no]adflag (Set AD flag in query)\n"
9ffbbce6a624b6051b3d001edcbad1e02c69bd45Andreas Gustafsson" +[no]cdflag (Set CD flag in query)\n"
9ffbbce6a624b6051b3d001edcbad1e02c69bd45Andreas Gustafsson" +ndots=### (Set NDOTS value)\n"
9ffbbce6a624b6051b3d001edcbad1e02c69bd45Andreas Gustafsson" +[no]cmd (Control display of command line)\n"
9ffbbce6a624b6051b3d001edcbad1e02c69bd45Andreas Gustafsson" +[no]comments (Control display of comment lines)\n"
9ffbbce6a624b6051b3d001edcbad1e02c69bd45Andreas Gustafsson" +[no]question (Control display of question)\n"
9ffbbce6a624b6051b3d001edcbad1e02c69bd45Andreas Gustafsson" +[no]answer (Control display of answer)\n"
9ffbbce6a624b6051b3d001edcbad1e02c69bd45Andreas Gustafsson" +[no]authority (Control display of authority)\n"
9ffbbce6a624b6051b3d001edcbad1e02c69bd45Andreas Gustafsson" +[no]additional (Control display of additional)\n"
9ffbbce6a624b6051b3d001edcbad1e02c69bd45Andreas Gustafsson" +[no]short (Disable everything except short\n"
9ffbbce6a624b6051b3d001edcbad1e02c69bd45Andreas Gustafsson" form of answer)\n"
9ffbbce6a624b6051b3d001edcbad1e02c69bd45Andreas Gustafsson" +[no]all (Set or clear all display flags)\n"
9ffbbce6a624b6051b3d001edcbad1e02c69bd45Andreas Gustafsson" +qr (Print question before sending)\n"
9ffbbce6a624b6051b3d001edcbad1e02c69bd45Andreas Gustafsson" +[no]nssearch (Search all authorative nameservers)\n"
9ffbbce6a624b6051b3d001edcbad1e02c69bd45Andreas Gustafsson" +[no]identify (ID responders in short answers)\n"
9ffbbce6a624b6051b3d001edcbad1e02c69bd45Andreas Gustafsson" +[no]trace (Trace delegation down from root)\n"
9ffbbce6a624b6051b3d001edcbad1e02c69bd45Andreas Gustafsson" +rrlimit=### (Limit number of rr's in xfr)\n"
9ffbbce6a624b6051b3d001edcbad1e02c69bd45Andreas Gustafsson" +namelimit=### (Limit number of names in xfr)\n"
9ffbbce6a624b6051b3d001edcbad1e02c69bd45Andreas Gustafsson" global d-opts and servers (before host name) affect all queries.\n"
9ffbbce6a624b6051b3d001edcbad1e02c69bd45Andreas Gustafsson" local d-opts and servers (after host name) affect only that lookup.\n"
9ffbbce6a624b6051b3d001edcbad1e02c69bd45Andreas Gustafsson * Callback from dighost.c to print the received message.
9ffbbce6a624b6051b3d001edcbad1e02c69bd45Andreas Gustafssonreceived(int bytes, int frmsize, char *frm, dig_query_t *query) {
9ffbbce6a624b6051b3d001edcbad1e02c69bd45Andreas Gustafsson diff = isc_time_microdiff(&now, &query->time_sent);
9ffbbce6a624b6051b3d001edcbad1e02c69bd45Andreas Gustafsson printf(";; Query time: %ld msec\n", (long int)diff/1000);
9ffbbce6a624b6051b3d001edcbad1e02c69bd45Andreas Gustafsson printf(";; SERVER: %.*s(%s)\n", frmsize, frm,
9ffbbce6a624b6051b3d001edcbad1e02c69bd45Andreas Gustafsson printf(";; XFR size: %d names, %d rrs\n",
9ffbbce6a624b6051b3d001edcbad1e02c69bd45Andreas Gustafsson puts(";; WARNING -- Some TSIG could not "
9ffbbce6a624b6051b3d001edcbad1e02c69bd45Andreas Gustafsson "be validated");
9ffbbce6a624b6051b3d001edcbad1e02c69bd45Andreas Gustafsson if ((key == NULL) && (keysecret[0] != 0)) {
ddccd5811feff696ba460dabfb666ce61040f545Andreas Gustafsson puts(";; WARNING -- TSIG key was not used.");
ddccd5811feff696ba460dabfb666ce61040f545Andreas Gustafsson } else if (query->lookup->identify && !short_form) {
9ffbbce6a624b6051b3d001edcbad1e02c69bd45Andreas Gustafsson diff = isc_time_microdiff(&now, &query->time_sent);
ddccd5811feff696ba460dabfb666ce61040f545Andreas Gustafsson printf(";; Received %u bytes from %.*s(%s) in %d ms\n\n",
9ffbbce6a624b6051b3d001edcbad1e02c69bd45Andreas Gustafsson * Callback from dighost.c to print that it is trying a server.
9ffbbce6a624b6051b3d001edcbad1e02c69bd45Andreas Gustafsson * Not used in dig.
9ffbbce6a624b6051b3d001edcbad1e02c69bd45Andreas Gustafsson * XXX print_trying
ddccd5811feff696ba460dabfb666ce61040f545Andreas Gustafssontrying(int frmsize, char *frm, dig_lookup_t *lookup) {
9ffbbce6a624b6051b3d001edcbad1e02c69bd45Andreas Gustafsson * Internal print routine used to print short form replies.
9ffbbce6a624b6051b3d001edcbad1e02c69bd45Andreas Gustafssonsay_message(dns_rdata_t *rdata, dig_query_t *query, isc_buffer_t *buf) {
ddccd5811feff696ba460dabfb666ce61040f545Andreas Gustafsson char store[sizeof("12345678901234567890")];
ddccd5811feff696ba460dabfb666ce61040f545Andreas Gustafsson if (query->lookup->trace || query->lookup->ns_search_only) {
ddccd5811feff696ba460dabfb666ce61040f545Andreas Gustafsson result = dns_rdatatype_totext(rdata->type, buf);
return (result);
return (ISC_R_SUCCESS);
static isc_result_t
return (ISC_R_SUCCESS);
return (result);
buf);
return (result);
return (ISC_R_SUCCESS);
* Callback from dighost.c to print the reply from a server
flags = 0;
if (!headers) {
if (headers) {
if (!short_form) {
goto question_again;
if (!short_form) {
goto answer_again;
if (!short_form) {
goto authority_again;
if (!short_form) {
goto additional_again;
if (headers) {
msg,
msg,
return (result);
if (printcmd) {
while (i < argc) {
if (first) {
char *ptr;
int end;
end--;
if (end == 0)
end--;
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;
goto need_value;
if (!state)
goto invalid_option;
if (ndots < 0)
ndots = 0;
if (state) {
goto invalid_option;
goto invalid_option;
goto need_value;
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;
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);
show_usage();
static isc_boolean_t
switch (cmd) {
return (ISC_FALSE);
show_usage();
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);
return (value_from_next);
value);
return (value_from_next);
show_usage();
show_usage();
return (value_from_next);
return (value_from_next);
show_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++;
* 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);