diff options
Diffstat (limited to 'bin/dig/dig.c')
-rw-r--r-- | bin/dig/dig.c | 67 |
1 files changed, 47 insertions, 20 deletions
diff --git a/bin/dig/dig.c b/bin/dig/dig.c index b2c46254..08f5b5b5 100644 --- a/bin/dig/dig.c +++ b/bin/dig/dig.c @@ -15,7 +15,7 @@ * PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: dig.c,v 1.157.2.13.2.20 2004/06/23 04:19:40 marka Exp $ */ +/* $Id: dig.c,v 1.157.2.13.2.25 2004/09/16 02:14:14 marka Exp $ */ #include <config.h> #include <stdlib.h> @@ -41,6 +41,8 @@ #include <dns/rdataclass.h> #include <dns/result.h> +#include <bind9/getaddresses.h> + #include <dig/dig.h> extern ISC_LIST(dig_lookup_t) lookup_list; @@ -54,6 +56,7 @@ extern ISC_LIST(dig_searchlist_t) search_list; isc_buffer_putstr(b, s); \ } +#define DIG_MAX_ADDRESSES 20 extern isc_boolean_t have_ipv4, have_ipv6, specified_source, usesearch, qr; @@ -83,6 +86,7 @@ extern isc_boolean_t debugging, memdebugging; static char *batchname = NULL; static FILE *batchfp = NULL; static char *argv0; +static int addresscount = 0; static char domainopt[DNS_NAME_MAXTEXT]; @@ -627,6 +631,15 @@ printgreeting(int argc, char **argv, dig_lookup_t *lookup) { remaining = sizeof(lookup->cmdline) - strlen(lookup->cmdline) - 1; strncat(lookup->cmdline, "\n", remaining); + if (first && addresscount != 0) { + snprintf(append, sizeof(append), + "; (%d server%s found)\n", + addresscount, + addresscount > 1 ? "s" : ""); + remaining = sizeof(lookup->cmdline) - + strlen(lookup->cmdline) - 1; + strncat(lookup->cmdline, append, remaining); + } if (first) { snprintf(append, sizeof(append), ";; global options: %s %s\n", @@ -1008,7 +1021,7 @@ plus_option(char *option, isc_boolean_t is_batchfile, lookup->stats = ISC_FALSE; lookup->section_additional = ISC_FALSE; lookup->section_authority = ISC_TRUE; - lookup->section_question = ISC_FALSE; + lookup->section_question = ISC_FALSE; } break; case 'i': /* tries */ @@ -1024,6 +1037,7 @@ plus_option(char *option, isc_boolean_t is_batchfile, break; #ifdef DIG_SIGCHASE case 'u': /* trusted-key */ + FULLCHECK("trusted-key"); if (value == NULL) goto need_value; if (!state) @@ -1068,8 +1082,7 @@ static const char *single_dash_opts = "46dhimnv"; static const char *dash_opts = "46bcdfhikmnptvyx"; static isc_boolean_t dash_option(char *option, char *next, dig_lookup_t **lookup, - isc_boolean_t *open_type_class, isc_boolean_t *firstarg, - int argc, char **argv) + isc_boolean_t *open_type_class) { char opt, *value, *ptr; isc_result_t result; @@ -1274,10 +1287,6 @@ dash_option(char *option, char *next, dig_lookup_t **lookup, if (!(*lookup)->rdclassset) (*lookup)->rdclass = dns_rdataclass_in; (*lookup)->new_search = ISC_TRUE; - if (*lookup && *firstarg) { - printgreeting(argc, argv, *lookup); - *firstarg = ISC_FALSE; - } ISC_LIST_APPEND(lookup_list, *lookup, link); } else { fprintf(stderr, "Invalid IP address %s\n", value); @@ -1325,12 +1334,35 @@ preparse_args(int argc, char **argv) { } static void +getaddresses(dig_lookup_t *lookup, const char *host) { + isc_result_t result; + isc_sockaddr_t sockaddrs[DIG_MAX_ADDRESSES]; + isc_netaddr_t netaddr; + int count, i; + dig_server_t *srv; + char tmp[ISC_NETADDR_FORMATSIZE]; + + result = bind9_getaddresses(host, 0, sockaddrs, + DIG_MAX_ADDRESSES, &count); + if (result != ISC_R_SUCCESS) + fatal("couldn't get address for '%s': %s", + host, isc_result_totext(result)); + + for (i = 0; i < count; i++) { + isc_netaddr_fromsockaddr(&netaddr, &sockaddrs[i]); + isc_netaddr_format(&netaddr, tmp, sizeof(tmp)); + srv = make_server(tmp, host); + ISC_LIST_APPEND(lookup->my_server_list, srv, link); + } + addresscount = count; +} + +static void parse_args(isc_boolean_t is_batchfile, isc_boolean_t config_only, int argc, char **argv) { isc_result_t result; isc_textregion_t tr; isc_boolean_t firstarg = ISC_TRUE; - dig_server_t *srv = NULL; dig_lookup_t *lookup = NULL; dns_rdatatype_t rdtype; dns_rdataclass_t rdclass; @@ -1410,24 +1442,20 @@ parse_args(isc_boolean_t is_batchfile, isc_boolean_t config_only, if (strncmp(rv[0], "%", 1) == 0) break; if (strncmp(rv[0], "@", 1) == 0) { - srv = make_server(&rv[0][1]); - ISC_LIST_APPEND(lookup->my_server_list, - srv, link); + getaddresses(lookup, &rv[0][1]); } else if (rv[0][0] == '+') { plus_option(&rv[0][1], is_batchfile, lookup); } else if (rv[0][0] == '-') { if (rc <= 1) { if (dash_option(&rv[0][1], NULL, - &lookup, &open_type_class, - &firstarg, argc, argv)) { + &lookup, &open_type_class)) { rc--; rv++; } } else { if (dash_option(&rv[0][1], rv[1], - &lookup, &open_type_class, - &firstarg, argc, argv)) { + &lookup, &open_type_class)) { rc--; rv++; } @@ -1498,10 +1526,6 @@ parse_args(isc_boolean_t is_batchfile, isc_boolean_t config_only, if (!config_only) { lookup = clone_lookup(default_lookup, ISC_TRUE); - if (firstarg) { - printgreeting(argc, argv, lookup); - firstarg = ISC_FALSE; - } strncpy(lookup->textname, rv[0], sizeof(lookup->textname)); lookup->textname[sizeof(lookup->textname)-1]=0; @@ -1568,6 +1592,9 @@ parse_args(isc_boolean_t is_batchfile, isc_boolean_t config_only, firstarg = ISC_FALSE; } ISC_LIST_APPEND(lookup_list, lookup, link); + } else if (!config_only && firstarg) { + printgreeting(argc, argv, lookup); + firstarg = ISC_FALSE; } } |