summaryrefslogtreecommitdiff
path: root/ahost.c
diff options
context:
space:
mode:
authorYu Jiung <jiung.yu@samsung.com>2016-11-10 16:24:08 +0900
committerYu Jiung <jiung.yu@samsung.com>2016-11-10 16:25:02 +0900
commit8166b0204b6945a4fdb89bbae0b0b7168a7cf6e8 (patch)
tree81f0750d91aa467df3ee81cf30d22a65db2e6685 /ahost.c
parentccccebb78520ec3a26a18370936516b12ae5d53a (diff)
parent45e88a8337839e5fd88519bc55467053d521c9f6 (diff)
downloadc-ares-196915eb4535a755c5005b5befd9d01b72120215.tar.gz
c-ares-196915eb4535a755c5005b5befd9d01b72120215.tar.bz2
c-ares-196915eb4535a755c5005b5befd9d01b72120215.zip
Conflicts: packaging/c-ares.spec Change-Id: I1ec10e394aed3ef19ee21fefbe3aba7d7a615c74
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);
}