- #include <stdio.h>
- #include <sys/types.h>
- #include <arpa/nameser.h>
- #include <netdb.h>
- #include <sys/socket.h>
- #include <netinet/in.h>
- #include <resolv.h>
- #include <sys/param.h>
- #include <string.h>
- #include <ctype.h>
- typedef union {
- HEADER qb1;
- char qb2[PACKETSZ];
- } querybuf;
- int getinfo(
- char *name,
- char *domain,
- int type)
- {
- HEADER *hp;
- char *eom, *cp;
- querybuf buf, answer;
- int n;
- int ancount, nscount, arcount, qdcount;
- char host[2*MAXDNAME+2];
- if (domain == NULL)
- else
- n = res_mkquery(QUERY, host, C_IN, type, (char *)NULL, 0, NULL,
- (char *)&buf, sizeof(buf));
- if (n < 0) {
- if (_res.options & RES_DEBUG)
- h_errno = NO_RECOVERY;
- return(0);
- }
- n = res_send((char *)&buf, n, (char *)&answer, sizeof(answer));
- if (n < 0) {
- if (_res.options & RES_DEBUG)
- h_errno = TRY_AGAIN;
- return (0);
- }
- eom = (char *)&answer + n;
- hp = (HEADER *)&answer;
- ancount = ntohs(hp->ancount);
- qdcount = ntohs(hp->qdcount);
- nscount = ntohs(hp->nscount);
- arcount = ntohs(hp->arcount);
- ancount, qdcount, nscount, arcount);
- return(n);
- }
- void main(
- int argc,
- char **argv)
- {
- int status;
- res_init();
- _res.options |= RES_USEVC;
- _res.retry = 1;
- _res.retrans = 15;
- _res.options &= ~RES_RECURSE;
- _res.options |= RES_DEBUG;
- if (argc < 3)
- status = getinfo(argv[1], "cs.clemson.edu.", T_A);
- else
- status = getinfo(argv[1], argv[2], T_A);
- }
Raw Paste