mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-08-29 13:38:26 +00:00
consolidate duplicated code.
This commit is contained in:
parent
fb0663dbdd
commit
e56101fa68
@ -15,7 +15,7 @@
|
|||||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* $Id: nslookup.c,v 1.76 2001/01/17 00:48:19 bwelling Exp $ */
|
/* $Id: nslookup.c,v 1.77 2001/01/17 02:21:51 bwelling Exp $ */
|
||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
|
||||||
@ -184,16 +184,76 @@ trying(int frmsize, char *frm, dig_lookup_t *lookup) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
printsoa(dns_rdata_t *rdata) {
|
||||||
|
dns_rdata_soa_t soa;
|
||||||
|
isc_result_t result;
|
||||||
|
char namebuf[DNS_NAME_FORMATSIZE];
|
||||||
|
|
||||||
|
result = dns_rdata_tostruct(rdata, &soa, NULL);
|
||||||
|
check_result(result, "dns_rdata_tostruct");
|
||||||
|
|
||||||
|
dns_name_format(&soa.origin, namebuf, sizeof(namebuf));
|
||||||
|
printf("\torigin = %s\n", namebuf);
|
||||||
|
dns_name_format(&soa.mname, namebuf, sizeof(namebuf));
|
||||||
|
printf("\tmail addr = %s\n", namebuf);
|
||||||
|
printf("\tserial = %u\n", soa.serial);
|
||||||
|
printf("\trefresh = %u\n", soa.refresh);
|
||||||
|
printf("\tretry = %u\n", soa.retry);
|
||||||
|
printf("\texpire = %u\n", soa.expire);
|
||||||
|
printf("\tminimum = %u\n", soa.minimum);
|
||||||
|
dns_rdata_freestruct(&soa);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
printa(dns_rdata_t *rdata) {
|
||||||
|
isc_result_t result;
|
||||||
|
char text[sizeof("255.255.255.255")];
|
||||||
|
isc_buffer_t b;
|
||||||
|
|
||||||
|
isc_buffer_init(&b, text, sizeof(text));
|
||||||
|
result = dns_rdata_totext(rdata, NULL, &b);
|
||||||
|
check_result(result, "dns_rdata_totext");
|
||||||
|
printf("Address: %.*s\n", (int)isc_buffer_usedlength(&b),
|
||||||
|
(char *)isc_buffer_base(&b));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
printrdata(dns_rdata_t *rdata) {
|
||||||
|
isc_result_t result;
|
||||||
|
isc_buffer_t *b = NULL;
|
||||||
|
unsigned int size = 1024;
|
||||||
|
isc_boolean_t done = ISC_FALSE;
|
||||||
|
|
||||||
|
if (rdata->type < N_KNOWN_RRTYPES)
|
||||||
|
printf("%s", rtypetext[rdata->type]);
|
||||||
|
else
|
||||||
|
printf("rdata_%d = ", rdata->type);
|
||||||
|
|
||||||
|
while (!done) {
|
||||||
|
result = isc_buffer_allocate(mctx, &b, size);
|
||||||
|
if (result != ISC_R_SUCCESS)
|
||||||
|
check_result(result, "isc_buffer_allocate");
|
||||||
|
result = dns_rdata_totext(rdata, NULL, b);
|
||||||
|
if (result == ISC_R_SUCCESS) {
|
||||||
|
printf("%.*s\n", (int)isc_buffer_usedlength(b),
|
||||||
|
(char *)isc_buffer_base(b));
|
||||||
|
done = ISC_TRUE;
|
||||||
|
} else if (result != ISC_R_NOSPACE)
|
||||||
|
check_result(result, "dns_rdata_totext");
|
||||||
|
isc_buffer_free(&b);
|
||||||
|
size *= 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static isc_result_t
|
static isc_result_t
|
||||||
printsection(dig_query_t *query, dns_message_t *msg, isc_boolean_t headers,
|
printsection(dig_query_t *query, dns_message_t *msg, isc_boolean_t headers,
|
||||||
dns_section_t section) {
|
dns_section_t section) {
|
||||||
isc_result_t result, loopresult;
|
isc_result_t result, loopresult;
|
||||||
isc_buffer_t *b = NULL;
|
|
||||||
dns_name_t *name;
|
dns_name_t *name;
|
||||||
dns_rdataset_t *rdataset = NULL;
|
dns_rdataset_t *rdataset = NULL;
|
||||||
dns_rdata_t rdata = DNS_RDATA_INIT;
|
dns_rdata_t rdata = DNS_RDATA_INIT;
|
||||||
char namebuf[DNS_NAME_FORMATSIZE];
|
char namebuf[DNS_NAME_FORMATSIZE];
|
||||||
dns_rdata_soa_t soa;
|
|
||||||
|
|
||||||
UNUSED(query);
|
UNUSED(query);
|
||||||
UNUSED(headers);
|
UNUSED(headers);
|
||||||
@ -205,8 +265,6 @@ printsection(dig_query_t *query, dns_message_t *msg, isc_boolean_t headers,
|
|||||||
return (ISC_R_SUCCESS);
|
return (ISC_R_SUCCESS);
|
||||||
else if (result != ISC_R_SUCCESS)
|
else if (result != ISC_R_SUCCESS)
|
||||||
return (result);
|
return (result);
|
||||||
result = isc_buffer_allocate(mctx, &b, MXNAME);
|
|
||||||
check_result(result, "isc_buffer_allocate");
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
name = NULL;
|
name = NULL;
|
||||||
dns_message_currentname(msg, section,
|
dns_message_currentname(msg, section,
|
||||||
@ -223,60 +281,22 @@ printsection(dig_query_t *query, dns_message_t *msg, isc_boolean_t headers,
|
|||||||
goto def_short_section;
|
goto def_short_section;
|
||||||
dns_name_format(name, namebuf,
|
dns_name_format(name, namebuf,
|
||||||
sizeof(namebuf));
|
sizeof(namebuf));
|
||||||
|
printf("Name:\t%s\n", namebuf);
|
||||||
isc_buffer_clear(b);
|
printa(&rdata);
|
||||||
result = dns_rdata_totext(&rdata,
|
|
||||||
NULL,
|
|
||||||
b);
|
|
||||||
check_result(result,
|
|
||||||
"dns_rdata_totext");
|
|
||||||
printf("Address: %.*s\n",
|
|
||||||
(int)isc_buffer_usedlength(b),
|
|
||||||
(char*)isc_buffer_base(b));
|
|
||||||
break;
|
break;
|
||||||
case dns_rdatatype_soa:
|
case dns_rdatatype_soa:
|
||||||
dns_name_format(name, namebuf,
|
dns_name_format(name, namebuf,
|
||||||
sizeof(namebuf));
|
sizeof(namebuf));
|
||||||
printf("%s\n", namebuf);
|
printf("%s\n", namebuf);
|
||||||
|
printsoa(&rdata);
|
||||||
result = dns_rdata_tostruct(&rdata,
|
|
||||||
&soa, NULL);
|
|
||||||
check_result(result,
|
|
||||||
"dns_rdata_tostruct");
|
|
||||||
|
|
||||||
dns_name_format(&soa.origin, namebuf,
|
|
||||||
sizeof(namebuf));
|
|
||||||
printf("\torigin = %s\n", namebuf);
|
|
||||||
|
|
||||||
dns_name_format(&soa.mname, namebuf,
|
|
||||||
sizeof(namebuf));
|
|
||||||
printf("\tmail addr = %s\n", namebuf);
|
|
||||||
|
|
||||||
printf("\tserial = %u\n", soa.serial);
|
|
||||||
printf("\trefresh = %u\n", soa.refresh);
|
|
||||||
printf("\tretry = %u\n", soa.retry);
|
|
||||||
printf("\texpire = %u\n", soa.expire);
|
|
||||||
printf("\tminimum = %u\n", soa.minimum);
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
def_short_section:
|
def_short_section:
|
||||||
dns_name_format(name, namebuf,
|
dns_name_format(name, namebuf,
|
||||||
sizeof(namebuf));
|
sizeof(namebuf));
|
||||||
if (rdata.type < N_KNOWN_RRTYPES)
|
printf("%s\t", namebuf);
|
||||||
printf("%s\t%s", namebuf,
|
printrdata(&rdata);
|
||||||
rtypetext[rdata.type]);
|
break;
|
||||||
else
|
|
||||||
printf("%s\trdata_%d = ",
|
|
||||||
namebuf,
|
|
||||||
rdata.type);
|
|
||||||
isc_buffer_clear(b);
|
|
||||||
result = dns_rdata_totext(&rdata,
|
|
||||||
NULL, b);
|
|
||||||
check_result(result,
|
|
||||||
"dns_rdata_totext");
|
|
||||||
printf("%.*s\n",
|
|
||||||
(int)isc_buffer_usedlength(b),
|
|
||||||
(char*)isc_buffer_base(b));
|
|
||||||
}
|
}
|
||||||
dns_rdata_reset(&rdata);
|
dns_rdata_reset(&rdata);
|
||||||
loopresult = dns_rdataset_next(rdataset);
|
loopresult = dns_rdataset_next(rdataset);
|
||||||
@ -286,11 +306,9 @@ printsection(dig_query_t *query, dns_message_t *msg, isc_boolean_t headers,
|
|||||||
if (result == ISC_R_NOMORE)
|
if (result == ISC_R_NOMORE)
|
||||||
break;
|
break;
|
||||||
else if (result != ISC_R_SUCCESS) {
|
else if (result != ISC_R_SUCCESS) {
|
||||||
isc_buffer_free (&b);
|
|
||||||
return (result);
|
return (result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
isc_buffer_free(&b);
|
|
||||||
return (ISC_R_SUCCESS);
|
return (ISC_R_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -298,12 +316,10 @@ static isc_result_t
|
|||||||
detailsection(dig_query_t *query, dns_message_t *msg, isc_boolean_t headers,
|
detailsection(dig_query_t *query, dns_message_t *msg, isc_boolean_t headers,
|
||||||
dns_section_t section) {
|
dns_section_t section) {
|
||||||
isc_result_t result, loopresult;
|
isc_result_t result, loopresult;
|
||||||
isc_buffer_t *b = NULL;
|
|
||||||
dns_name_t *name;
|
dns_name_t *name;
|
||||||
dns_rdataset_t *rdataset = NULL;
|
dns_rdataset_t *rdataset = NULL;
|
||||||
dns_rdata_t rdata = DNS_RDATA_INIT;
|
dns_rdata_t rdata = DNS_RDATA_INIT;
|
||||||
char namebuf[DNS_NAME_FORMATSIZE];
|
char namebuf[DNS_NAME_FORMATSIZE];
|
||||||
dns_rdata_soa_t soa;
|
|
||||||
|
|
||||||
UNUSED(query);
|
UNUSED(query);
|
||||||
|
|
||||||
@ -331,8 +347,6 @@ detailsection(dig_query_t *query, dns_message_t *msg, isc_boolean_t headers,
|
|||||||
return (ISC_R_SUCCESS);
|
return (ISC_R_SUCCESS);
|
||||||
else if (result != ISC_R_SUCCESS)
|
else if (result != ISC_R_SUCCESS)
|
||||||
return (result);
|
return (result);
|
||||||
result = isc_buffer_allocate(mctx, &b, MXNAME);
|
|
||||||
check_result(result, "isc_buffer_allocate");
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
name = NULL;
|
name = NULL;
|
||||||
dns_message_currentname(msg, section,
|
dns_message_currentname(msg, section,
|
||||||
@ -363,40 +377,11 @@ detailsection(dig_query_t *query, dns_message_t *msg, isc_boolean_t headers,
|
|||||||
|
|
||||||
switch (rdata.type) {
|
switch (rdata.type) {
|
||||||
case dns_rdatatype_soa:
|
case dns_rdatatype_soa:
|
||||||
result = dns_rdata_tostruct(&rdata,
|
printsoa(&rdata);
|
||||||
&soa, NULL);
|
|
||||||
check_result(result,
|
|
||||||
"dns_rdata_tostruct");
|
|
||||||
|
|
||||||
dns_name_format(&soa.origin, namebuf,
|
|
||||||
sizeof(namebuf));
|
|
||||||
printf("\torigin = %s\n", namebuf);
|
|
||||||
|
|
||||||
dns_name_format(&soa.mname, namebuf,
|
|
||||||
sizeof(namebuf));
|
|
||||||
printf("\tmail addr = %s\n", namebuf);
|
|
||||||
|
|
||||||
printf("\tserial = %u\n", soa.serial);
|
|
||||||
printf("\trefresh = %u\n", soa.refresh);
|
|
||||||
printf("\tretry = %u\n", soa.retry);
|
|
||||||
printf("\texpire = %u\n", soa.expire);
|
|
||||||
printf("\tminimum = %u\n", soa.minimum);
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if (rdata.type < N_KNOWN_RRTYPES)
|
printf("\t");
|
||||||
printf("\t%s",
|
printrdata(&rdata);
|
||||||
rtypetext[rdata.type]);
|
|
||||||
else
|
|
||||||
printf("\trdata_%d = ",
|
|
||||||
rdata.type);
|
|
||||||
isc_buffer_clear(b);
|
|
||||||
result = dns_rdata_totext(&rdata,
|
|
||||||
NULL, b);
|
|
||||||
check_result(result,
|
|
||||||
"dns_rdata_totext");
|
|
||||||
printf("%.*s\n",
|
|
||||||
(int)isc_buffer_usedlength(b),
|
|
||||||
(char*)isc_buffer_base(b));
|
|
||||||
}
|
}
|
||||||
dns_rdata_reset(&rdata);
|
dns_rdata_reset(&rdata);
|
||||||
loopresult = dns_rdataset_next(rdataset);
|
loopresult = dns_rdataset_next(rdataset);
|
||||||
@ -406,11 +391,9 @@ detailsection(dig_query_t *query, dns_message_t *msg, isc_boolean_t headers,
|
|||||||
if (result == ISC_R_NOMORE)
|
if (result == ISC_R_NOMORE)
|
||||||
break;
|
break;
|
||||||
else if (result != ISC_R_SUCCESS) {
|
else if (result != ISC_R_SUCCESS) {
|
||||||
isc_buffer_free (&b);
|
|
||||||
return (result);
|
return (result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
isc_buffer_free(&b);
|
|
||||||
return (ISC_R_SUCCESS);
|
return (ISC_R_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user