// NULL name will always match static DNSRR* DNSFindRR(DNSDG * pDNSDG, void * pRRCur, uint32_t rrr, uint16_t type, uint16_t _class, uint8_t * pName, uint8_t * pEnd) { uint8_t * pRR = DNSSkipToRRSection(pDNSDG, rrr, pEnd); uint32_t cRR = ((uint16_t *) &pDNSDG->dnsHdr.QDCOUNT)[rrr-DNSRRQD]; uint32_t cbDNSRR = (rrr == DNSRRQD) ? sizeof(DNSQRR) : sizeof(DNSRR); uint32_t i = 0; // if we have indexed in for(i=0; i<cRR && pRR < pEnd; i++) { DNSRR * pDNSRR = (DNSRR *) DNSSkipName(pRR, pEnd); // compare the names if( pRR >= (uint8_t *) pRRCur && pDNSRR->TYPE == type && pDNSRR->CLASS == _class && (pName == NULL || DNSCompareRRName((uint8_t *) pDNSDG, pName, pRR, pEnd))) { // we found a matching CName, so lets use the new CName and see if we find another CName return(pDNSRR); } pRR = ((uint8_t *) pDNSRR) + pDNSRR->RDLENGTH + cbDNSRR; } return(NULL); }
static DNSRR * DNSFindNSARR(DNSDG * pDNSDG, uint8_t * pName, uint8_t * pEnd, uint16_t dnsType) { DNSRR * pDNSRRNS = NULL; DNSRR * pDNSRRA = NULL; uint32_t i = 0; uint32_t cBestMatch = 0; DNSRR * pDNSRRABest = NULL; uint8_t * pRR = DNSSkipToRRSection(pDNSDG, DNSRRNS, pEnd); uint16_t rgLL[DNScLL]; uint32_t crgLL = DNSGetNameLabelList((uint8_t *) pDNSDG, pName, pEnd, 0, rgLL, DNScLL); if(crgLL == 0) { return(NULL); } // now walk all of the name servers looking for the best match for(i=0; i < pDNSDG->dnsHdr.NSCOUNT && ((uint8_t *) pDNSDG) <= pRR && pRR < pEnd; i++) { uint32_t cLabelMatches = 0; pDNSRRNS = (DNSRR *) DNSSkipName(pRR, pEnd); // see if this is a NS and that there is a dnsType in Additional records if(pDNSRRNS != NULL && pDNSRRNS->TYPE == DNSTYPENS && (pDNSRRA = DNSFindRR(pDNSDG, NULL, DNSRRAR, dnsType, DNSCLASSIN, pDNSRRNS->RDATA, pEnd)) != NULL) { // now lets see how well this name matches to what we are looking for cLabelMatches = DNSCompareLabelListAndName((uint8_t *) pDNSDG, pRR, pEnd, 0, rgLL, crgLL); if(cLabelMatches > cBestMatch || pDNSRRABest == NULL) { pDNSRRABest = pDNSRRA; } } pRR = ((uint8_t *) pDNSRRNS) + sizeof(DNSRR) + pDNSRRNS->RDLENGTH; } return(pDNSRRABest); }
return(NULL); } // skip up to the record in question for(i=0; i<cRRSkip && pRR < pEnd; i++) { pRR = DNSSkipRRecord(pRR, (i < pDNSDG->dnsHdr.QDCOUNT), pEnd); } return(pRR); } // NULL name will always match static DNSRR * DNSFindRR(DNSDG * pDNSDG, void * pRRCur, uint32_t rrr, uint16_t type, uint16_t class, uint8_t * pName, uint8_t * pEnd) { uint8_t * pRR = DNSSkipToRRSection(pDNSDG, rrr, pEnd); uint32_t cRR = ((uint16_t *) &pDNSDG->dnsHdr.QDCOUNT)[rrr-DNSRRQD]; uint32_t cbDNSRR = (rrr == DNSRRQD) ? sizeof(DNSQRR) : sizeof(DNSRR); int i = 0; // if we have indexed in for(i=0; i<cRR && pRR < pEnd; i++) { DNSRR * pDNSRR = (DNSRR *) DNSSkipName(pRR, pEnd); // compare the names if( pRR >= (uint8_t *) pRRCur && pDNSRR->TYPE == type && pDNSRR->CLASS == class && (pName == NULL || DNSCompareRRName((uint8_t *) pDNSDG, pName, pRR, pEnd))) {