diff --git a/bin/dig/dig.c b/bin/dig/dig.c index b8587c1837..40020b0c1a 100644 --- a/bin/dig/dig.c +++ b/bin/dig/dig.c @@ -126,14 +126,14 @@ check_next_lookup(dig_lookup_t *lookup) { isc_boolean_t still_working=ISC_FALSE; #ifdef DEBUG - fputs("In check_next_lookup",stderr); + fputs("In check_next_lookup\n",stderr); #endif for (query = ISC_LIST_HEAD(lookup->q); query != NULL; query = ISC_LIST_NEXT(query, link)) { if (query->working) { #ifdef DEBUG - fputs("Still have a worker.",stderr); + fputs("Still have a worker.\n",stderr); #endif still_working=ISC_TRUE; } @@ -144,7 +144,7 @@ check_next_lookup(dig_lookup_t *lookup) { next = ISC_LIST_NEXT(lookup, link); if (next == NULL) { #ifdef DEBUG - fputs("Shutting Down.",stderr); + fputs("Shutting Down.\n",stderr); #endif isc_app_shutdown(); return; diff --git a/bin/dig/dighost.c b/bin/dig/dighost.c index 58cfebd966..41541ab8f9 100644 --- a/bin/dig/dighost.c +++ b/bin/dig/dighost.c @@ -15,8 +15,6 @@ * SOFTWARE. */ -#define MEMDEBUG - #include #include @@ -238,7 +236,6 @@ setup_libs(void) { result = isc_socketmgr_create (mctx, &socketmgr); check_result(result, "isc_socketmgr_create"); - isc_buffer_init(&b, ".", 1); isc_buffer_add(&b, 1); dns_name_init(&rootorg, NULL); @@ -377,7 +374,7 @@ cancel_lookup(dig_lookup_t *lookup) { dig_query_t *query; #ifdef DEBUG - fputs("Cancelling all queries", stderr); + fputs("Cancelling all queries\n", stderr); #endif if (!lookup->pending) return; @@ -405,6 +402,9 @@ connect_timeout(isc_task_t *task, isc_event_t *event) { REQUIRE(event->ev_type == ISC_TIMEREVENT_IDLE); +#ifdef DEBUG + fputs ("Buffer Allocate connect_timeout\n",stderr); +#endif result = isc_buffer_allocate(mctx, &b, 256); check_result(result, "isc_buffer_allocate"); for (q = ISC_LIST_HEAD(lookup->q); @@ -442,7 +442,7 @@ tcp_length_done(isc_task_t *task, isc_event_t *event) { UNUSED(task); #ifdef DEBUG - fputs("In tcp_length_done", stderr); + fputs("In tcp_length_done\n", stderr); #endif REQUIRE(event->ev_type == ISC_SOCKEVENT_RECVDONE); sevent = (isc_socketevent_t *)event; @@ -457,6 +457,9 @@ tcp_length_done(isc_task_t *task, isc_event_t *event) { return; } if (sevent->result != ISC_R_SUCCESS) { +#ifdef DEBUG + fputs ("Buffer Allocate connect_timeout\n",stderr); +#endif result = isc_buffer_allocate(mctx, &b, 256); check_result(result, "isc_buffer_allocate"); result = isc_sockaddr_totext(&query->sockaddr, b); @@ -500,7 +503,8 @@ launch_next_query(dig_query_t *query, isc_boolean_t include_question) { if (!query->lookup->pending) { #ifdef DEBUG - fputs("Ignoring launch_next_query because !pending.", stderr); + fputs("Ignoring launch_next_query because !pending.\n", + stderr); #endif isc_socket_detach(&query->sock); query->working = ISC_FALSE; @@ -523,7 +527,7 @@ launch_next_query(dig_query_t *query, isc_boolean_t include_question) { check_result(result, "isc_socket_recvv"); sendcount++; #ifdef DEBUG - fputs("Sending a request.", stderr); + fputs("Sending a request.\n", stderr); #endif result = isc_socket_sendv(query->sock, &query->sendlist, task, send_done, query); @@ -552,9 +556,12 @@ connect_done(isc_task_t *task, isc_event_t *event) { query->waiting_connect = ISC_FALSE; #ifdef DEBUG - fputs("In connect_done.", stderr); + fputs("In connect_done.\n", stderr); #endif if (sevent->result != ISC_R_SUCCESS) { +#ifdef DEBUG + fputs ("Buffer Allocate connect_timeout\n",stderr); +#endif result = isc_buffer_allocate(mctx, &b, 256); check_result(result, "isc_buffer_allocate"); result = isc_sockaddr_totext(&query->sockaddr, b); @@ -584,7 +591,7 @@ msg_contains_soa(dns_message_t *msg, dig_query_t *query) { 0, &name, NULL); if (result == ISC_R_SUCCESS) { #ifdef DEBUG - fputs("Found SOA", stderr); + fputs("Found SOA\n", stderr); #endif return (ISC_TRUE); } else { @@ -625,7 +632,13 @@ recv_done(isc_task_t *task, isc_event_t *event) { #endif query->working = ISC_FALSE; query->waiting_connect = ISC_FALSE; +#ifdef DEBUG + fputs ("Starting the cancel\n",stderr); +#endif cancel_lookup(query->lookup); +#ifdef DEBUG + fputs ("Starting the check\n",stderr); +#endif check_next_lookup(query->lookup); isc_event_free(&event); return; @@ -652,7 +665,7 @@ recv_done(isc_task_t *task, isc_event_t *event) { } #ifdef DEBUG if (query->lookup->pending) - fputs("Still pending.", stderr); + fputs("Still pending.\n", stderr); #endif if (query->lookup->doing_xfr) { if (!query->first_soa_rcvd) { @@ -660,8 +673,10 @@ recv_done(isc_task_t *task, isc_event_t *event) { puts("; Transfer failed. " "Didn't start with SOA answer."); query->working = ISC_FALSE; - check_next_lookup(query->lookup); - isc_event_free(&event); + cancel_lookup(query->lookup); + check_next_lookup (query->lookup); + isc_event_free (&event); + dns_message_destroy (&msg); return; } else { @@ -675,6 +690,7 @@ recv_done(isc_task_t *task, isc_event_t *event) { query->working = ISC_FALSE; check_next_lookup(query->lookup); isc_event_free(&event); + dns_message_destroy (&msg); return; } else { @@ -742,7 +758,7 @@ do_lookup_tcp(dig_lookup_t *lookup) { isc_result_t result; #ifdef DEBUG - fputs("Starting a TCP lookup", stderr); + fputs("Starting a TCP lookup\n", stderr); #endif lookup->pending = ISC_TRUE; isc_interval_set(&lookup->interval, timeout, 0); @@ -774,7 +790,7 @@ do_lookup_udp(dig_lookup_t *lookup) { isc_result_t result; #ifdef DEBUG - fputs("Starting a UDP lookup.", stderr); + fputs("Starting a UDP lookup.\n", stderr); #endif lookup->pending = ISC_TRUE; isc_interval_set(&lookup->interval, timeout, 0); @@ -836,9 +852,9 @@ free_lists(void) { isc_mem_free(mctx, ptr); } if (l->sendmsg != NULL) - dns_message_destroy(&l->sendmsg); + dns_message_destroy (&l->sendmsg); if (l->timer != NULL) - isc_timer_detach(&l->timer); + isc_timer_detach (&l->timer); ptr = l; l = ISC_LIST_NEXT(l, link); isc_mem_free(mctx, ptr); diff --git a/bin/dig/host.c b/bin/dig/host.c index 2f7da44481..61889ec95d 100644 --- a/bin/dig/host.c +++ b/bin/dig/host.c @@ -77,7 +77,8 @@ extern isc_buffer_t rootbuf; extern int sendcount; isc_boolean_t short_form=ISC_TRUE, - filter=ISC_FALSE; + filter=ISC_FALSE, + showallsoa=ISC_FALSE; static char *opcodetext[] = { "QUERY", @@ -118,6 +119,50 @@ static char *rcodetext[] = { "BADVERS" }; +static char *rtypetext[] = { + "zero", /* 0 */ + "has address", /* 1 */ + "name server", /* 2 */ + "MD", /* 3 */ + "MF", /* 4 */ + "is an alias for", /* 5 */ + "start of authority", /* 6 */ + "MB", /* 7 */ + "MG", /* 8 */ + "MR", /* 9 */ + "NULL", /* 10 */ + "has well known services", /* 11 */ + "domain name pointer", /* 12 */ + "host information", /* 13 */ + "MINFO", /* 14 */ + "mail is handled by", /* 15 */ + "text", /* 16 */ + "RP", /* 17 */ + "AFSDB", /* 18 */ + "x25 address", /* 19 */ + "isdn address", /* 20 */ + "RT" /* 21 */ + "NSAP", /* 22 */ + "NSAP_PTR", /* 23 */ + "has signature", /* 24 */ + "has key", /* 25 */ + "PX", /* 26 */ + "GPOS", /* 27 */ + "has AAAA address", /* 28 */ + "LOC", /* 29 */ + "has next record", /* 30 */ + "has 31 record", /* 31 */ + "has 32 record", /* 32 */ + "SRV", /* 33 */ + "has 34 record", /* 34 */ + "NAPTR", /* 35 */ + "KX", /* 36 */ + "CERT", /* 37 */ + "has v6 address", /* 38 */ + "DNAME", /* 39 */ + "has 40 record", /* 40 */ + "has optional information"}; /* 41 */ + void check_next_lookup (dig_lookup_t *lookup) { dig_lookup_t *next; @@ -165,17 +210,25 @@ show_usage() { } static void -say_message(char *host, char *msg, dns_rdata_t *rdata, isc_buffer_t *target) { - isc_region_t r; +say_message(dns_name_t *name, char *msg, dns_rdata_t *rdata) { + isc_buffer_t *b, *b2; + isc_region_t r, r2; isc_result_t result; - result = dns_rdata_totext( rdata, NULL, target); + isc_buffer_allocate(mctx, &b, BUFSIZE); + isc_buffer_allocate(mctx, &b2, BUFSIZE); + result = dns_name_totext(name, ISC_TRUE, b); + check_result(result, "dns_name_totext"); + isc_buffer_usedregion(b, &r); + result = dns_rdata_totext(rdata, NULL, b2); check_result(result, "dns_rdata_totext"); - isc_buffer_usedregion(target, &r); - printf ( "%s %s %.*s\n", host, msg, (int)r.length, - (char *)r.base); -} - + isc_buffer_usedregion(b2, &r2); + printf ( "%.*s %s %.*s\n", (int)r.length, (char *)r.base, + msg, (int)r2.length, (char *)r2.base); + isc_buffer_free(&b); + isc_buffer_free(&b2); +} + static isc_result_t printsection(dns_message_t *msg, dns_section_t sectionid, char *section_name, @@ -191,6 +244,7 @@ printsection(dns_message_t *msg, dns_section_t sectionid, char *section_name, char t[4096]; isc_boolean_t first; isc_boolean_t no_rdata; + char *rtt; if (sectionid == DNS_SECTION_QUESTION) no_rdata = ISC_TRUE; @@ -237,24 +291,19 @@ printsection(dns_message_t *msg, dns_section_t sectionid, char *section_name, loopresult = dns_rdataset_first(rdataset); while (loopresult == ISC_R_SUCCESS) { dns_rdataset_current(rdataset, &rdata); - if (rdata.type == dns_rdatatype_a) { - say_message ("Something", - "has address", - &rdata, - &target); - } else if - (rdata.type == dns_rdatatype_mx) { - say_message ("Something", - "mail server", - &rdata, - &target); - } else if - (rdata.type == dns_rdatatype_ns) { - say_message ("Something", - "name server", - &rdata, - &target); - } + if (rdata.type <= 41) + rtt=rtypetext[rdata.type]; + else if (rdata.type == 103) + rtt="unspecified data"; + else if (rdata.type == 249) + rtt="key"; + else if (rdata.type == 250) + rtt="signature"; + else + rtt="unknown"; + say_message(print_name, + rtypetext[rdata.type], + &rdata); loopresult = dns_rdataset_next( rdataset); } @@ -311,6 +360,11 @@ printmessage(dns_message_t *msg, isc_boolean_t headers) { dns_name_t *tsigname; isc_result_t result = ISC_R_SUCCESS; + if (msg->rcode != 0) { + printf ("Host not found: %d(%s)\n", + msg->rcode, rcodetext[msg->rcode]); + return (ISC_R_SUCCESS); + } if (!short_form) { printf(";; ->>HEADER<<- opcode: %s, status: %s, id: %u\n", opcodetext[msg->opcode], rcodetext[msg->rcode], @@ -413,11 +467,12 @@ parse_args(isc_boolean_t is_batchfile, int argc, char **argv) { char hostname[MXNAME]; char servname[MXNAME]; char querytype[32]="a"; + char queryclass[32]="in"; dig_server_t *srv; dig_lookup_t *lookup; int c; - while ((c = isc_commandline_parse(argc, argv,"lvwrdt:a")) != EOF) { + while ((c = isc_commandline_parse(argc, argv,"lvwrdt:aC")) != EOF) { switch (c) { case 'l': tcp_mode = ISC_TRUE; @@ -435,6 +490,9 @@ parse_args(isc_boolean_t is_batchfile, int argc, char **argv) { case 't': strncpy (querytype, isc_commandline_argument, 32); break; + case 'c': + strncpy (queryclass, isc_commandline_argument, 32); + break; case 'a': strcpy (querytype, "any"); short_form = ISC_FALSE; @@ -444,6 +502,9 @@ parse_args(isc_boolean_t is_batchfile, int argc, char **argv) { thing! */ timeout = 32767; break; + case 'C': + showallsoa = ISC_TRUE; + break; } } if (isc_commandline_index >= argc) { @@ -469,7 +530,7 @@ parse_args(isc_boolean_t is_batchfile, int argc, char **argv) { lookup->pending = ISC_FALSE; strncpy (lookup->textname, hostname, MXNAME); strncpy (lookup->rttext, querytype, 32); - strcpy (lookup->rctext,"in"); + strncpy (lookup->rctext,queryclass, 32); lookup->namespace[0]=0; lookup->sendspace[0]=0; lookup->sendmsg=NULL;