2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-09-03 16:15:27 +00:00

Change command line options for dig. In particular, +short option added,

so users can easily get (for example) SOA list from all authorative servers
with 'dig +short +nssearch isc.org soa' rather than stringing dozens of
options together.  (Rather these options remain or are removed in the
release version is still subject to discussion.)
This commit is contained in:
Michael Sawyer
2000-05-04 21:40:47 +00:00
parent 6d7909017d
commit c4ae16b2aa
3 changed files with 136 additions and 46 deletions

View File

@@ -62,7 +62,7 @@ extern ISC_LIST(dig_lookup_t) lookup_list;
extern ISC_LIST(dig_server_t) server_list; extern ISC_LIST(dig_server_t) server_list;
extern isc_boolean_t tcp_mode, have_ipv6, show_details, extern isc_boolean_t tcp_mode, have_ipv6, show_details,
usesearch; usesearch, trace;
extern in_port_t port; extern in_port_t port;
extern unsigned int timeout; extern unsigned int timeout;
extern isc_mem_t *mctx; extern isc_mem_t *mctx;
@@ -87,6 +87,7 @@ isc_boolean_t comments = ISC_TRUE, section_question = ISC_TRUE,
section_answer = ISC_TRUE, section_authority = ISC_TRUE, section_answer = ISC_TRUE, section_authority = ISC_TRUE,
section_additional = ISC_TRUE, recurse = ISC_TRUE; section_additional = ISC_TRUE, recurse = ISC_TRUE;
static char *opcodetext[] = { static char *opcodetext[] = {
"QUERY", "QUERY",
"IQUERY", "IQUERY",
@@ -149,8 +150,6 @@ show_usage() {
" +[no]search (Set whether to use searchlist)\n" " +[no]search (Set whether to use searchlist)\n"
" +[no]recursive (Recursive mode)\n" " +[no]recursive (Recursive mode)\n"
" +[no]details (Show details of all requests)\n" " +[no]details (Show details of all requests)\n"
" +[no]nssearch (Search for info on all authorative\n"
" nameservers for the domain.)\n"
#ifdef TWIDDLE #ifdef TWIDDLE
" +twiddle (Intentionally form bad requests)\n" " +twiddle (Intentionally form bad requests)\n"
#endif #endif
@@ -160,6 +159,13 @@ show_usage() {
" +[no]answer (Control display of answer)\n" " +[no]answer (Control display of answer)\n"
" +[no]authority (Control display of authority)\n" " +[no]authority (Control display of authority)\n"
" +[no]additional (Control display of additional)\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); , stderr);
} }
@@ -231,6 +237,25 @@ trying(int frmsize, char *frm, dig_lookup_t *lookup) {
} }
static void
say_message(dns_rdata_t *rdata, dig_query_t *query) {
isc_buffer_t *b=NULL;
isc_region_t r;
isc_result_t result;
result = isc_buffer_allocate(mctx, &b, BUFSIZE);
check_result (result, "isc_buffer_allocate");
result = dns_rdata_totext(rdata, NULL, b);
check_result(result, "dns_rdata_totext");
isc_buffer_usedregion(b, &r);
printf ( "%.*s", (int)r.length, (char *)r.base);
if (query->lookup->identify) {
printf (" on server %s", query->servname);
}
printf ("\n");
isc_buffer_free(&b);
}
static isc_result_t static isc_result_t
printsection(dns_message_t *msg, dns_section_t sectionid, char *section_name, printsection(dns_message_t *msg, dns_section_t sectionid, char *section_name,
isc_boolean_t headers, dig_query_t *query) isc_boolean_t headers, dig_query_t *query)
@@ -238,12 +263,13 @@ printsection(dns_message_t *msg, dns_section_t sectionid, char *section_name,
dns_name_t *name, *print_name; dns_name_t *name, *print_name;
dns_rdataset_t *rdataset; dns_rdataset_t *rdataset;
isc_buffer_t target; isc_buffer_t target;
isc_result_t result; isc_result_t result, loopresult;
isc_region_t r; isc_region_t r;
dns_name_t empty_name; dns_name_t empty_name;
char t[4096]; char t[4096];
isc_boolean_t first; isc_boolean_t first;
isc_boolean_t no_rdata; isc_boolean_t no_rdata;
dns_rdata_t rdata;
if (sectionid == DNS_SECTION_QUESTION) if (sectionid == DNS_SECTION_QUESTION)
no_rdata = ISC_TRUE; no_rdata = ISC_TRUE;
@@ -272,19 +298,30 @@ printsection(dns_message_t *msg, dns_section_t sectionid, char *section_name,
for (rdataset = ISC_LIST_HEAD(name->list); for (rdataset = ISC_LIST_HEAD(name->list);
rdataset != NULL; rdataset != NULL;
rdataset = ISC_LIST_NEXT(rdataset, link)) { rdataset = ISC_LIST_NEXT(rdataset, link)) {
result = dns_rdataset_totext(rdataset, if (!short_form) {
print_name, result = dns_rdataset_totext(rdataset,
ISC_FALSE, print_name,
no_rdata, ISC_FALSE,
&target); no_rdata,
if (result != ISC_R_SUCCESS) &target);
return (result); if (result != ISC_R_SUCCESS)
return (result);
#ifdef USEINITALWS #ifdef USEINITALWS
if (first) { if (first) {
print_name = &empty_name; print_name = &empty_name;
first = ISC_FALSE; first = ISC_FALSE;
} }
#endif #endif
} else {
loopresult = dns_rdataset_first(rdataset);
while (loopresult == ISC_R_SUCCESS) {
dns_rdataset_current(rdataset, &rdata);
say_message(&rdata, query);
loopresult = dns_rdataset_next(
rdataset);
}
}
} }
isc_buffer_usedregion(&target, &r); isc_buffer_usedregion(&target, &r);
if (no_rdata) if (no_rdata)
@@ -484,7 +521,7 @@ reorder_args(int argc, char *argv[]) {
*/ */
void void
parse_args(isc_boolean_t is_batchfile, int argc, char **argv) { parse_args(isc_boolean_t is_batchfile, int argc, char **argv) {
isc_boolean_t have_host = ISC_FALSE; isc_boolean_t have_host = ISC_FALSE, identify = ISC_FALSE;
dig_server_t *srv = NULL; dig_server_t *srv = NULL;
dig_lookup_t *lookup = NULL; dig_lookup_t *lookup = NULL;
char *batchname = NULL; char *batchname = NULL;
@@ -550,12 +587,34 @@ parse_args(isc_boolean_t is_batchfile, int argc, char **argv) {
recurse = ISC_FALSE; recurse = ISC_FALSE;
} else if (strncmp(argv[0], "+ns", 3) == 0) { } else if (strncmp(argv[0], "+ns", 3) == 0) {
ns_search_only = ISC_TRUE; ns_search_only = ISC_TRUE;
recurse = ISC_FALSE;
identify = ISC_TRUE;
} else if (strncmp(argv[0], "+nons", 6) == 0) { } else if (strncmp(argv[0], "+nons", 6) == 0) {
ns_search_only = ISC_FALSE; ns_search_only = ISC_FALSE;
} else if (strncmp(argv[0], "+tr", 3) == 0) {
trace = ISC_TRUE;
ns_search_only = ISC_TRUE;
recurse = ISC_FALSE;
} else if (strncmp(argv[0], "+notr", 6) == 0) {
trace = ISC_FALSE;
} else if (strncmp(argv[0], "+det", 4) == 0) { } else if (strncmp(argv[0], "+det", 4) == 0) {
show_details = ISC_TRUE; show_details = ISC_TRUE;
short_form = ISC_FALSE;
} else if (strncmp(argv[0], "+nodet", 6) == 0) { } else if (strncmp(argv[0], "+nodet", 6) == 0) {
show_details = ISC_FALSE; show_details = ISC_FALSE;
} else if (strncmp(argv[0], "+sho", 4) == 0) {
short_form = ISC_TRUE;
show_details = ISC_FALSE;
comments = ISC_FALSE;
section_additional = ISC_FALSE;
section_authority = ISC_FALSE;
section_question = ISC_FALSE;
} else if (strncmp(argv[0], "+nosho", 6) == 0) {
short_form = ISC_FALSE;
} else if (strncmp(argv[0], "+id", 3) == 0) {
identify = ISC_TRUE;
} else if (strncmp(argv[0], "+noid", 5) == 0) {
identify = ISC_FALSE;
} else if (strncmp(argv[0], "+com", 4) == 0) { } else if (strncmp(argv[0], "+com", 4) == 0) {
comments = ISC_TRUE; comments = ISC_TRUE;
} else if (strncmp(argv[0], "+nocom", 6) == 0) { } else if (strncmp(argv[0], "+nocom", 6) == 0) {
@@ -650,10 +709,11 @@ parse_args(isc_boolean_t is_batchfile, int argc, char **argv) {
lookup->oname=NULL; lookup->oname=NULL;
lookup->timer = NULL; lookup->timer = NULL;
lookup->xfr_q = NULL; lookup->xfr_q = NULL;
lookup->origin = NULL;
lookup->use_my_server_list = ISC_FALSE; lookup->use_my_server_list = ISC_FALSE;
lookup->ns_search_only = ns_search_only; lookup->ns_search_only = ns_search_only;
lookup->doing_xfr = ISC_FALSE; lookup->doing_xfr = ISC_FALSE;
lookup->identify = ISC_FALSE; lookup->identify = identify;
lookup->recurse = recurse; lookup->recurse = recurse;
lookup->retries = tries; lookup->retries = tries;
lookup->comments = comments; lookup->comments = comments;
@@ -671,14 +731,14 @@ parse_args(isc_boolean_t is_batchfile, int argc, char **argv) {
} else { } else {
if (have_host) { if (have_host) {
ENSURE(lookup != NULL); ENSURE(lookup != NULL);
if (isclass(argv[0])) { if (istype(argv[0])) {
strncpy(lookup->rctext, argv[0],
MXRD);
continue;
} else if (istype(argv[0])) {
strncpy(lookup->rttext, argv[0], MXRD); strncpy(lookup->rttext, argv[0], MXRD);
continue; continue;
} } else if (isclass(argv[0])) {
strncpy(lookup->rctext, argv[0],
MXRD);
continue;
}
} }
lookup = isc_mem_allocate(mctx, lookup = isc_mem_allocate(mctx,
sizeof(struct dig_lookup)); sizeof(struct dig_lookup));
@@ -695,10 +755,11 @@ parse_args(isc_boolean_t is_batchfile, int argc, char **argv) {
lookup->oname=NULL; lookup->oname=NULL;
lookup->timer = NULL; lookup->timer = NULL;
lookup->xfr_q = NULL; lookup->xfr_q = NULL;
lookup->origin = NULL;
lookup->use_my_server_list = ISC_FALSE; lookup->use_my_server_list = ISC_FALSE;
lookup->doing_xfr = ISC_FALSE; lookup->doing_xfr = ISC_FALSE;
lookup->ns_search_only = ns_search_only; lookup->ns_search_only = ns_search_only;
lookup->identify = ISC_FALSE; lookup->identify = identify;
lookup->recurse = recurse; lookup->recurse = recurse;
lookup->retries = tries; lookup->retries = tries;
lookup->comments = comments; lookup->comments = comments;
@@ -748,10 +809,11 @@ parse_args(isc_boolean_t is_batchfile, int argc, char **argv) {
lookup->oname=NULL; lookup->oname=NULL;
lookup->timer = NULL; lookup->timer = NULL;
lookup->xfr_q = NULL; lookup->xfr_q = NULL;
lookup->origin = NULL;
lookup->use_my_server_list = ISC_FALSE; lookup->use_my_server_list = ISC_FALSE;
lookup->doing_xfr = ISC_FALSE; lookup->doing_xfr = ISC_FALSE;
lookup->ns_search_only = ns_search_only; lookup->ns_search_only = ns_search_only;
lookup->identify = ISC_FALSE; lookup->identify = identify;
lookup->recurse = recurse; lookup->recurse = recurse;
lookup->retries = tries; lookup->retries = tries;
lookup->comments = comments; lookup->comments = comments;
@@ -760,7 +822,6 @@ parse_args(isc_boolean_t is_batchfile, int argc, char **argv) {
lookup->section_authority = section_authority; lookup->section_authority = section_authority;
lookup->section_additional = section_additional; lookup->section_additional = section_additional;
ISC_LIST_INIT(lookup->q); ISC_LIST_INIT(lookup->q);
lookup->origin = NULL;
ISC_LIST_INIT(lookup->my_server_list); ISC_LIST_INIT(lookup->my_server_list);
strcpy(lookup->textname, "."); strcpy(lookup->textname, ".");
strcpy(lookup->rttext, "NS"); strcpy(lookup->rttext, "NS");

View File

@@ -60,7 +60,8 @@ ISC_LIST(dig_server_t) server_list;
ISC_LIST(dig_searchlist_t) search_list; ISC_LIST(dig_searchlist_t) search_list;
isc_boolean_t tcp_mode = ISC_FALSE, have_ipv6 = ISC_FALSE, isc_boolean_t tcp_mode = ISC_FALSE, have_ipv6 = ISC_FALSE,
free_now = ISC_FALSE, show_details = ISC_FALSE, usesearch=ISC_TRUE; free_now = ISC_FALSE, show_details = ISC_FALSE, usesearch=ISC_TRUE,
trace = ISC_FALSE;
#ifdef TWIDDLE #ifdef TWIDDLE
isc_boolean_t twiddle = ISC_FALSE; isc_boolean_t twiddle = ISC_FALSE;
#endif #endif
@@ -479,6 +480,7 @@ followup_lookup(dns_message_t *msg, dig_query_t *query) {
lookup->oname=NULL; lookup->oname=NULL;
lookup->timer = NULL; lookup->timer = NULL;
lookup->xfr_q = NULL; lookup->xfr_q = NULL;
lookup->origin = NULL;
lookup->doing_xfr = ISC_FALSE; lookup->doing_xfr = ISC_FALSE;
lookup->identify = ISC_TRUE; lookup->identify = ISC_TRUE;
lookup->recurse = query->lookup-> lookup->recurse = query->lookup->
@@ -520,9 +522,9 @@ followup_lookup(dns_message_t *msg, dig_query_t *query) {
srv, link); srv, link);
isc_buffer_free (&b); isc_buffer_free (&b);
} }
debug ("Before insertion, init@%ld " debug ("Before insertion, init@%lx "
"-> %ld, new@%ld " "-> %lx, new@%lx "
"-> %ld", (long int)query->lookup, "-> %lx", (long int)query->lookup,
(long int)query->lookup->link.next, (long int)query->lookup->link.next,
(long int)lookup, (long int)lookup-> (long int)lookup, (long int)lookup->
link.next); link.next);
@@ -530,8 +532,8 @@ followup_lookup(dns_message_t *msg, dig_query_t *query) {
lookup, lookup, lookup, lookup,
link); link);
debug ("After insertion, init -> " debug ("After insertion, init -> "
"%ld, new = %ld, " "%lx, new = %lx, "
"new -> %ld", (long int)query-> "new -> %lx", (long int)query->
lookup->link.next, lookup->link.next,
(long int)lookup, (long int)lookup-> (long int)lookup, (long int)lookup->
link.next); link.next);
@@ -639,7 +641,7 @@ setup_lookup(dig_lookup_t *lookup) {
char store[MXNAME]; char store[MXNAME];
debug("setup_lookup()"); debug("setup_lookup()");
debug("Setting up for looking up %s @%ld->%ld", debug("Setting up for looking up %s @%lx->%lx",
lookup->textname, (long int)lookup, lookup->textname, (long int)lookup,
(long int)lookup->link.next); (long int)lookup->link.next);
@@ -657,6 +659,7 @@ setup_lookup(dig_lookup_t *lookup) {
if (count_dots(lookup->textname) >= ndots) if (count_dots(lookup->textname) >= ndots)
lookup->origin = NULL; /* Force root lookup */ lookup->origin = NULL; /* Force root lookup */
debug ("lookup->origin = %lx", (long int)lookup->origin);
if (lookup->origin != NULL) { if (lookup->origin != NULL) {
debug ("Trying origin %s", lookup->origin->origin); debug ("Trying origin %s", lookup->origin->origin);
result = dns_message_gettempname(lookup->sendmsg, result = dns_message_gettempname(lookup->sendmsg,
@@ -905,9 +908,10 @@ connect_timeout(isc_task_t *task, isc_event_t *event) {
if (q->lookup->retries > 1) if (q->lookup->retries > 1)
printf(";; Connection to server %.*s " printf(";; Connection to server %.*s "
"for %s timed out. " "for %s timed out. "
"Retrying.\n", "Retrying %d.\n",
(int)r.length, r.base, (int)r.length, r.base,
q->lookup->textname); q->lookup->textname,
q->lookup->retries-1);
else else
printf(";; Connection to server %.*s " printf(";; Connection to server %.*s "
"for %s timed out. " "for %s timed out. "
@@ -1149,9 +1153,16 @@ recv_done(isc_task_t *task, isc_event_t *event) {
if (query->lookup->xfr_q == NULL) if (query->lookup->xfr_q == NULL)
query->lookup->xfr_q = query; query->lookup->xfr_q = query;
if (query->lookup->xfr_q == query) { if (query->lookup->xfr_q == query) {
if (query->lookup->ns_search_only) if (query->lookup->ns_search_only) {
followup_lookup(msg, query); if (show_details) {
else if ((msg->rcode != 0) && printmessage(query, msg, ISC_TRUE);
}
if ((msg->rcode != 0) &&
(query->lookup->origin != NULL)) {
next_origin(msg, query);
} else
followup_lookup(msg, query);
} else if ((msg->rcode != 0) &&
(query->lookup->origin != NULL)) { (query->lookup->origin != NULL)) {
next_origin(msg, query); next_origin(msg, query);
if (show_details) { if (show_details) {
@@ -1405,7 +1416,6 @@ free_lists(void) {
o = ISC_LIST_NEXT(o, link); o = ISC_LIST_NEXT(o, link);
isc_mem_free(mctx, ptr); isc_mem_free(mctx, ptr);
} }
dns_name_invalidate(dns_rootname);
if (socketmgr != NULL) if (socketmgr != NULL)
isc_socketmgr_destroy(&socketmgr); isc_socketmgr_destroy(&socketmgr);
if (timermgr != NULL) if (timermgr != NULL)

View File

@@ -61,7 +61,7 @@ extern ISC_LIST(dig_server_t) server_list;
extern ISC_LIST(dig_searchlist_t) search_list; extern ISC_LIST(dig_searchlist_t) search_list;
extern isc_boolean_t tcp_mode, extern isc_boolean_t tcp_mode,
have_ipv6; have_ipv6, show_details;
extern in_port_t port; extern in_port_t port;
extern unsigned int timeout; extern unsigned int timeout;
extern isc_mem_t *mctx; extern isc_mem_t *mctx;
@@ -170,7 +170,7 @@ check_next_lookup (dig_lookup_t *lookup) {
dig_query_t *query; dig_query_t *query;
isc_boolean_t still_working=ISC_FALSE; isc_boolean_t still_working=ISC_FALSE;
debug("In check_next_lookup"); debug("check_next_lookup()");
for (query = ISC_LIST_HEAD(lookup->q); for (query = ISC_LIST_HEAD(lookup->q);
query != NULL; query != NULL;
query = ISC_LIST_NEXT(query, link)) { query = ISC_LIST_NEXT(query, link)) {
@@ -244,10 +244,17 @@ show_usage() {
void void
received(int bytes, int frmsize, char *frm, dig_query_t *query) { received(int bytes, int frmsize, char *frm, dig_query_t *query) {
UNUSED(query); isc_time_t now;
if (!short_form) isc_result_t result;
printf("Received %u bytes from %.*s\n", int diff;
bytes, frmsize, frm);
if ((!short_form) || (show_details)) {
result = isc_time_now(&now);
check_result (result, "isc_time_now");
diff = isc_time_microdiff(&now, &query->time_sent);
printf("Received %u bytes from %.*s in %d ms\n",
bytes, frmsize, frm, diff/1000);
}
} }
void void
@@ -416,12 +423,22 @@ printmessage(dig_query_t *query, dns_message_t *msg, isc_boolean_t headers) {
dns_rdataset_t *opt, *tsig = NULL; dns_rdataset_t *opt, *tsig = NULL;
dns_name_t *tsigname; dns_name_t *tsigname;
isc_result_t result = ISC_R_SUCCESS; isc_result_t result = ISC_R_SUCCESS;
isc_buffer_t *b;
isc_region_t r;
UNUSED (headers); UNUSED (headers);
if (msg->rcode != 0) { if (msg->rcode != 0) {
printf ("Host not found: %d(%s)\n", result = isc_buffer_allocate(mctx, &b, MXNAME);
check_result (result, "isc_buffer_allocate");
result = dns_name_totext(query->lookup->name, ISC_FALSE,
b);
check_result (result, "dns_name_totext");
isc_buffer_usedregion (b, &r);
printf ("Host %.*s not found: %d(%s)\n",
(int)r.length, (char *)r.base,
msg->rcode, rcodetext[msg->rcode]); msg->rcode, rcodetext[msg->rcode]);
isc_buffer_free (&b);
return (ISC_R_SUCCESS); return (ISC_R_SUCCESS);
} }
if (!short_form) { if (!short_form) {
@@ -585,6 +602,7 @@ parse_args(isc_boolean_t is_batchfile, int argc, char **argv) {
strcpy (queryclass, "in"); strcpy (queryclass, "in");
nsfind = ISC_TRUE; nsfind = ISC_TRUE;
showallsoa = ISC_TRUE; showallsoa = ISC_TRUE;
show_details = ISC_TRUE;
break; break;
case 'N': case 'N':
debug ("Setting NDOTS to %s", debug ("Setting NDOTS to %s",
@@ -627,6 +645,7 @@ parse_args(isc_boolean_t is_batchfile, int argc, char **argv) {
lookup->oname=NULL; lookup->oname=NULL;
lookup->timer = NULL; lookup->timer = NULL;
lookup->xfr_q = NULL; lookup->xfr_q = NULL;
lookup->origin = NULL;
lookup->doing_xfr = ISC_FALSE; lookup->doing_xfr = ISC_FALSE;
lookup->identify = ISC_FALSE; lookup->identify = ISC_FALSE;
lookup->recurse = recursion; lookup->recurse = recursion;