dig.c revision 38cf6e52ce4b33795713388824b69d78e430b115
/*
* Copyright (C) 2000 Internet Software Consortium.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
* ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
* CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
* SOFTWARE.
*/
/* $Id: dig.c,v 1.56 2000/07/05 23:28:27 mws Exp $ */
#include <config.h>
#include <stdlib.h>
#include <dns/rdataset.h>
#include <dns/rdatatype.h>
#define ADD_STRING(b, s) { \
if (strlen(s) >= isc_buffer_availablelength(b)) \
return (ISC_R_NOSPACE); \
else \
isc_buffer_putstr(b, s); \
}
extern unsigned int timeout;
extern dns_messageid_t id;
extern isc_buffer_t rootbuf;
extern int sendcount;
extern int ndots;
extern int tries;
extern int lookup_counter;
extern char fixeddomain[MXNAME];
extern int exitcode;
extern isc_sockaddr_t bind_address;
extern char keynametext[MXNAME];
extern dns_tsigkey_t *key;
extern isc_boolean_t validated;
extern isc_taskmgr_t *taskmgr;
extern isc_boolean_t debugging;
extern isc_boolean_t isc_mem_debugging;
isc_uint16_t bufsize = 0;
static const char *opcodetext[] = {
"QUERY",
"IQUERY",
"STATUS",
"RESERVED3",
"NOTIFY",
"UPDATE",
"RESERVED6",
"RESERVED7",
"RESERVED8",
"RESERVED9",
"RESERVED10",
"RESERVED11",
"RESERVED12",
"RESERVED13",
"RESERVED14",
"RESERVED15"
};
static const char *rcodetext[] = {
"NOERROR",
"FORMERR",
"SERVFAIL",
"NXDOMAIN",
"NOTIMPL",
"REFUSED",
"YXDOMAIN",
"YXRRSET",
"NXRRSET",
"NOTAUTH",
"NOTZONE",
"RESERVED11",
"RESERVED12",
"RESERVED13",
"RESERVED14",
"RESERVED15",
"BADVERS"
};
extern char *progname;
static void
show_usage(void) {
"Usage: dig [@global-server] [domain] [q-type] [q-class] {q-opt}\n"
" {global-d-opt} host [@local-server] {local-d-opt}\n"
" [ host [@local-server] {local-d-opt} [...]]\n"
"Where: domain are in the Domain Name System\n"
" q-class is one of (in,chaos,...) [default: in]\n"
" q-type is one of (a,any,mx,ns,soa,hinfo,axfr,txt,...) [default:a]\n"
" (Use ixfr=version for type ixfr)\n"
" q-opt is one of:\n"
" -x dot-notation (shortcut for in-addr lookups)\n"
" -f filename (batch mode)\n"
" -p port (specify port number)\n"
" -t type (specify query type)\n"
" -c class (specify query class)\n"
" -y name:key (specify named base64 tsig key)\n"
" d-opt is of the form +keyword[=value], where keyword is:\n"
" +[no]vc (TCP mode)\n"
" +[no]tcp (TCP mode, alternate syntax)\n"
" +time=### (Set query timeout) [5]\n"
" +tries=### (Set number of UDP attempts) [3]\n"
" +domain=### (Set default domainname)\n"
" +bufsize=### (Set EDNS0 Max UDP packet size)\n"
" +[no]search (Set whether to use searchlist)\n"
" +[no]defname (Set whether to use default domaon)\n"
" +[no]recursive (Recursive mode)\n"
" +[no]aaonly (Set AA flag in query)\n"
" +[no]details (Show details of all requests)\n"
" +ndots=### (Set NDOTS value)\n"
" +[no]comments (Control display of comment lines)\n"
" +[no]question (Control display of question)\n"
" +[no]answer (Control display of answer)\n"
" +[no]authority (Control display of authority)\n"
" +[no]additional (Control display of additional)\n"
" +[no]short (Disable everything except short\n"
" form of answer)\n"
" +qr (Print question before sending)\n"
" +[no]cdflag (Set or clear CD flag in query)\n"
" +[no]adflag (Set or clear AD flag in query)\n"
" +[no]nssearch (Search all authorative nameservers)\n"
" +[no]identify (ID responders in short answers)\n"
" +[no]trace (Trace delegation down from root)\n"
" global d-opts and servers (before host name) affect all queries.\n"
" local d-opts and servers (after host name) affect only that lookup.\n"
, stderr);
}
void
dighost_shutdown(void) {
free_lists();
}
void
if (!validated)
puts(";; WARNING -- Some TSIG could not "
"be validated");
}
puts(";; WARNING -- TSIG key was not used.");
}
puts("");
printf(";; Received %u bytes from %.*s in %d ms\n",
}
}
void
}
static isc_result_t
char store[sizeof("12345678901234567890")];
if (result != ISC_R_SUCCESS)
return (result);
}
if (result != ISC_R_SUCCESS)
return (result);
}
return (ISC_R_SUCCESS);
}
static isc_result_t
{
char t[4096];
if (result == ISC_R_NOMORE)
return (ISC_R_SUCCESS);
else if (result != ISC_R_SUCCESS)
return (result);
for (;;) {
isc_buffer_init(&target, t, sizeof(t));
while (loopresult == ISC_R_SUCCESS) {
buf);
}
}
if (result == ISC_R_NOMORE)
break;
else if (result != ISC_R_SUCCESS)
return (result);
}
return (ISC_R_SUCCESS);
}
/*
* Exitcode 9 means we timed out, but if we're printing a message,
* we must have recovered. Go ahead and reset it to code 0, and
* call this a success.
*/
if (exitcode == 9)
exitcode = 0;
flags = 0;
if (!headers) {
}
printf(";; Sending:\n");
else
printf(";; Got answer:\n");
}
if (headers) {
printf(";; ->>HEADER<<- opcode: %s, status: %s, "
"id: %u\n",
printf(";; flags: ");
printf("qr");
}
}
}
}
}
}
printf("; QUERY: %u, ANSWER: %u, "
"AUTHORITY: %u, ADDITIONAL: %u\n",
"dns_message_pseudosectiontotext");
}
}
if (!short_form) {
if (result == ISC_R_NOSPACE) {
if (result == ISC_R_SUCCESS)
goto question_again;
}
}
}
if (!short_form) {
if (result == ISC_R_NOSPACE) {
if (result == ISC_R_SUCCESS)
goto answer_again;
}
} else {
}
}
if (!short_form) {
if (result == ISC_R_NOSPACE) {
if (result == ISC_R_SUCCESS)
goto authority_again;
}
}
}
if (!short_form) {
if (result == ISC_R_NOSPACE) {
if (result == ISC_R_SUCCESS)
goto additional_again;
}
/*
* Only print the signature on the first record.
*/
if (headers) {
msg,
"dns_message_pseudosectiontotext");
msg,
"dns_message_pseudosectiontotext");
}
}
}
printf("\n");
(char *)isc_buffer_base(buf));
return (result);
}
static void
int i = 1;
if (printcmd) {
puts("");
printf("; <<>> DiG 9.0 <<>>");
while (i < argc) {
}
puts("");
printf(";; global options: %s %s\n",
}
}
/*
* Reorder an argument list so that server names all come at the end.
* This is a bit of a hack, to allow batch-mode processing to properly
* handle the server options.
*/
static void
int i, j;
char *ptr;
int end;
debug("reorder_args()");
end--;
if (end == 0)
return;
}
if (argv[i][0] == '@') {
for (j = i + 1; j < end; j++) {
}
end--;
if (end < 1)
return;
}
}
}
/*
* We're not using isc_commandline_parse() here since the command line
* syntax of dig is quite a bit different from that which can be described
* that routine. There is a portability issue here.
*/
static void
int bargc;
char *bargv[16];
char bargv0[sizeof("dig")];
int i, n;
int adrs[4];
int rc;
char **rv;
char *ptr;
/*
* The semantics for parsing the args is a bit complex; if
* we don't have a host yet, make the arg apply globally,
* otherwise make it apply to the latest host. This is
* a bit different than the previous versions, but should
* form a consistent user interface.
*/
break;
sizeof(struct dig_server));
fatal("Memory allocation failure");
if (is_batchfile && have_host) {
if (!lookup->use_my_server_list) {
}
} else {
}
&& (!is_batchfile)) {
if (have_host)
else
&& (!is_batchfile)) {
if (have_host)
else
&& (!is_batchfile)) {
if (have_host)
else
&& (!is_batchfile)) {
if (have_host)
else
/* Global option always */
/* Global option always */
if (have_host)
else
if (have_host)
else
/* Global option always */
if (timeout <= 0)
timeout = 1;
if (have_host) {
} else {
if (tries <= 0)
tries = 1;
}
if (have_host) {
} else {
if (bufsize <= 0)
bufsize = 0;
}
if (have_host) {
} else {
if (bufsize <= 0)
bufsize = 0;
}
/* Global option always */
if (ndots < 0)
ndots = 0;
if (have_host)
else
if (have_host)
else
if (have_host)
else
if (have_host)
else
if (have_host)
else
if (have_host)
else
if (have_host)
else
if (have_host)
else
if (have_host) {
if (!forcecomment)
} else {
if (!forcecomment)
}
if (have_host)
else
if (have_host) {
if (!forcecomment) {
}
} else {
if (!forcecomment) {
}
}
if (have_host) {
}
else
if (have_host) {
if (!forcecomment) {
}
} else {
if (!forcecomment) {
}
}
if (have_host)
else
if (have_host)
else
if (have_host)
else
if (have_host) {
} else {
}
if (have_host)
else
if (have_host)
else
if (have_host)
else
if (have_host)
else
if (have_host)
else
if (have_host)
else
if (have_host)
else
if (have_host)
else
if (have_host)
else
if (have_host)
else
if (have_host) {
} else {
}
if (have_host) {
} else {
}
if (have_host) {
if (rv[0][2] != 0) {
MXRD);
} else {
MXRD);
rv++;
rc--;
}
}
if (have_host) {
if (rv[0][2] != 0) {
MXRD);
} else {
MXRD);
rv++;
rc--;
}
}
if (rv[0][2] != 0) {
} else {
rv++;
rc--;
}
if (rv[0][2] != 0)
else {
rv++;
rc--;
}
show_usage();
}
show_usage();
}
if (rv[0][2] != 0) {
} else {
rv++;
rc--;
}
if (rv[0][2] != 0) {
MXRD);
} else {
MXRD);
rv++;
rc--;
}
show_usage();
isc_mem_debugging = 1;
/*
* XXXMWS Only works for ipv4 now.
* Can't use inet_pton here, since we allow
* partial addresses.
*/
if (rc == 1) {
show_usage();
}
if (n == 0)
show_usage();
sizeof(struct dig_lookup));
fatal("Memory allocation failure");
for (i = n - 1; i >= 0; i--) {
adrs[i]);
}
lookup->ixfr_serial = 0;
ISC_LIST_INIT(lookup->q);
rv++;
rc--;
} else {
if (have_host) {
continue;
}
continue;
MXRD);
continue;
}
}
sizeof(struct dig_lookup));
fatal("Memory allocation failure");
lookup->ixfr_serial = 0;
ISC_LIST_INIT(lookup->q);
}
}
if (exitcode < 10)
exitcode = 10;
fatal("Couldn't open specified batch file");
}
bargc = 1;
bargc++;
}
/*
* This silliness (instead of ``bargv[0] = "dig";'')
* dances around the const string issue. If in
* the future the 2nd argument to strncpy() is made
* longer than three characters, don't forget to resize
* bargv0 to accommodate it.
*/
}
}
fatal("Memory allocation failure");
lookup->ixfr_serial = 0;
ISC_LIST_INIT(lookup->q);
}
if (!is_batchfile)
}
int
debug("main()");
setup_libs();
setup_system();
start_lookup();
isc_app_run();
/*
* XXXMWS This code should really NOT be bypassed. However,
* correctly, just exit out "hard" and deal as best we can.
*/
#if 0
debug ("Freeing taskmgr");
}
if (isc_mem_debugging)
#endif
return (exitcode);
}