From 6d3f954c572db02159deedd444373161fda47a88 Mon Sep 17 00:00:00 2001 From: Brian Wellington Date: Mon, 14 Aug 2000 19:11:05 +0000 Subject: [PATCH] 388. [func] host can now do reverse ipv6 lookups. --- CHANGES | 2 ++ bin/dig/dighost.c | 3 ++- bin/dig/host.c | 39 ++++++++++++++++++++++++++++++++------- bin/dig/include/dig/dig.h | 3 ++- 4 files changed, 38 insertions(+), 9 deletions(-) diff --git a/CHANGES b/CHANGES index cde073d821..601644bfe9 100644 --- a/CHANGES +++ b/CHANGES @@ -1,4 +1,6 @@ + 388. [func] host can now do reverse ipv6 lookups. + 387. [func] Add dns_byaddr_createptrname(), which converts an address into the name used by a PTR query. diff --git a/bin/dig/dighost.c b/bin/dig/dighost.c index 8d5d2d419f..1d43d91522 100644 --- a/bin/dig/dighost.c +++ b/bin/dig/dighost.c @@ -15,7 +15,7 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: dighost.c,v 1.114 2000/08/09 19:10:54 gson Exp $ */ +/* $Id: dighost.c,v 1.115 2000/08/14 19:11:02 bwelling Exp $ */ /* * Notice to programmers: Do not use this code as an example of how to @@ -292,6 +292,7 @@ make_empty_lookup(void) { looknew->retries = tries; looknew->nsfound = 0; looknew->tcp_mode = ISC_FALSE; + looknew->nibble = ISC_FALSE; looknew->comments = ISC_TRUE; looknew->stats = ISC_TRUE; looknew->section_question = ISC_TRUE; diff --git a/bin/dig/host.c b/bin/dig/host.c index 9eb267dd4f..9483f00a2d 100644 --- a/bin/dig/host.c +++ b/bin/dig/host.c @@ -15,7 +15,7 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: host.c,v 1.46 2000/08/03 17:43:04 mws Exp $ */ +/* $Id: host.c,v 1.47 2000/08/14 19:11:03 bwelling Exp $ */ #include #include @@ -25,10 +25,13 @@ extern int h_errno; #include #include +#include #include #include #include +#include +#include #include #include #include @@ -210,13 +213,14 @@ static const char *rtypetext[] = { static void show_usage(void) { fputs( -"Usage: host [-aCdlrTwv] [-c class] [-N ndots] [-t type] [-W time]\n" +"Usage: host [-aCdlrTwv] [-c class] [-n] [-N ndots] [-t type] [-W time]\n" " [-R number] hostname [server]\n" " -a is equivalent to -v -t *\n" " -c specifies query class for non-IN data\n" " -C compares SOA records on authorative nameservers\n" " -d is equivalent to -v\n" " -l lists all hosts in a domain, using AXFR\n" +" -n Use the nibble form of IPv6 reverse lookup\n" " -N changes the number of dots allowed before root lookup is done\n" " -r disables recursive processing\n" " -R specifies number of retries for UDP packets\n" @@ -542,7 +546,7 @@ parse_args(isc_boolean_t is_batchfile, int argc, char **argv) { lookup = make_empty_lookup(); - while ((c = isc_commandline_parse(argc, argv, "lvwrdt:c:aTCN:R:W:D")) + while ((c = isc_commandline_parse(argc, argv, "lvwrdt:c:aTCN:R:W:Dn")) != EOF) { switch (c) { case 'l': @@ -584,6 +588,9 @@ parse_args(isc_boolean_t is_batchfile, int argc, char **argv) { lookup->rdtype = dns_rdatatype_any; short_form = ISC_FALSE; break; + case 'n': + lookup->nibble = ISC_TRUE; + break; case 'w': /* * The timer routines are coded such that @@ -633,10 +640,6 @@ parse_args(isc_boolean_t is_batchfile, int argc, char **argv) { } lookup->pending = ISC_FALSE; - /* - * XXXMWS Add IPv6 translation here, probably using inet_pton - * to extract the formatted text. - */ if (strspn(hostname, "0123456789.") == strlen(hostname)) { lookup->textname[0] = 0; n = sscanf(hostname, "%d.%d.%d.%d", &adrs[0], &adrs[1], @@ -651,7 +654,29 @@ parse_args(isc_boolean_t is_batchfile, int argc, char **argv) { } strncat(lookup->textname, "in-addr.arpa.", MXNAME); lookup->rdtype = dns_rdatatype_ptr; + } else if (strspn(hostname, "0123456789abcdef.:") == strlen(hostname)) + { + isc_netaddr_t addr; + dns_fixedname_t fname; + isc_buffer_t b; + + addr.family = AF_INET6; + n = inet_pton(AF_INET6, hostname, &addr.type.in6); + if (n <= 0) + goto notv6; + dns_fixedname_init(&fname); + result = dns_byaddr_createptrname(&addr, lookup->nibble, + dns_fixedname_name(&fname)); + if (result != ISC_R_SUCCESS) + show_usage(); + isc_buffer_init(&b, lookup->textname, sizeof lookup->textname); + result = dns_name_totext(dns_fixedname_name(&fname), + ISC_FALSE, &b); + isc_buffer_putuint8(&b, 0); + if (result != ISC_R_SUCCESS) + show_usage(); } else { + notv6: strncpy(lookup->textname, hostname, MXNAME); } lookup->new_search = ISC_TRUE; diff --git a/bin/dig/include/dig/dig.h b/bin/dig/include/dig/dig.h index 1ae42883d0..4a6d739cdd 100644 --- a/bin/dig/include/dig/dig.h +++ b/bin/dig/include/dig/dig.h @@ -15,7 +15,7 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: dig.h,v 1.42 2000/08/09 00:09:27 gson Exp $ */ +/* $Id: dig.h,v 1.43 2000/08/14 19:11:05 bwelling Exp $ */ #ifndef DIG_H #define DIG_H @@ -84,6 +84,7 @@ struct dig_lookup { trace_root, defname, tcp_mode, + nibble, comments, stats, section_question,