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:
93:580fc113d9e9
Parent:
66:18a10c0b6d93
Child:
128:79052cb4a41c
--- a/udp/dns/dnsquery.c	Thu Nov 29 16:52:10 2018 +0000
+++ b/udp/dns/dnsquery.c	Sun Dec 02 18:40:35 2018 +0000
@@ -2,7 +2,7 @@
 #include <stdbool.h>
 
 #include     "log.h"
-#include   "clock.h"
+#include "mstimer.h"
 #include     "net.h"
 #include  "action.h"
 #include "ip4addr.h"
@@ -16,7 +16,7 @@
 
 bool DnsQueryTrace = false;
 
-#define TIME_OUT_SENT 3
+#define TIME_OUT_SENT_MS 3000
 
 #define MDNS_UNICAST false
 
@@ -28,13 +28,12 @@
 int      DnsQueryProtocol   = DNS_PROTOCOL_NONE;
 bool     DnsQueryIsBusy     = false;
 
-static uint32_t started = 0;
-static uint32_t elapsed = 0;
+static uint32_t startedMs = 0;
 static void reap()
 {
     if (!DnsQueryIsBusy) return;
     
-    if (elapsed - started >= TIME_OUT_SENT)
+    if (MsTimerHasElapsed(startedMs, TIME_OUT_SENT_MS))
     {
         LogTimeF("DNS reaped ongoing request for ");
         if (DnsQueryName[0]) LogF("name %s", DnsQueryName);
@@ -52,18 +51,14 @@
         DnsQueryIp4        = 0;
         DnsQueryIp6[0]     = 0;
         DnsQueryIsBusy     = false;
-        started            = 0;
+        startedMs          = MsTimerCount;
         DnsQueryProtocol   = DNS_PROTOCOL_NONE;
         DnsQueryRecordType = DNS_RECORD_NONE;
     }
 }
 void DnsQueryMain()
 {
-    if (ClockTicked)
-    {
-        elapsed++;
-        reap();
-    }
+    reap();
 }
 void DnsQueryIp4FromName(char * name, int protocol)
 {
@@ -71,7 +66,7 @@
     DnsQueryIp4        = 0;
     DnsQueryIp6[0]     = 0;
     DnsQueryIsBusy     = true;
-    started            = elapsed;
+    startedMs          = MsTimerCount;
     DnsQueryProtocol   = protocol;
     DnsQueryRecordType = DNS_RECORD_A;
 }
@@ -81,7 +76,7 @@
     DnsQueryIp4        = 0;
     DnsQueryIp6[0]     = 0;
     DnsQueryIsBusy     = true;
-    started            = elapsed;
+    startedMs          = MsTimerCount;
     DnsQueryProtocol   = protocol;
     DnsQueryRecordType = DNS_RECORD_AAAA;
 }
@@ -91,7 +86,7 @@
     DnsQueryIp4        = ip;
     DnsQueryIp6[0]     = 0;
     DnsQueryIsBusy     = true;
-    started            = elapsed;
+    startedMs          = MsTimerCount;
     DnsQueryProtocol   = protocol;
     DnsQueryRecordType = DNS_RECORD_PTR;
 }
@@ -101,7 +96,7 @@
     DnsQueryIp4        = 0;
     Ip6AddressCopy(DnsQueryIp6, ip);
     DnsQueryIsBusy     = true;
-    started            = elapsed;
+    startedMs          = MsTimerCount;
     DnsQueryProtocol   = protocol;
     DnsQueryRecordType = DNS_RECORD_PTR;
 }