Commit 5d20773a authored by Michael Sawyer's avatar Michael Sawyer
Browse files

Move generation of reverse lookups (blah.in-addr.arpa, etc...) names to

a common place.
parent 8e61de2e
......@@ -15,7 +15,7 @@
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: dig.c,v 1.121 2000/10/20 19:53:59 gson Exp $ */
/* $Id: dig.c,v 1.122 2000/10/23 23:13:16 mws Exp $ */
#include <config.h>
#include <stdlib.h>
......@@ -895,9 +895,7 @@ dash_option(char *option, char *next, dig_lookup_t **lookup,
isc_textregion_t tr;
dns_rdatatype_t rdtype;
dns_rdataclass_t rdclass;
int adrs[4];
int n, i;
char batchline[MXNAME];
char textname[MXNAME];
cmd = option[0];
if (strlen(option) > 1) {
......@@ -996,54 +994,21 @@ dash_option(char *option, char *next, dig_lookup_t **lookup,
return (value_from_next);
case 'x':
*lookup = clone_lookup(default_lookup, ISC_TRUE);
if (strchr(value, ':') == NULL) {
n = sscanf(value, "%d.%d.%d.%d",
&adrs[0], &adrs[1],
&adrs[2], &adrs[3]);
if (n == 0) {
show_usage();
exit (1);
}
for (i = n - 1; i >= 0; i--) {
snprintf(batchline, MXNAME/8, "%d.",
adrs[i]);
strncat((*lookup)->textname, batchline,
MXNAME);
}
strncat((*lookup)->textname, "in-addr.arpa.",
MXNAME);
} else {
isc_netaddr_t addr;
dns_fixedname_t fname;
dns_name_t *name;
isc_buffer_t b;
addr.family = AF_INET6;
n = inet_pton(AF_INET6, value, &addr.type.in6);
if (n <= 0)
show_usage();
dns_fixedname_init(&fname);
name = dns_fixedname_name(&fname);
if (get_reverse(textname, value, nibble) == ISC_R_SUCCESS) {
strncpy((*lookup)->textname, textname,
sizeof((*lookup)->textname));
debug("looking up %s", (*lookup)->textname);
(*lookup)->trace_root = ISC_TF((*lookup)->trace ||
(*lookup)->ns_search_only);
(*lookup)->nibble = nibble;
result = dns_byaddr_createptrname(&addr, nibble,
name);
if (result != ISC_R_SUCCESS)
show_usage();
isc_buffer_init(&b, (*lookup)->textname,
sizeof (*lookup)->textname);
result = dns_name_totext(name, ISC_FALSE, &b);
isc_buffer_putuint8(&b, 0);
if (result != ISC_R_SUCCESS)
show_usage();
(*lookup)->rdtype = dns_rdatatype_ptr;
(*lookup)->rdclass = dns_rdataclass_in;
(*lookup)->new_search = ISC_TRUE;
ISC_LIST_APPEND(lookup_list, *lookup, link);
} else {
fprintf(stderr, "Invalid IP address %s\n", value);
exit(1);
}
debug("looking up %s", (*lookup)->textname);
(*lookup)->trace_root = ISC_TF((*lookup)->trace ||
(*lookup)->ns_search_only);
(*lookup)->rdtype = dns_rdatatype_ptr;
(*lookup)->rdclass = dns_rdataclass_in;
(*lookup)->new_search = ISC_TRUE;
ISC_LIST_APPEND(lookup_list, *lookup, link);
return (value_from_next);
invalid_option:
default:
......
......@@ -15,7 +15,7 @@
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: dighost.c,v 1.156 2000/10/23 17:49:03 mws Exp $ */
/* $Id: dighost.c,v 1.157 2000/10/23 23:13:17 mws Exp $ */
/*
* Notice to programmers: Do not use this code as an example of how to
......@@ -36,6 +36,7 @@
extern int h_errno;
#endif
#include <dns/byaddr.h>
#include <dns/fixedname.h>
#include <dns/message.h>
#include <dns/name.h>
......@@ -55,6 +56,7 @@ extern int h_errno;
#include <isc/base64.h>
#include <isc/entropy.h>
#include <isc/lang.h>
#include <isc/netaddr.h>
#include <isc/netdb.h>
#include <isc/result.h>
#include <isc/string.h>
......@@ -97,7 +99,7 @@ int ndots = -1;
int tries = 2;
int lookup_counter = 0;
char fixeddomain[MXNAME] = "";
dig_server_t *fixedsearch = NULL;
dig_searchlist_t *fixedsearch = NULL;
/*
* Exit Codes:
* 0 Everything went well, including things like NXDOMAIN
......@@ -192,6 +194,55 @@ hex_dump(isc_buffer_t *b) {
printf("\n");
}
isc_result_t
get_reverse(char reverse[MXNAME], char *value, isc_boolean_t nibble) {
int adrs[4];
char working[MXNAME];
int i, n;
isc_result_t result;
result = DNS_R_BADDOTTEDQUAD;
debug("get_reverse(%s)", value);
if (strspn(value, "0123456789.") == strlen(value)) {
n = sscanf(value, "%d.%d.%d.%d",
&adrs[0], &adrs[1],
&adrs[2], &adrs[3]);
if (n == 0) {
return (DNS_R_BADDOTTEDQUAD);
}
for (i = n - 1; i >= 0; i--) {
snprintf(working, MXNAME/8, "%d.",
adrs[i]);
strncat(reverse, working, MXNAME);
}
strncat(reverse, "in-addr.arpa.", MXNAME);
result = ISC_R_SUCCESS;
} else if (strspn(value, "0123456789abcdefABCDEF:")
== strlen(value)) {
isc_netaddr_t addr;
dns_fixedname_t fname;
dns_name_t *name;
isc_buffer_t b;
addr.family = AF_INET6;
n = inet_pton(AF_INET6, value, &addr.type.in6);
if (n <= 0)
return (DNS_R_BADDOTTEDQUAD);
dns_fixedname_init(&fname);
name = dns_fixedname_name(&fname);
result = dns_byaddr_createptrname(&addr, nibble,
name);
if (result != ISC_R_SUCCESS)
return (result);
isc_buffer_init(&b, reverse, MXNAME);
result = dns_name_totext(name, ISC_FALSE, &b);
isc_buffer_putuint8(&b, 0);
}
return (result);
}
void
fatal(const char *format, ...) {
va_list args;
......@@ -1227,10 +1278,9 @@ setup_lookup(dig_lookup_t *lookup) {
if (fixedsearch == NULL)
fatal("Memory allocation failure in %s:%d",
__FILE__, __LINE__);
strncpy(fixedsearch->servername, fixeddomain,
sizeof(fixedsearch->servername));
fixedsearch->servername[sizeof
(fixedsearch->servername)-1]=0;
strncpy(fixedsearch->origin, fixeddomain,
sizeof(fixedsearch->origin));
fixedsearch->origin[sizeof(fixedsearch->origin)-1]=0;
lookup->origin = fixedsearch;
} else
lookup->origin = ISC_LIST_HEAD(search_list);
......
......@@ -15,7 +15,7 @@
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: host.c,v 1.56 2000/10/19 23:31:56 mws Exp $ */
/* $Id: host.c,v 1.57 2000/10/23 23:13:19 mws Exp $ */
#include <config.h>
#include <stdlib.h>
......@@ -542,7 +542,7 @@ parse_args(isc_boolean_t is_batchfile, int argc, char **argv) {
char hostname[MXNAME];
dig_server_t *srv;
dig_lookup_t *lookup;
int i, c, n, adrs[4];
int c;
char store[MXNAME];
isc_textregion_t tr;
isc_result_t result;
......@@ -648,44 +648,11 @@ parse_args(isc_boolean_t is_batchfile, int argc, char **argv) {
}
lookup->pending = ISC_FALSE;
if (strspn(hostname, "0123456789.") == strlen(hostname)) {
lookup->textname[0] = 0;
n = sscanf(hostname, "%d.%d.%d.%d", &adrs[0], &adrs[1],
&adrs[2], &adrs[3]);
if (n == 0) {
show_usage();
}
for (i = n - 1; i >= 0; i--) {
snprintf(store, MXNAME/8, "%d.",
adrs[i]);
strncat(lookup->textname, store, MXNAME);
}
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();
if (get_reverse(store, hostname, lookup->nibble) == ISC_R_SUCCESS) {
strncpy(lookup->textname, store, sizeof(lookup->textname));
lookup->textname[sizeof(lookup->textname)-1] = 0;
lookup->rdtype = dns_rdatatype_ptr;
} else {
notv6:
strncpy(lookup->textname, hostname, sizeof(lookup->textname));
lookup->textname[sizeof(lookup->textname)-1]=0;
}
......
......@@ -15,7 +15,7 @@
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: dig.h,v 1.54 2000/10/20 05:03:31 mws Exp $ */
/* $Id: dig.h,v 1.55 2000/10/23 23:13:21 mws Exp $ */
#ifndef DIG_H
#define DIG_H
......@@ -177,6 +177,9 @@ struct dig_searchlist {
void
get_address(char *host, in_port_t port, isc_sockaddr_t *sockaddr);
isc_result_t
get_reverse(char reverse[MXNAME], char *value, isc_boolean_t nibble);
void
fatal(const char *format, ...);
......
......@@ -15,7 +15,7 @@
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: nslookup.c,v 1.59 2000/10/23 17:49:05 mws Exp $ */
/* $Id: nslookup.c,v 1.60 2000/10/23 23:13:20 mws Exp $ */
#include <config.h>
......@@ -700,6 +700,7 @@ addlookup(char *opt) {
isc_textregion_t tr;
dns_rdatatype_t rdtype;
dns_rdataclass_t rdclass;
char store[MXNAME];
debug("addlookup()");
tr.base = deftype;
......@@ -717,49 +718,11 @@ addlookup(char *opt) {
rdclass = dns_rdataclass_in;
}
lookup = make_empty_lookup();
if (strspn(opt, "0123456789.") == strlen(opt)) {
int n, i, adrs[4];
char store[MXNAME];
lookup->textname[0] = 0;
n = sscanf(opt, "%d.%d.%d.%d", &adrs[0], &adrs[1],
&adrs[2], &adrs[3]);
if (n == 0) {
show_usage();
}
for (i = n - 1; i >= 0; i--) {
snprintf(store, MXNAME/8, "%d.",
adrs[i]);
strncat(lookup->textname, store, MXNAME);
}
strncat(lookup->textname, "in-addr.arpa.", MXNAME);
lookup->rdtype = dns_rdatatype_ptr;
} else if (strspn(opt, "0123456789abcdef.:") == strlen(opt))
{
isc_netaddr_t addr;
dns_fixedname_t fname;
isc_buffer_t b;
int n;
addr.family = AF_INET6;
n = inet_pton(AF_INET6, opt, &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();
if (get_reverse(store, opt, lookup->nibble) == ISC_R_SUCCESS) {
safecpy(lookup->textname, store, sizeof(lookup->textname));
lookup->rdtype = dns_rdatatype_ptr;
} else {
notv6:
safecpy(lookup->textname, opt, MXNAME-1);
safecpy(lookup->textname, opt, sizeof(lookup->textname));
lookup->rdtype = rdtype;
}
lookup->rdclass = rdclass;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment