dig.c revision 1a69a1a78cfaa86f3b68bbc965232b7876d4da2a
/*
* 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.
*/
#include <config.h>
#include <stdlib.h>
extern int h_errno;
#include <dns/rdataset.h>
#include <dns/rdatatype.h>
extern unsigned int timeout;
extern isc_taskmgr_t *taskmgr;
extern isc_task_t *task;
extern isc_timermgr_t *timermgr;
extern isc_socketmgr_t *socketmgr;
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];
#ifdef TWIDDLE
extern isc_boolean_t twiddle;
#endif
static char *opcodetext[] = {
"QUERY",
"IQUERY",
"STATUS",
"RESERVED3",
"NOTIFY",
"UPDATE",
"RESERVED6",
"RESERVED7",
"RESERVED8",
"RESERVED9",
"RESERVED10",
"RESERVED11",
"RESERVED12",
"RESERVED13",
"RESERVED14",
"RESERVED15"
};
static char *rcodetext[] = {
"NOERROR",
"FORMERR",
"SERVFAIL",
"NXDOMAIN",
"NOTIMPL",
"REFUSED",
"YXDOMAIN",
"YXRRSET",
"NXRRSET",
"NOTAUTH",
"NOTZONE",
"RESERVED11",
"RESERVED12",
"RESERVED13",
"RESERVED14",
"RESERVED15",
"BADVERS"
};
static void
show_usage() {
fputs (
"Usage: dig [@server] [domain] [q-type] [q-class] {q-opt} {d-opt}\n"
"where: server,\n"
" 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"
" 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"
" 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"
" +[no]search (Set whether to use searchlist)\n"
" +[no]recursive (Recursive mode)\n"
" +[no]details (Show details of all requests)\n"
#ifdef TWIDDLE
" +twiddle (Intentionally form bad requests)\n"
#endif
" +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"
" Additional d-opts subject to removal before release:\n"
" +[no]nssearch (Search all authorative nameservers)\n"
" +[no]identify (ID responders in short answers)\n"
" Available but not yet completed:\n"
" +[no]trace (Trace delegation down from root)\n"
, stderr);
}
void
}
}
if (still_working)
return;
debug ("Have %d retries left for %s\n",
return;
}
if (tcp_mode) {
} else {
} else {
}
}
}
void
printf(";; Received %u bytes from %.*s\n",
printf(";; Received %u bytes from %.*s in %d ms\n",
}
}
void
}
static void
isc_region_t r, r2;
isc_buffer_usedregion(b, &r);
else {
isc_buffer_free (&b2);
}
(int)diff/1000);
}
printf ("\n");
isc_buffer_free(&b);
}
static isc_result_t
{
isc_region_t r;
char t[4096];
if (sectionid == DNS_SECTION_QUESTION)
else
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));
print_name = name;
if (!short_form) {
&target);
if (result != ISC_R_SUCCESS)
return (result);
#ifdef USEINITALWS
if (first) {
print_name = &empty_name;
}
#endif
} else {
while (loopresult == ISC_R_SUCCESS) {
rdataset);
}
}
}
isc_buffer_usedregion(&target, &r);
if (no_rdata)
else
if (result == ISC_R_NOMORE)
break;
else if (result != ISC_R_SUCCESS)
return (result);
}
return (ISC_R_SUCCESS);
}
static isc_result_t
{
isc_region_t r;
char t[4096];
if (headers)
isc_buffer_init(&target, t, sizeof(t));
&target);
if (result != ISC_R_SUCCESS)
return (result);
isc_buffer_usedregion(&target, &r);
return (ISC_R_SUCCESS);
}
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",
}
printf(";; EDNS: version: %u, udp=%u\n",
0x00ff0000) >> 16),
printf(";; PSEUDOSECTIONS: TSIG\n");
}
}
printf("\n");
if (result != ISC_R_SUCCESS)
return (result);
}
printf("\n");
if (result != ISC_R_SUCCESS)
return (result);
}
printf("\n");
if (result != ISC_R_SUCCESS)
return (result);
}
printf("\n");
if (result != ISC_R_SUCCESS)
return (result);
}
printf("\n");
"PSEUDOSECTION TSIG", ISC_TRUE);
if (result != ISC_R_SUCCESS)
return (result);
}
printf("\n");
return (result);
}
/*
* 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.
*/
void
int bargc;
char *bargv[16];
int i, n;
int adrs[4];
fatal("Memory allocation failure.");
if (is_batchfile && have_host) {
if (!lookup->use_my_server_list) {
}
} else {
}
&& (!is_batchfile)) {
&& (!is_batchfile)) {
&& (!is_batchfile)) {
&& (!is_batchfile)) {
if (timeout <= 0)
timeout = 1;
if (tries <= 0)
tries = 1;
if (timeout <= 0)
timeout = 1;
if (!forcecomment)
if (!forcecomment)
if (!forcecomment)
#ifdef TWIDDLE
#endif
if (have_host) {
if (argv[0][2]!=0) {
MXRD);
} else {
MXRD);
argv++;
argc--;
}
}
if (have_host) {
if (argv[0][2]!=0) {
MXRD);
} else {
MXRD);
argv++;
argc--;
}
}
if (argv[0][2]!=0) {
} else {
argv++;
argc--;
}
if (argv[0][2]!=0) {
} else {
argv++;
argc--;
}
show_usage();
exit (0);
if (n == 0)
show_usage();
if (lookup_counter > LOOKUP_LIMIT)
fatal ("Too many lookups.");
sizeof(struct dig_lookup));
fatal("Memory allocation failure.");
for (i = n - 1; i >= 0; i--) {
adrs[i]);
}
ISC_LIST_INIT(lookup->q);
argv++;
argc--;
} else {
if (have_host) {
continue;
MXRD);
continue;
}
}
if (lookup_counter > LOOKUP_LIMIT)
fatal ("Too many lookups.");
sizeof(struct dig_lookup));
fatal("Memory allocation failure.");
ISC_LIST_INIT(lookup->q);
}
}
fatal("Couldn't open specified batch file.");
}
bargc=1;
(bargc < 14 )) {
bargc++;
}
bargc--;
bargv[0]="dig";
}
}
if (lookup_counter > LOOKUP_LIMIT)
fatal ("Too many lookups.");
fatal("Memory allocation failure.");
ISC_LIST_INIT(lookup->q);
}
}