summaryrefslogtreecommitdiff
path: root/ahost.c
diff options
context:
space:
mode:
Diffstat (limited to 'ahost.c')
-rw-r--r--ahost.c24
1 files changed, 20 insertions, 4 deletions
diff --git a/ahost.c b/ahost.c
index fd6e50d..7fbfd64 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 = (char **)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);
}