6
#include <netinet/in.h>
11
static char sccsid[] = "@(#)sample.c 1.1 12/21/92 (C)1992 Darren Reed. ASYNC DNS";
16
int lookup = 0, seq = 0;
26
int afd, nfd, pid = getpid(), del;
28
afd = ar_init(ARES_INITLIST|ARES_CALLINIT|ARES_INITSOCK);
30
(void)printf("afd = %d pid = %d\n",afd, pid);
34
(void)printf("Host =>");
44
tv2.tv_sec = expire - now;
45
nfd = select(FD_SETSIZE, &rd, NULL, NULL, &tv2);
48
nfd = select(FD_SETSIZE, &rd, NULL, NULL, NULL);
52
if (!fgets(line, sizeof(line) - 1, stdin))
54
if (s = index(line, '\n'))
60
(void)printf("Asking about [%s] #%d.\n",line, ++seq);
61
(void)ar_gethostbyname(line, (char *)&seq,
65
else if (isdigit(*line))
67
(void)printf("Asking about IP#[%s] #%d.\n",
69
adr.s_addr = inet_addr(line);
70
(void)ar_gethostbyaddr(&adr, (char *)&seq,
75
(void)printf("Waiting for answer:\n");
76
if (FD_ISSET(afd, &rd))
77
(void)waitonlookup(afd);
79
expire = ar_timeout(time(NULL), &del, sizeof(del));
82
(void)fprintf(stderr,"#%d failed\n", del);
94
(void)printf("hname = %s\n", hp->h_name);
95
for (i = 0; hp->h_aliases[i]; i++)
96
(void)printf("alias %d = %s\n", i+1, hp->h_aliases[i]);
97
for (i = 0; hp->h_addr_list[i]; i++)
99
bcopy(hp->h_addr_list[i], (char *)&ip, sizeof(ip));
100
(void)printf("IP# %d = %s\n", i+1, inet_ntoa(ip));
104
int waitonlookup(afd)
107
struct timeval delay;
117
delay.tv_sec = expire - now;
124
nfd = select(FD_SETSIZE, &rd, 0, 0, &delay);
127
else if (FD_ISSET(afd, &rd))
130
hp = ar_answer(&del, sizeof(del));
132
(void)printf("hp=%x seq=%d\n",hp,del);
135
(void)printhostent(hp);
140
if (FD_ISSET(0, &rd))