- if (!qdcount) {
- adns__diag(ads,serv,0,"server sent reply without quoting our question");
- return;
- } else if (qdcount>1) {
- adns__diag(ads,serv,0,"server claimed to answer %d questions with one message",
- qdcount);
- return;
- }
- for (qu= ads->timew.head; qu; qu= nqu) {
- nqu= qu->next;
- if (qu->id != id) continue;
- if (dglen < qu->query_dglen) continue;
- if (memcmp(qu->query_dgram+DNS_HDRSIZE,
- dgram+DNS_HDRSIZE,
- qu->query_dglen-DNS_HDRSIZE))
- continue;
- break;
- }
- if (!qu) {
- if (ads->iflags & adns_if_debug) {
- adns__vbuf_init(&tempvb);
- adns__debug(ads,serv,0,"reply not found, id %02x, query owner %s",
- id, adns__diag_domain(ads,serv,0,&tempvb,dgram,dglen,DNS_HDRSIZE));
- adns__vbuf_free(&tempvb);
+
+ qu= 0;
+ /* See if we can find the relevant query, or leave qu=0 otherwise ... */
+
+ if (qdcount == 1) {
+ for (qu= viatcp ? ads->tcpw.head : ads->udpw.head; qu; qu= nqu) {
+ nqu= qu->next;
+ if (qu->id != id) continue;
+ if (dglen < qu->query_dglen) continue;
+ if (memcmp(qu->query_dgram+DNS_HDRSIZE,
+ dgram+DNS_HDRSIZE,
+ qu->query_dglen-DNS_HDRSIZE))
+ continue;
+ if (viatcp) {
+ assert(qu->state == query_tcpw);
+ } else {
+ assert(qu->state == query_tosend);
+ if (!(qu->udpsent & (1<<serv))) continue;
+ }
+ break;
+ }
+ if (qu) {
+ /* We're definitely going to do something with this query now */
+ if (viatcp) LIST_UNLINK(ads->tcpw,qu);
+ else LIST_UNLINK(ads->udpw,qu);