mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-08-22 10:10:06 +00:00
simplify dig/host/nslookup code by using the _format() functions in
more places; fix spacing issues; make nslookup print debugging details for all lookup results, not just those with rcode==0; add comments
This commit is contained in:
parent
4115131757
commit
b4876b6ddf
@ -15,7 +15,7 @@
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
/* $Id: dig.c,v 1.134 2001/01/18 05:12:39 gson Exp $ */
|
||||
/* $Id: dig.c,v 1.135 2001/01/24 19:28:29 gson Exp $ */
|
||||
|
||||
#include <config.h>
|
||||
#include <stdlib.h>
|
||||
@ -192,11 +192,14 @@ show_usage(void) {
|
||||
* Callback from dighost.c to print the received message.
|
||||
*/
|
||||
void
|
||||
received(int bytes, int frmsize, char *frm, dig_query_t *query) {
|
||||
received(int bytes, isc_sockaddr_t *from, dig_query_t *query) {
|
||||
isc_uint64_t diff;
|
||||
isc_time_t now;
|
||||
isc_result_t result;
|
||||
time_t tnow;
|
||||
char fromtext[ISC_SOCKADDR_FORMATSIZE];
|
||||
|
||||
isc_sockaddr_format(from, fromtext, sizeof(fromtext));
|
||||
|
||||
result = isc_time_now(&now);
|
||||
check_result(result, "isc_time_now");
|
||||
@ -204,8 +207,7 @@ received(int bytes, int frmsize, char *frm, dig_query_t *query) {
|
||||
if (query->lookup->stats) {
|
||||
diff = isc_time_microdiff(&now, &query->time_sent);
|
||||
printf(";; Query time: %ld msec\n", (long int)diff/1000);
|
||||
printf(";; SERVER: %.*s(%s)\n", frmsize, frm,
|
||||
query->servname);
|
||||
printf(";; SERVER: %s(%s)\n", fromtext, query->servname);
|
||||
time(&tnow);
|
||||
printf(";; WHEN: %s", ctime(&tnow));
|
||||
if (query->lookup->doing_xfr) {
|
||||
@ -226,8 +228,8 @@ received(int bytes, int frmsize, char *frm, dig_query_t *query) {
|
||||
puts("");
|
||||
} else if (query->lookup->identify && !short_form) {
|
||||
diff = isc_time_microdiff(&now, &query->time_sent);
|
||||
printf(";; Received %u bytes from %.*s(%s) in %d ms\n\n",
|
||||
bytes, frmsize, frm, query->servname,
|
||||
printf(";; Received %u bytes from %s(%s) in %d ms\n\n",
|
||||
bytes, fromtext, query->servname,
|
||||
(int)diff/1000);
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,7 @@
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
/* $Id: dighost.c,v 1.187 2001/01/22 22:38:21 gson Exp $ */
|
||||
/* $Id: dighost.c,v 1.188 2001/01/24 19:28:30 gson Exp $ */
|
||||
|
||||
/*
|
||||
* Notice to programmers: Do not use this code as an example of how to
|
||||
@ -2095,8 +2095,6 @@ check_for_more_data(dig_query_t *query, dns_message_t *msg,
|
||||
dns_rdata_soa_t soa;
|
||||
isc_result_t result;
|
||||
isc_buffer_t b;
|
||||
isc_region_t r;
|
||||
char abspace[MXNAME];
|
||||
isc_boolean_t atlimit=ISC_FALSE;
|
||||
|
||||
debug("check_for_more_data()");
|
||||
@ -2240,13 +2238,7 @@ check_for_more_data(dig_query_t *query, dns_message_t *msg,
|
||||
} while (result == ISC_R_SUCCESS);
|
||||
if (atlimit) {
|
||||
doexit:
|
||||
isc_buffer_init(&b, abspace, MXNAME);
|
||||
result = isc_sockaddr_totext(&sevent->address, &b);
|
||||
check_result(result,
|
||||
"isc_sockaddr_totext");
|
||||
isc_buffer_usedregion(&b, &r);
|
||||
received(b.used, r.length,
|
||||
(char *)r.base, query);
|
||||
received(b.used, &sevent->address, query);
|
||||
if (atlimit)
|
||||
if (exitcode < 7)
|
||||
exitcode = 7;
|
||||
@ -2267,9 +2259,6 @@ recv_done(isc_task_t *task, isc_event_t *event) {
|
||||
isc_buffer_t *b = NULL;
|
||||
dns_message_t *msg = NULL;
|
||||
isc_result_t result;
|
||||
isc_buffer_t ab;
|
||||
char abspace[MXNAME];
|
||||
isc_region_t r;
|
||||
dig_lookup_t *n, *l;
|
||||
isc_boolean_t docancel = ISC_FALSE;
|
||||
unsigned int local_timeout;
|
||||
@ -2465,16 +2454,8 @@ recv_done(isc_task_t *task, isc_event_t *event) {
|
||||
if (!next_origin(msg, query)) {
|
||||
printmessage(query, msg,
|
||||
ISC_TRUE);
|
||||
isc_buffer_init(&ab, abspace,
|
||||
MXNAME);
|
||||
result = isc_sockaddr_totext(
|
||||
&sevent->address,
|
||||
&ab);
|
||||
check_result(result,
|
||||
"isc_sockaddr_totext");
|
||||
isc_buffer_usedregion(&ab, &r);
|
||||
received(b->used, r.length,
|
||||
(char *)r.base,
|
||||
received(b->used,
|
||||
&sevent->address,
|
||||
query);
|
||||
}
|
||||
} else {
|
||||
@ -2490,15 +2471,8 @@ recv_done(isc_task_t *task, isc_event_t *event) {
|
||||
if (!next_origin(msg, query)) {
|
||||
printmessage(query, msg,
|
||||
ISC_TRUE);
|
||||
isc_buffer_init(&ab, abspace, MXNAME);
|
||||
result = isc_sockaddr_totext(
|
||||
&sevent->address,
|
||||
&ab);
|
||||
check_result(result,
|
||||
"isc_sockaddr_totext");
|
||||
isc_buffer_usedregion(&ab, &r);
|
||||
received(b->used, r.length,
|
||||
(char *)r.base,
|
||||
received(b->used,
|
||||
&sevent->address,
|
||||
query);
|
||||
}
|
||||
} else {
|
||||
@ -2535,13 +2509,8 @@ recv_done(isc_task_t *task, isc_event_t *event) {
|
||||
else {
|
||||
if ((msg->rcode == 0) ||
|
||||
(l->origin == NULL)) {
|
||||
isc_buffer_init(&ab, abspace, MXNAME);
|
||||
result = isc_sockaddr_totext(&sevent->address,
|
||||
&ab);
|
||||
check_result(result, "isc_sockaddr_totext");
|
||||
isc_buffer_usedregion(&ab, &r);
|
||||
received(b->used, r.length,
|
||||
(char *)r.base,
|
||||
received(b->used,
|
||||
&sevent->address,
|
||||
query);
|
||||
}
|
||||
query->lookup->pending = ISC_FALSE;
|
||||
|
@ -15,7 +15,7 @@
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
/* $Id: host.c,v 1.62 2001/01/18 05:12:42 gson Exp $ */
|
||||
/* $Id: host.c,v 1.63 2001/01/24 19:28:32 gson Exp $ */
|
||||
|
||||
#include <config.h>
|
||||
#include <stdlib.h>
|
||||
@ -229,17 +229,20 @@ dighost_shutdown(void) {
|
||||
}
|
||||
|
||||
void
|
||||
received(int bytes, int frmsize, char *frm, dig_query_t *query) {
|
||||
received(int bytes, isc_sockaddr_t *from, dig_query_t *query)
|
||||
{
|
||||
isc_time_t now;
|
||||
isc_result_t result;
|
||||
int diff;
|
||||
|
||||
if (!short_form) {
|
||||
char fromtext[ISC_SOCKADDR_FORMATSIZE];
|
||||
isc_sockaddr_format(from, fromtext, sizeof(fromtext));
|
||||
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);
|
||||
printf("Received %u bytes from %s in %d ms\n",
|
||||
bytes, fromtext, diff/1000);
|
||||
}
|
||||
}
|
||||
|
||||
@ -248,7 +251,7 @@ trying(int frmsize, char *frm, dig_lookup_t *lookup) {
|
||||
UNUSED(lookup);
|
||||
|
||||
if (!short_form)
|
||||
printf ("Trying \"%.*s\"\n", frmsize, frm);
|
||||
printf("Trying \"%.*s\"\n", frmsize, frm);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -269,12 +272,12 @@ say_message(dns_name_t *name, const char *msg, dns_rdata_t *rdata,
|
||||
result = dns_rdata_totext(rdata, NULL, b2);
|
||||
check_result(result, "dns_rdata_totext");
|
||||
isc_buffer_usedregion(b2, &r2);
|
||||
printf ( "%.*s %s %.*s", (int)r.length, (char *)r.base,
|
||||
msg, (int)r2.length, (char *)r2.base);
|
||||
printf("%.*s %s %.*s", (int)r.length, (char *)r.base,
|
||||
msg, (int)r2.length, (char *)r2.base);
|
||||
if (query->lookup->identify) {
|
||||
printf (" on server %s", query->servname);
|
||||
printf(" on server %s", query->servname);
|
||||
}
|
||||
printf ("\n");
|
||||
printf("\n");
|
||||
isc_buffer_free(&b);
|
||||
isc_buffer_free(&b2);
|
||||
}
|
||||
@ -345,7 +348,7 @@ printsection(dns_message_t *msg, dns_section_t sectionid,
|
||||
while (loopresult == ISC_R_SUCCESS) {
|
||||
dns_rdataset_current(rdataset, &rdata);
|
||||
if (rdata.type <= 103)
|
||||
rtt=rtypetext[rdata.type];
|
||||
rtt = rtypetext[rdata.type];
|
||||
else if (rdata.type == 249)
|
||||
rtt = "key";
|
||||
else if (rdata.type == 250)
|
||||
@ -575,8 +578,8 @@ parse_args(isc_boolean_t is_batchfile, int argc, char **argv) {
|
||||
(isc_textregion_t *)&tr);
|
||||
|
||||
if (result != ISC_R_SUCCESS)
|
||||
fprintf (stderr,"Warning: invalid type: %s\n",
|
||||
isc_commandline_argument);
|
||||
fprintf(stderr,"Warning: invalid type: %s\n",
|
||||
isc_commandline_argument);
|
||||
else {
|
||||
lookup->rdtype = rdtype;
|
||||
lookup->rdtypeset = ISC_TRUE;
|
||||
@ -589,8 +592,8 @@ parse_args(isc_boolean_t is_batchfile, int argc, char **argv) {
|
||||
(isc_textregion_t *)&tr);
|
||||
|
||||
if (result != ISC_R_SUCCESS)
|
||||
fprintf (stderr,"Warning: invalid class: %s\n",
|
||||
isc_commandline_argument);
|
||||
fprintf(stderr,"Warning: invalid class: %s\n",
|
||||
isc_commandline_argument);
|
||||
else {
|
||||
lookup->rdclass = rdclass;
|
||||
lookup->rdclassset = ISC_TRUE;
|
||||
|
@ -15,7 +15,7 @@
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
/* $Id: dig.h,v 1.62 2001/01/18 05:12:44 gson Exp $ */
|
||||
/* $Id: dig.h,v 1.63 2001/01/24 19:28:34 gson Exp $ */
|
||||
|
||||
#ifndef DIG_H
|
||||
#define DIG_H
|
||||
@ -243,13 +243,22 @@ void
|
||||
set_search_domain(char *domain);
|
||||
|
||||
/*
|
||||
* Routines needed in dig.c and host.c.
|
||||
* Routines to be defined in dig.c, host.c, and nslookup.c.
|
||||
*/
|
||||
|
||||
isc_result_t
|
||||
printmessage(dig_query_t *query, dns_message_t *msg, isc_boolean_t headers);
|
||||
/*
|
||||
* Print the final result of the lookup.
|
||||
*/
|
||||
|
||||
void
|
||||
received(int bytes, int frmsize, char *frm, dig_query_t *query);
|
||||
received(int bytes, isc_sockaddr_t *from, dig_query_t *query);
|
||||
/*
|
||||
* Print a message about where and when the response
|
||||
* was received from, like the final comment in the
|
||||
* output of "dig".
|
||||
*/
|
||||
|
||||
void
|
||||
trying(int frmsize, char *frm, dig_lookup_t *lookup);
|
||||
|
@ -15,7 +15,7 @@
|
||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
/* $Id: nslookup.c,v 1.79 2001/01/22 23:22:09 gson Exp $ */
|
||||
/* $Id: nslookup.c,v 1.80 2001/01/24 19:28:33 gson Exp $ */
|
||||
|
||||
#include <config.h>
|
||||
|
||||
@ -169,22 +169,6 @@ dighost_shutdown(void) {
|
||||
isc_task_send(global_task, &event);
|
||||
}
|
||||
|
||||
void
|
||||
received(int bytes, int frmsize, char *frm, dig_query_t *query) {
|
||||
UNUSED(bytes);
|
||||
UNUSED(frmsize);
|
||||
UNUSED(frm);
|
||||
UNUSED(query);
|
||||
}
|
||||
|
||||
void
|
||||
trying(int frmsize, char *frm, dig_lookup_t *lookup) {
|
||||
UNUSED(frmsize);
|
||||
UNUSED(frm);
|
||||
UNUSED(lookup);
|
||||
|
||||
}
|
||||
|
||||
static void
|
||||
printsoa(dns_rdata_t *rdata) {
|
||||
dns_rdata_soa_t soa;
|
||||
@ -398,39 +382,36 @@ detailsection(dig_query_t *query, dns_message_t *msg, isc_boolean_t headers,
|
||||
return (ISC_R_SUCCESS);
|
||||
}
|
||||
|
||||
void
|
||||
received(int bytes, isc_sockaddr_t *from, dig_query_t *query)
|
||||
{
|
||||
UNUSED(bytes);
|
||||
UNUSED(from);
|
||||
UNUSED(query);
|
||||
}
|
||||
|
||||
void
|
||||
trying(int frmsize, char *frm, dig_lookup_t *lookup) {
|
||||
UNUSED(frmsize);
|
||||
UNUSED(frm);
|
||||
UNUSED(lookup);
|
||||
|
||||
}
|
||||
|
||||
isc_result_t
|
||||
printmessage(dig_query_t *query, dns_message_t *msg, isc_boolean_t headers) {
|
||||
isc_buffer_t *b = NULL;
|
||||
isc_region_t r;
|
||||
isc_result_t result;
|
||||
char servtext[ISC_SOCKADDR_FORMATSIZE];
|
||||
|
||||
debug("printmessage()");
|
||||
debug("continuing on with rcode != 0");
|
||||
result = isc_buffer_allocate(mctx, &b, MXNAME);
|
||||
check_result(result, "isc_buffer_allocate");
|
||||
|
||||
isc_sockaddr_format(&query->sockaddr, servtext, sizeof(servtext));
|
||||
printf("Server:\t\t%s\n", query->servname);
|
||||
result = isc_sockaddr_totext(&query->sockaddr, b);
|
||||
check_result(result, "isc_sockaddr_totext");
|
||||
printf("Address:\t%.*s\n", (int)isc_buffer_usedlength(b),
|
||||
(char*)isc_buffer_base(b));
|
||||
isc_buffer_free(&b);
|
||||
printf("Address:\t%s\n", servtext);
|
||||
|
||||
puts("");
|
||||
|
||||
if (msg->rcode != 0) {
|
||||
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("** server can't find %.*s: %s\n",
|
||||
(int)r.length, (char*)r.base,
|
||||
rcodetext[msg->rcode]);
|
||||
isc_buffer_free(&b);
|
||||
debug("returning with rcode == 0");
|
||||
return (ISC_R_SUCCESS);
|
||||
}
|
||||
if (!short_form) {
|
||||
isc_boolean_t headers = ISC_TRUE;
|
||||
puts("------------");
|
||||
/* detailheader(query, msg);*/
|
||||
detailsection(query, msg, headers, DNS_SECTION_QUESTION);
|
||||
@ -440,6 +421,16 @@ printmessage(dig_query_t *query, dns_message_t *msg, isc_boolean_t headers) {
|
||||
puts("------------");
|
||||
}
|
||||
|
||||
if (msg->rcode != 0) {
|
||||
char nametext[DNS_NAME_FORMATSIZE];
|
||||
dns_name_format(query->lookup->name,
|
||||
nametext, sizeof(nametext));
|
||||
printf("** server can't find %s: %s\n", nametext,
|
||||
rcodetext[msg->rcode]);
|
||||
debug("returning with rcode == 0");
|
||||
return (ISC_R_SUCCESS);
|
||||
}
|
||||
|
||||
if ((msg->flags & DNS_MESSAGEFLAG_AA) == 0)
|
||||
puts("Non-authoritative answer:");
|
||||
if (!ISC_LIST_EMPTY(msg->sections[DNS_SECTION_ANSWER]))
|
||||
|
Loading…
x
Reference in New Issue
Block a user