Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: oldheating gps motorhome heating
Diff: udp/dns/dnsserver.cpp
- Revision:
- 33:714a0345e59b
- Parent:
- 32:679654f2d023
- Child:
- 36:900e24b27bfb
--- a/udp/dns/dnsserver.cpp Thu Aug 17 14:21:02 2017 +0000 +++ b/udp/dns/dnsserver.cpp Wed Aug 23 18:02:42 2017 +0000 @@ -17,8 +17,8 @@ //Set by readQuestions and used by answerQuestions int questionTypes[4]; +int nodeNameTypes[4]; bool mdnsUnicastReply; -int nodeNameType; static int initialise(int dnsProtocol, int size) { @@ -34,22 +34,18 @@ static int readQuestions() { char iEncodedName; - nodeNameType = DNS_RECORD_NONE; mdnsUnicastReply = false; //Get the questions - DnsHdrAncount = 0; for (int q = 0; q < DnsHdrQdcount; q++) { iEncodedName = DnsNameIndexFromPointer(p); int nameLength = DnsNameLength(p); if (!nameLength) return DO_NOTHING; - if (!q) - { - if (!nodeNameType && DnsNameCompare (p, fullname) ) nodeNameType = DNS_RECORD_PTR; //rtc.local - if (!nodeNameType && DnsNameCompareIp4(p, DhcpLocalIp) ) nodeNameType = DNS_RECORD_A; //3.1.168.192.inaddr.arpa - if (!nodeNameType && DnsNameCompareIp6(p, SlaacLinkLocalIp)) nodeNameType = DNS_RECORD_AAAA; //5.8.c.c.0.1.e.f.f.f.2.3.1.1.2.0.8.7.d.0.9.0.f.1.0.7.4.0.1.0.0.2.ip6.arpa - } + nodeNameTypes[q] = DNS_RECORD_NONE; + if (!nodeNameTypes[q] && DnsNameCompare (p, fullname) ) nodeNameTypes[q] = DNS_RECORD_PTR; //rtc.local + if (!nodeNameTypes[q] && DnsNameCompareIp4(p, DhcpLocalIp) ) nodeNameTypes[q] = DNS_RECORD_A; //3.1.168.192.inaddr.arpa + if (!nodeNameTypes[q] && DnsNameCompareIp6(p, SlaacLinkLocalIp)) nodeNameTypes[q] = DNS_RECORD_AAAA; //5.8.c.c.0.1.e.f.f.f.2.3.1.1.2.0.8.7.d.0.9.0.f.1.0.7.4.0.1.0.0.2.ip6.arpa p += nameLength; //Skip past the name p++ ; //skip the first byte of the type char recordType = *p++; //read the record type @@ -76,6 +72,7 @@ } static int addAnswers(int dnsProtocol) { + DnsHdrAncount = 0; for (int q = 0; q < DnsHdrQdcount; q++) { //Skip unwanted record types @@ -83,8 +80,10 @@ { case DNS_RECORD_A: case DNS_RECORD_AAAA: - case DNS_RECORD_PTR: continue; + case DNS_RECORD_PTR: break; + default: continue; } + if (!nodeNameTypes[q]) continue; //Skip queries which are not addressed to me if (p - DnsHdrPacket > 500) { LogTimeF("DnsServer-addAnswers Ip4 query reply is getting too big\r\n"); @@ -108,8 +107,8 @@ break; case DNS_RECORD_PTR: - if (nodeNameType == DNS_RECORD_A ) DnsNameEncodeIp4(DhcpLocalIp, &p); - if (nodeNameType == DNS_RECORD_AAAA) DnsNameEncodeIp6(SlaacLinkLocalIp, &p); + if (nodeNameTypes[q] == DNS_RECORD_A ) DnsNameEncodeIp4(DhcpLocalIp, &p); + if (nodeNameTypes[q] == DNS_RECORD_AAAA) DnsNameEncodeIp6(SlaacLinkLocalIp, &p); lenPayload = fullnamelength; pPayload = fullname; break; @@ -132,7 +131,6 @@ if (initialise(dnsProtocol, *pSize)) return DO_NOTHING; if (readQuestions() ) return DO_NOTHING; - if (!nodeNameType) return DO_NOTHING; if (addAnswers(dnsProtocol) ) return DO_NOTHING; if (!DnsHdrAncount) return DO_NOTHING;