1 #define _BSD_SOURCE
2 #include <resolv.h>
3 #include <netdb.h>
4
res_query(const char * name,int class,int type,unsigned char * dest,int len)5 int res_query(const char *name, int class, int type, unsigned char *dest, int len)
6 {
7 unsigned char q[280];
8 int ql = __res_mkquery(0, name, class, type, 0, 0, 0, q, sizeof q);
9 if (ql < 0) return ql;
10 int r = __res_send(q, ql, dest, len);
11 if (r<12) {
12 h_errno = TRY_AGAIN;
13 return -1;
14 }
15 if ((dest[3] & 15) == 3) {
16 h_errno = HOST_NOT_FOUND;
17 return -1;
18 }
19 if ((dest[3] & 15) == 0 && !dest[6] && !dest[7]) {
20 h_errno = NO_DATA;
21 return -1;
22 }
23 return r;
24 }
25
26 weak_alias(res_query, res_search);
27