38 int cbyte, rrstart, wantedrrs, rri, foundsoa, foundns, cname_here;
39 int id,
f1,
f2, qdcount, ancount, nscount, arcount;
40 int flg_ra, flg_rd, flg_tc, flg_qr, opcode;
41 int rrtype, rrclass, rdlength, rdstart;
42 int anstart, nsstart, arstart;
43 int ownermatched,
l, nrrs;
44 unsigned long ttl, soattl;
50 byte *newquery, *rrsdata;
54 adns__diag(
ads,serv,0,
"received datagram too short for message header (%d)",dglen);
77 adns__diag(
ads,serv,0,
"server sent us a query, not a response");
81 adns__diag(
ads,serv,0,
"server sent us unknown opcode %d (wanted 0=QUERY)",opcode);
89 for (qu= viatcp ?
ads->tcpw.head :
ads->udpw.head; qu; qu= nqu) {
91 if (qu->
id !=
id)
continue;
92 if (dglen < qu->query_dglen)
continue;
101 if (!(qu->
udpsent & (1<<serv)))
continue;
121 adns__warn(
ads,serv,qu,
"server cannot understand our query (Format Error)");
126 else adns__debug(
ads,serv,qu,
"server failure on unidentifiable query");
129 adns__warn(
ads,serv,qu,
"server claims not to implement our query");
144 adns__diag(
ads,serv,0,
"server sent reply without quoting our question");
145 }
else if (qdcount>1) {
146 adns__diag(
ads,serv,0,
"server claimed to answer %d questions with one message",
150 adns__debug(
ads,serv,0,
"reply not found, id %02x, query owner %s",
167 for (rri= 0; rri<ancount; rri++) {
170 &rrtype,&rrclass,&ttl, &rdlength,&rdstart,
173 if (rrtype == -1)
goto x_truncated;
176 adns__diag(
ads,serv,qu,
"ignoring answer RR with wrong class %d (expected IN=%d)",
182 adns__debug(
ads,serv,qu,
"ignoring RR with an unexpected owner %s",
193 adns__debug(
ads,serv,qu,
"allegedly canonical name %s is actually alias for %s",
198 }
else if (wantedrrs) {
199 adns__debug(
ads,serv,qu,
"ignoring CNAME (to %s) coexisting with RR",
206 dgram,dglen, &rdstart,rdstart+rdlength);
207 if (!qu->
vb.
used)
goto x_truncated;
228 adns__debug(
ads,serv,qu,
"ignoring answer RR with irrelevant type %d",rrtype);
235 if (flg_tc)
goto x_truncated;
243 foundsoa= 0; soattl= 0; foundns= 0;
244 for (rri= 0; rri<nscount; rri++) {
247 &rrtype,&rrclass,&ttl, &rdlength,&rdstart, 0);
249 if (rrtype==-1)
goto x_truncated;
252 "ignoring authority RR with wrong class %d (expected IN=%d)",
256 if (rrtype ==
adns_r_soa_raw) { foundsoa= 1; soattl= ttl;
break; }
272 if (foundsoa || !foundns) {
284 if (cname_here)
goto x_restartquery;
288 adns__diag(
ads,serv,qu,
"server is not willing to do recursive lookups for us");
292 adns__diag(
ads,serv,qu,
"server thinks we didn't ask for recursive lookup");
294 adns__debug(
ads,serv,qu,
"server claims to do recursion, but gave us a referral");
319 for (rri=0, nrrs=0; rri<ancount; rri++) {
321 &rrtype,&rrclass,&ttl, &rdlength,&rdstart,
329 st= typei->
parse(&pai, rdstart,rdstart+rdlength, rrsdata+nrrs*typei->
rrsz);
331 if (rdstart==-1)
goto x_truncated;
339 qu->
state= query_childw;
349 adns__diag(
ads,serv,qu,
"server sent datagram which points outside itself");
370 if (qu->
state == query_tcpw) qu->
state= query_tosend;
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
ACPI_SIZE strlen(const char *String)
@ adns_s_rcodeformaterror
@ adns_s_rcodenotimplemented
@ adns_qf_quotefail_cname
#define memcpy(s1, s2, n)
#define LIST_UNLINK(list, node)
#define LIST_LINK_TAIL(list, node)
void adns__vbuf_init(vbuf *vb)
void adns__debug(adns_state ads, int serv, adns_query qu, const char *fmt,...)
void adns__vbuf_free(vbuf *vb)
void adns__warn(adns_state ads, int serv, adns_query qu, const char *fmt,...)
const char * adns__diag_domain(adns_state ads, int serv, adns_query qu, vbuf *vb, const byte *dgram, int dglen, int cbyte)
void adns__diag(adns_state ads, int serv, adns_query qu, const char *fmt,...)
void * adns__alloc_preserved(adns_query qu, size_t sz)
void * adns__alloc_interim(adns_query qu, size_t sz)
adns_status adns__findrr(adns_query qu, int serv, const byte *dgram, int dglen, int *cbyte_io, int *type_r, int *class_r, unsigned long *ttl_r, int *rdlen_r, int *rdstart_r, int *ownermatchedquery_r)
void adns__query_fail(adns_query qu, adns_status stat)
void * adns__alloc_mine(adns_query qu, size_t sz)
adns_status adns__parse_domain(adns_state ads, int serv, adns_query qu, vbuf *vb, adns_queryflags flags, const byte *dgram, int dglen, int *cbyte_io, int max)
void adns__search_next(adns_state ads, adns_query qu, struct timeval now)
void adns__reset_preserved(adns_query qu)
adns_status adns__mkquery_frdgram(adns_state ads, vbuf *vb, int *id_r, const byte *qd_dgram, int qd_dglen, int qd_begin, adns_rrtype type, adns_queryflags flags)
void adns__query_send(adns_query qu, struct timeval now)
void adns__update_expires(adns_query qu, unsigned long ttl, struct timeval now)
void adns__query_done(adns_query qu)
void adns__procdgram(adns_state ads, const byte *dgram, int dglen, int serv, int viatcp, struct timeval now)
struct adns__query::@4220 children
enum adns__query::@4219 state
union adns_answer::@4217 rrs
adns_status(* parse)(const parseinfo *pai, int cbyte, int max, void *store_r)