summaryrefslogtreecommitdiffstats
path: root/contrib/bind/bin/dnsquery/dnsquery.c
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/bind/bin/dnsquery/dnsquery.c')
-rw-r--r--contrib/bind/bin/dnsquery/dnsquery.c73
1 files changed, 42 insertions, 31 deletions
diff --git a/contrib/bind/bin/dnsquery/dnsquery.c b/contrib/bind/bin/dnsquery/dnsquery.c
index c9fed3c..cbc1e85 100644
--- a/contrib/bind/bin/dnsquery/dnsquery.c
+++ b/contrib/bind/bin/dnsquery/dnsquery.c
@@ -1,5 +1,5 @@
#if !defined(lint) && !defined(SABER)
-static const char rcsid[] = "$Id: dnsquery.c,v 8.16 2001/09/25 04:50:15 marka Exp $";
+static const char rcsid[] = "$Id: dnsquery.c,v 8.19 2002/04/12 03:03:48 marka Exp $";
#endif /* not lint */
/*
@@ -30,7 +30,6 @@ static const char rcsid[] = "$Id: dnsquery.c,v 8.16 2001/09/25 04:50:15 marka Ex
#include <errno.h>
#include <netdb.h>
-#include <resolv.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -38,21 +37,54 @@ static const char rcsid[] = "$Id: dnsquery.c,v 8.16 2001/09/25 04:50:15 marka Ex
#include "port_after.h"
+#include <resolv.h>
+
extern int errno;
extern int h_errno;
extern char *h_errlist[];
struct __res_state res;
+static int
+newserver(char *srv, union res_sockaddr_union *u, int ns, int max) {
+ struct addrinfo *answer = NULL;
+ struct addrinfo *cur = NULL;
+ struct addrinfo hint;
+ short port = htons(NAMESERVER_PORT);
+
+ memset(&hint, 0, sizeof(hint));
+ hint.ai_socktype = SOCK_DGRAM;
+ if (!getaddrinfo(srv, NULL, &hint, &answer)) {
+ for (cur = answer; cur != NULL; cur = cur->ai_next) {
+ if (ns >= max)
+ break;
+ switch (cur->ai_addr->sa_family) {
+ case AF_INET6:
+ u[ns].sin6 =
+ *(struct sockaddr_in6*)cur->ai_addr;
+ u[ns++].sin6.sin6_port = port;
+ break;
+ case AF_INET:
+ u[ns].sin = *(struct sockaddr_in*)cur->ai_addr;
+ u[ns++].sin6.sin6_port = port;
+ break;
+ }
+ }
+ freeaddrinfo(answer);
+ } else {
+ fprintf(stderr, "Bad nameserver (%s)\n", srv);
+ exit(1);
+ }
+ return (ns);
+}
+
int
main(int argc, char *argv[]) {
char name[MAXDNAME];
u_char answer[8*1024];
- int c, n, i = 0;
- u_int32_t ul;
+ int c, n;
int nameservers = 0, class, type, len;
- struct in_addr q_nsaddr[MAXNS];
- struct hostent *q_nsname;
+ union res_sockaddr_union q_nsaddr[MAXNS];
extern int optind, opterr;
extern char *optarg;
int stream = 0, debug = 0;
@@ -137,23 +169,8 @@ main(int argc, char *argv[]) {
);
exit(1);
}
- if (nameservers >= MAXNS) break;
- (void) inet_aton(optarg,
- &q_nsaddr[nameservers]);
- if (!inet_aton(optarg, (struct in_addr *)&ul)){
- q_nsname = gethostbyname(optarg);
- if (q_nsname == 0) {
- fprintf(stderr,
- "Bad nameserver (%s)\n",
- optarg);
- exit(1);
- }
- memcpy(&q_nsaddr[nameservers],
- q_nsname->h_addr, INADDRSZ);
- }
- else
- q_nsaddr[nameservers].s_addr = ul;
- nameservers++;
+ nameservers = newserver(optarg, q_nsaddr,
+ nameservers, MAXNS);
break;
default : fprintf(stderr,
@@ -189,14 +206,8 @@ main(int argc, char *argv[]) {
res.options |= RES_USEVC;
/* if the -n flag was used, add them to the resolver's list */
- if (nameservers != 0) {
- res.nscount = nameservers;
- for (i = nameservers - 1; i >= 0; i--) {
- res.nsaddr_list[i].sin_addr.s_addr = q_nsaddr[i].s_addr;
- res.nsaddr_list[i].sin_family = AF_INET;
- res.nsaddr_list[i].sin_port = htons(NAMESERVER_PORT);
- }
- }
+ if (nameservers != 0)
+ res_setservers(&res, q_nsaddr, nameservers);
/*
* if the -h arg is fully-qualified, use res_query() since
OpenPOWER on IntegriCloud