summaryrefslogtreecommitdiff
path: root/usr.sbin/bind/bin/dig/dig.c
diff options
context:
space:
mode:
Diffstat (limited to 'usr.sbin/bind/bin/dig/dig.c')
-rw-r--r--usr.sbin/bind/bin/dig/dig.c65
1 files changed, 45 insertions, 20 deletions
diff --git a/usr.sbin/bind/bin/dig/dig.c b/usr.sbin/bind/bin/dig/dig.c
index df1330be8a2..f2277abcbc1 100644
--- a/usr.sbin/bind/bin/dig/dig.c
+++ b/usr.sbin/bind/bin/dig/dig.c
@@ -15,7 +15,7 @@
* PERFORMANCE OF THIS SOFTWARE.
*/
-/* $ISC: dig.c,v 1.157.2.13.2.20 2004/06/23 04:19:40 marka Exp $ */
+/* $ISC: 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];
@@ -622,6 +626,13 @@ printgreeting(int argc, char **argv, dig_lookup_t *lookup) {
strlcat(lookup->cmdline, append, sizeof(lookup->cmdline));
}
strlcat(lookup->cmdline, "\n", sizeof(lookup->cmdline));
+ if (first && addresscount != 0) {
+ snprintf(append, sizeof(append),
+ "; (%d server%s found)\n",
+ addresscount,
+ addresscount > 1 ? "s" : "");
+ strlcat(lookup->cmdline, append, sizeof(lookup->cmdline));
+ }
if (first) {
snprintf(append, sizeof(append),
";; global options: %s %s\n",
@@ -999,7 +1010,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 */
@@ -1015,6 +1026,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)
@@ -1059,8 +1071,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;
@@ -1262,10 +1273,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);
@@ -1313,12 +1320,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;
@@ -1398,24 +1428,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++;
}
@@ -1486,10 +1512,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;
- }
strlcpy(lookup->textname, rv[0],
sizeof(lookup->textname));
lookup->trace_root = ISC_TF(lookup->trace ||
@@ -1555,6 +1577,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;
}
}