//make import info into struct baseinfo void passer_dns_data(mbuf_type *mbuf) { uchar *buf = mbuf->buf; int num; int dlen = 0; uchar *tail = NULL; dnsheader *hdr = (dnsheader *) buf; mbuf->err = 1; num = ntohs(hdr->qdcount); if (num != 1) return; num = ntohs(hdr->ancount); if (num != 0) return; num = ntohs(hdr->nscount); if (num != 0) return ; num = ntohs(hdr->arcount); if (num > 1) //edns makes ar==1 return; mbuf->id = hdr->id; dlen = check_dns_name(buf + sizeof(dnsheader), &(mbuf->lowerdomain)); if (dlen < 0) { return; } mbuf->dlen = dlen; tail = mbuf->origindomain = buf + sizeof(dnsheader); if (dlen == 2) // root tail += 1; else tail += dlen; mbuf->qtype = ntohs(*(ushort *) tail); if (check_support_type(mbuf->qtype) == 0) mbuf->err = 0; return; }
//make import info into struct baseinfo struct baseinfo passer_dns_data(struct sockinfo *si) { uchar *buf = si->buf; int num; int i = 0,len = sizeof(struct sockaddr_in); int dlen = 0,seg = 0; struct baseinfo bi; uchar *tail = NULL,*ptrs[MAX_NS_LVL] = {0},*domain = NULL; ushort offset; dnsheader *hdr = (dnsheader*)buf; bi.err = 1; num = ntohs(hdr->qdcount); if(num != 1) return bi; num = ntohs(hdr->ancount); if(num != 0) return bi; num = ntohs(hdr->nscount); if(num != 0) return bi; num = ntohs(hdr->arcount); if(num > 1) //edns makes ar==1 return bi; bi.id = hdr->id; //if(check_client_addr() < 0) //return bi; dlen = check_dns_name(buf + sizeof(dnsheader),&seg); if(dlen < 0) return bi; bi.dlen = dlen; tail = bi.origindomain = buf + sizeof(dnsheader); tail += dlen; bi.type = ntohs(*(ushort*)tail); if(check_support_type(bi.type) == 0) bi.err = 0; return bi; }