8 #include <netinet/in.h>
13 static char sccsid
[] = "@(#)sample.c 1.1 12/21/92 (C)1992 Darren Reed. ASYNC DNS";
18 int lookup
= 0, seq
= 0;
28 int afd
, nfd
, pid
= getpid(), del
;
30 afd
= ar_init(ARES_INITLIST
|ARES_CALLINIT
|ARES_INITSOCK
);
32 (void)printf("afd = %d pid = %d\n",afd
, pid
);
36 (void)printf("Host =>");
46 tv2
.tv_sec
= expire
- now
;
47 nfd
= select(FD_SETSIZE
, &rd
, NULL
, NULL
, &tv2
);
50 nfd
= select(FD_SETSIZE
, &rd
, NULL
, NULL
, NULL
);
54 if (!fgets(line
, sizeof(line
) - 1, stdin
))
56 if (s
= index(line
, '\n'))
62 (void)printf("Asking about [%s] #%d.\n",line
, ++seq
);
63 (void)ar_gethostbyname(line
, (char *)&seq
,
67 else if (isdigit(*line
))
69 (void)printf("Asking about IP#[%s] #%d.\n",
71 adr
.s_addr
= inet_addr(line
);
72 (void)ar_gethostbyaddr(&adr
, (char *)&seq
,
77 (void)printf("Waiting for answer:\n");
78 if (FD_ISSET(afd
, &rd
))
79 (void)waitonlookup(afd
);
81 expire
= ar_timeout(time(NULL
), &del
, sizeof(del
));
84 (void)fprintf(stderr
,"#%d failed\n", del
);
96 (void)printf("hname = %s\n", hp
->h_name
);
97 for (i
= 0; hp
->h_aliases
[i
]; i
++)
98 (void)printf("alias %d = %s\n", i
+1, hp
->h_aliases
[i
]);
99 for (i
= 0; hp
->h_addr_list
[i
]; i
++)
101 bcopy(hp
->h_addr_list
[i
], (char *)&ip
, sizeof(ip
));
102 (void)printf("IP# %d = %s\n", i
+1, inet_ntoa(ip
));
106 int waitonlookup(afd
)
109 struct timeval delay
;
119 delay
.tv_sec
= expire
- now
;
126 nfd
= select(FD_SETSIZE
, &rd
, 0, 0, &delay
);
129 else if (FD_ISSET(afd
, &rd
))
132 hp
= ar_answer(&del
, sizeof(del
));
134 (void)printf("hp=%x seq=%d\n",hp
,del
);
137 (void)printhostent(hp
);
142 if (FD_ISSET(0, &rd
))