Allow specification of search domain in ahost

Add the "-s domain" command line option to override the search
domains.
pull/17/head
David Drysdale 11 years ago committed by Jakub Hrozek
parent 0004f498dc
commit ee22246507
  1. 14
      ahost.c

@ -52,6 +52,8 @@ static void usage(void);
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
struct ares_options options;
int optmask = 0;
ares_channel channel; ares_channel channel;
int status, nfds, c, addr_family = AF_INET; int status, nfds, c, addr_family = AF_INET;
fd_set read_fds, write_fds; fd_set read_fds, write_fds;
@ -59,6 +61,8 @@ int main(int argc, char **argv)
struct in_addr addr4; struct in_addr addr4;
struct ares_in6_addr addr6; struct ares_in6_addr addr6;
memset(&options, 0, sizeof(options));
#ifdef USE_WINSOCK #ifdef USE_WINSOCK
WORD wVersionRequested = MAKEWORD(USE_WINSOCK,USE_WINSOCK); WORD wVersionRequested = MAKEWORD(USE_WINSOCK,USE_WINSOCK);
WSADATA wsaData; WSADATA wsaData;
@ -72,7 +76,7 @@ int main(int argc, char **argv)
return 1; return 1;
} }
while ((c = ares_getopt(argc,argv,"dt:h")) != -1) while ((c = ares_getopt(argc,argv,"dt:hs:")) != -1)
{ {
switch (c) switch (c)
{ {
@ -81,6 +85,12 @@ int main(int argc, char **argv)
dbug_init(); dbug_init();
#endif #endif
break; break;
case 's':
optmask |= ARES_OPT_DOMAINS;
options.ndomains = 1;
options.domains = malloc(options.ndomains * sizeof(char *));
options.domains[0] = strdup(optarg);
break;
case 't': case 't':
if (!strcasecmp(optarg,"a")) if (!strcasecmp(optarg,"a"))
addr_family = AF_INET; addr_family = AF_INET;
@ -101,7 +111,7 @@ int main(int argc, char **argv)
if (argc < 1) if (argc < 1)
usage(); usage();
status = ares_init(&channel); status = ares_init_options(&channel, &options, optmask);
if (status != ARES_SUCCESS) if (status != ARES_SUCCESS)
{ {
fprintf(stderr, "ares_init: %s\n", ares_strerror(status)); fprintf(stderr, "ares_init: %s\n", ares_strerror(status));

Loading…
Cancel
Save