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

Revision:
59:e0e556c8bd46
Parent:
58:d48c899e482f
--- a/udp/dns/dnshdr.cpp	Thu Dec 07 20:44:32 2017 +0000
+++ b/udp/dns/dnshdr.cpp	Thu Dec 14 20:55:40 2017 +0000
@@ -36,11 +36,13 @@
 
 char*    DnsHdrPacket;
 char*    DnsHdrData;
+int      DnsHdrDataLength;
 
-void DnsHdrSetup(void* pPacket)
+void DnsHdrSetup(void* pPacket, int lenPacket)
 {
     DnsHdrPacket = (char*)pPacket;
-    DnsHdrData = DnsHdrPacket + HEADER_LENGTH;
+    DnsHdrData = DnsHdrPacket + sizeof(header);
+    DnsHdrDataLength = lenPacket - sizeof(header);
 }
 
 void DnsHdrRead()
@@ -132,7 +134,7 @@
     //Get the questions
     for (int q = 0; q < DnsHdrQdcount; q++)
     {
-        if (p > DnsHdrData + 500)
+        if (p >= DnsHdrData + DnsHdrDataLength)
         {
             Log("   Questions have overrun the buffer\r\n");
             return;
@@ -155,7 +157,7 @@
     //Get the answers
     for (int a = 0; a < DnsHdrAncount; a++)
     {
-        if (p > DnsHdrData + 500) { Log("  Answers have overrun the buffer\r\n"); return; }
+        if (p >= DnsHdrData + DnsHdrDataLength) { Log("  Answers have overrun the buffer\r\n"); return; }
         
         char* pEncodedName = p;
         int nameLength = DnsNameLength(p);