A stack which works with or without an Mbed os library. Provides IPv4 or IPv6 with a full 1500 byte buffer.
Dependents: oldheating gps motorhome heating
Diff: udp/dns/dnsreply.cpp
- Revision:
- 43:bc028d5a6424
- Parent:
- 37:793b39683406
- Child:
- 48:952dddb74b8b
diff -r 222a4f45f916 -r bc028d5a6424 udp/dns/dnsreply.cpp --- a/udp/dns/dnsreply.cpp Sun Oct 15 17:54:09 2017 +0000 +++ b/udp/dns/dnsreply.cpp Thu Oct 19 20:56:58 2017 +0000 @@ -29,11 +29,7 @@ static int scanQuery() { int recordNameLength = DnsNameLength(p); - if (!recordNameLength) - { - if (DnsReplyTrace) LogTimeF("DnsReply scanRecord name length of zero\r\n"); - return -1; //failure - } + if (!recordNameLength) return -1; //failure recordNameOffset = DnsNameIndexFromPointer(p); p += recordNameLength; @@ -49,11 +45,7 @@ static int scanAnswer() { int recordNameLength = DnsNameLength(p); - if (!recordNameLength) - { - if (DnsReplyTrace) LogTimeF("DnsReply scanRecord name length of zero\r\n"); - return -1; //failure - } + if (!recordNameLength) return -1; //failure recordNameOffset = DnsNameIndexFromPointer(p); p += recordNameLength; @@ -89,8 +81,7 @@ case DNS_RECORD_SRV: case DNS_RECORD_TXT: break; - default: - LogTimeF("DnsReply readAnswer unrecognised record type %d\r\n", recordType); + default: return; } @@ -101,65 +92,18 @@ switch (recordType) { case DNS_RECORD_A: - if (recordDataLength != 4) - { - LogTimeF("DnsReply A type length of %d\r\n", recordDataLength); - return; - } + if (recordDataLength != 4) return; memcpy(&DnsReplyIp4, pRecordData, 4); break; case DNS_RECORD_AAAA: - if (recordDataLength != 16) - { - LogTimeF("DnsReply AAAA type length of %d\r\n", recordDataLength); - return; - } + if (recordDataLength != 16) return; memcpy(DnsReplyIp6, pRecordData, 16); break; case DNS_RECORD_PTR: - if (recordDataLength > DNS_MAX_LABEL_LENGTH) - { - LogTimeF("DnsReply PTR type length %d is greater than max DNS label length of %d\r\n", recordDataLength, DNS_MAX_LABEL_LENGTH); - return; - } + if (recordDataLength > DNS_MAX_LABEL_LENGTH) return; DnsNameDecodePtr(DnsNameIndexFromPointer(pRecordData), sizeof(DnsReplyName), DnsReplyName); break; } - - if (DnsReplyTrace) - { - LogF(" answer: %s", DnsReplyRecordName); - char text[100]; - if (DnsReplyRecordNameAsIp4) - { - Ip4AddressToString(DnsReplyRecordNameAsIp4, sizeof(text), text); - LogF(" (%s)", text); - } - if (DnsReplyRecordNameAsIp6[0]) - { - Ip6AddressToString(DnsReplyRecordNameAsIp6, sizeof(text), text); - LogF(" (%s)", text); - } - LogF(" == "); - switch (recordType) - { - case DNS_RECORD_A: - Ip4AddressToString(DnsReplyIp4, sizeof(text), text); - LogF("%s\r\n", text); - break; - case DNS_RECORD_AAAA: - Ip6AddressToString(DnsReplyIp6, sizeof(text), text); - LogF("%s\r\n", text); - break; - case DNS_RECORD_PTR: - LogF("%s\r\n", DnsReplyName); - break; - default: - DnsRecordTypeToString(recordType, sizeof(text), text); - LogF("%d bytes of %s\r\n", recordDataLength, text); - break; - } - } } static void sendToDnsCache(int dnsProtocol) @@ -178,8 +122,9 @@ if (!DnsHdrAncount) return DO_NOTHING; if (DnsReplyTrace) { - LogTimeF("DNS received reply\r\n"); - if (NetTraceBack) traceback(); + if (NetTraceNewLine) Log("\r\n"); + LogTimeF("DnsReply received\r\n"); + if (NetTraceStack) traceback(); DnsHdrLog(dnsProtocol); }