1 /* Copyright 1998 by the Massachusetts Institute of Technology.
3 * Permission to use, copy, modify, and distribute this
4 * software and its documentation for any purpose and without
5 * fee is hereby granted, provided that the above copyright
6 * notice appear in all copies and that both that copyright
7 * notice and this permission notice appear in supporting
8 * documentation, and that the name of M.I.T. not be used in
9 * advertising or publicity pertaining to distribution of the
10 * software without specific, written prior permission.
11 * M.I.T. makes no representations about the suitability of
12 * this software for any purpose. It is provided "as is"
13 * without express or implied warranty.
17 #include <sys/types.h>
22 #include <sys/socket.h>
23 #include <netinet/in.h>
24 #include <arpa/inet.h>
36 #define INADDR_NONE 0xffffffff
39 static void callback(void *arg, int status, struct hostent *host);
40 static void usage(void);
42 int main(int argc, char **argv)
46 fd_set read_fds, write_fds;
47 struct timeval *tvp, tv;
51 WORD wVersionRequested = MAKEWORD(1,1);
53 WSAStartup(wVersionRequested, &wsaData);
59 status = ares_init(&channel);
60 if (status != ARES_SUCCESS)
62 fprintf(stderr, "ares_init: %s\n", ares_strerror(status));
66 /* Initiate the queries, one per command-line argument. */
67 for (argv++; *argv; argv++)
69 addr.s_addr = inet_addr(*argv);
70 if (addr.s_addr == INADDR_NONE)
71 ares_gethostbyname(channel, *argv, AF_INET, callback, *argv);
74 ares_gethostbyaddr(channel, &addr, sizeof(addr), AF_INET, callback,
79 /* Wait for all queries to complete. */
84 nfds = ares_fds(channel, &read_fds, &write_fds);
87 tvp = ares_timeout(channel, NULL, &tv);
88 select(nfds, &read_fds, &write_fds, NULL, tvp);
89 ares_process(channel, &read_fds, &write_fds);
92 ares_destroy(channel);
96 static void callback(void *arg, int status, struct hostent *host)
101 if (status != ARES_SUCCESS)
103 fprintf(stderr, "%s: %s\n", (char *) arg, ares_strerror(status));
107 for (p = host->h_addr_list; *p; p++)
109 memcpy(&addr, *p, sizeof(struct in_addr));
110 printf("%-32s\t%s\n", host->h_name, inet_ntoa(addr));
114 static void usage(void)
116 fprintf(stderr, "usage: ahost {host|addr} ...\n");