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:
- 37:793b39683406
- Parent:
- 35:93c39d260a83
- Child:
- 43:bc028d5a6424
diff -r 900e24b27bfb -r 793b39683406 udp/dns/dnsreply.cpp --- a/udp/dns/dnsreply.cpp Mon Sep 25 07:09:32 2017 +0000 +++ b/udp/dns/dnsreply.cpp Wed Oct 04 07:51:02 2017 +0000 @@ -1,16 +1,17 @@ -#include "mbed.h" -#include "log.h" -#include "net.h" -#include "ip4.h" -#include "ip6.h" -#include "ar.h" -#include "nr.h" -#include "dns.h" -#include "dnshdr.h" -#include "dnsname.h" -#include "dhcp.h" +#include "mbed.h" +#include "log.h" +#include "net.h" +#include "action.h" +#include "ip4.h" +#include "ip6.h" +#include "ar.h" +#include "nr.h" +#include "dns.h" +#include "dnshdr.h" +#include "dnsname.h" +#include "dhcp.h" -#define DEBUG false +bool DnsReplyTrace = false; char DnsReplyRecordName[256]; uint32_t DnsReplyRecordNameAsIp4 = 0; @@ -30,7 +31,7 @@ int recordNameLength = DnsNameLength(p); if (!recordNameLength) { - if (DEBUG) LogTimeF("DnsReply scanRecord name length of zero\r\n"); + if (DnsReplyTrace) LogTimeF("DnsReply scanRecord name length of zero\r\n"); return -1; //failure } @@ -50,7 +51,7 @@ int recordNameLength = DnsNameLength(p); if (!recordNameLength) { - if (DEBUG) LogTimeF("DnsReply scanRecord name length of zero\r\n"); + if (DnsReplyTrace) LogTimeF("DnsReply scanRecord name length of zero\r\n"); return -1; //failure } @@ -93,7 +94,7 @@ return; } - DnsNameDecode (recordNameOffset, sizeof(DnsReplyRecordName), DnsReplyRecordName); + DnsNameDecodePtr(recordNameOffset, sizeof(DnsReplyRecordName), DnsReplyRecordName); DnsNameDecodeIp4(recordNameOffset, &DnsReplyRecordNameAsIp4); DnsNameDecodeIp6(recordNameOffset, DnsReplyRecordNameAsIp6); @@ -121,11 +122,11 @@ LogTimeF("DnsReply PTR type length %d is greater than max DNS label length of %d\r\n", recordDataLength, DNS_MAX_LABEL_LENGTH); return; } - DnsNameDecode(DnsNameIndexFromPointer(pRecordData), sizeof(DnsReplyName), DnsReplyName); + DnsNameDecodePtr(DnsNameIndexFromPointer(pRecordData), sizeof(DnsReplyName), DnsReplyName); break; } - if (DEBUG) + if (DnsReplyTrace) { LogF(" answer: %s", DnsReplyRecordName); char text[100]; @@ -172,10 +173,15 @@ if (DnsReplyRecordNameAsIp4 && DnsReplyName[0] ) NrAddIp4Record(DnsReplyRecordNameAsIp4, strippedName, dnsProtocol); if (DnsReplyRecordNameAsIp6[0] && DnsReplyName[0] ) NrAddIp6Record(DnsReplyRecordNameAsIp6, strippedName, dnsProtocol); } -int DnsReplyHandle(int dnsProtocol, int *pSize) +int DnsReplyHandle(void (*traceback)(void), int dnsProtocol, int *pSize) { if (!DnsHdrAncount) return DO_NOTHING; - if (DEBUG) DnsHdrLog("received reply", dnsProtocol); + if (DnsReplyTrace) + { + LogTimeF("DNS received reply\r\n"); + if (NetTraceBack) traceback(); + DnsHdrLog(dnsProtocol); + } p = DnsHdrData;