From eb886f120599b2a184db20b527db6dfdfcb7852e Mon Sep 17 00:00:00 2001 From: Yu Jiung Date: Wed, 9 Nov 2016 11:18:45 +0900 Subject: Imported Upstream version 1.11.0 Change-Id: I238c24b75a10aa902d9bc4076ed68b76b5e2a750 --- ahost.c | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) (limited to 'ahost.c') diff --git a/ahost.c b/ahost.c index fd6e50d..dec66a9 100644 --- a/ahost.c +++ b/ahost.c @@ -52,6 +52,8 @@ static void usage(void); int main(int argc, char **argv) { + struct ares_options options; + int optmask = 0; ares_channel channel; int status, nfds, c, addr_family = AF_INET; fd_set read_fds, write_fds; @@ -65,6 +67,8 @@ int main(int argc, char **argv) WSAStartup(wVersionRequested, &wsaData); #endif + memset(&options, 0, sizeof(options)); + status = ares_library_init(ARES_LIB_INIT_ALL); if (status != ARES_SUCCESS) { @@ -72,7 +76,7 @@ int main(int argc, char **argv) return 1; } - while ((c = ares_getopt(argc,argv,"dt:h")) != -1) + while ((c = ares_getopt(argc,argv,"dt:hs:")) != -1) { switch (c) { @@ -81,11 +85,20 @@ int main(int argc, char **argv) dbug_init(); #endif break; + case 's': + optmask |= ARES_OPT_DOMAINS; + options.ndomains++; + options.domains = realloc(options.domains, + options.ndomains * sizeof(char *)); + options.domains[options.ndomains - 1] = strdup(optarg); + break; case 't': if (!strcasecmp(optarg,"a")) addr_family = AF_INET; else if (!strcasecmp(optarg,"aaaa")) addr_family = AF_INET6; + else if (!strcasecmp(optarg,"u")) + addr_family = AF_UNSPEC; else usage(); break; @@ -101,7 +114,7 @@ int main(int argc, char **argv) if (argc < 1) usage(); - status = ares_init(&channel); + status = ares_init_options(&channel, &options, optmask); if (status != ARES_SUCCESS) { fprintf(stderr, "ares_init: %s\n", ares_strerror(status)); @@ -130,13 +143,16 @@ int main(int argc, char **argv) /* Wait for all queries to complete. */ for (;;) { + int res; FD_ZERO(&read_fds); FD_ZERO(&write_fds); nfds = ares_fds(channel, &read_fds, &write_fds); if (nfds == 0) break; tvp = ares_timeout(channel, NULL, &tv); - select(nfds, &read_fds, &write_fds, NULL, tvp); + res = select(nfds, &read_fds, &write_fds, NULL, tvp); + if (-1 == res) + break; ares_process(channel, &read_fds, &write_fds); } @@ -185,6 +201,6 @@ static void callback(void *arg, int status, int timeouts, struct hostent *host) static void usage(void) { - fprintf(stderr, "usage: ahost [-t {a|aaaa}] {host|addr} ...\n"); + fprintf(stderr, "usage: ahost [-t {a|aaaa|u}] {host|addr} ...\n"); exit(1); } -- cgit v1.2.3