/* query.c */ /* A simple example of how to use resolver services to */ /* make a name server query. */ #include #include #include #include #include #include #include #include #include #include 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) (void)sprintf(host, "%.*s", MAXDNAME, name); else (void)sprintf(host, "%.*s.%.*s", MAXDNAME, name, MAXDNAME, domain); printf("Querying name: %s\n", host); n = res_mkquery(QUERY, host, C_IN, type, (char *)NULL, 0, NULL, (char *)&buf, sizeof(buf)); if (n < 0) { if (_res.options & RES_DEBUG) printf("res_mkquery failed\n"); h_errno = NO_RECOVERY; return(0); } n = res_send((char *)&buf, n, (char *)&answer, sizeof(answer)); if (n < 0) { if (_res.options & RES_DEBUG) printf("res_send failed\n"); 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); printf("Ans %d - QDs %d - NSs %d - ARs %d \n", 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); printf("%d bytes returned \n", status); }