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:
138:5ff0c7069300
Parent:
133:a37eb35a03f1
Child:
139:1f3641abc07f
--- a/udp/ntp/ntpclientquery.c	Sun Apr 07 11:05:16 2019 +0000
+++ b/udp/ntp/ntpclientquery.c	Sun Apr 07 18:36:42 2019 +0000
@@ -12,6 +12,7 @@
 #include "clktm.h"
 #include "net.h"
 #include "ntp.h"
+#include "ntphdr.h"
 #include "ntpclient.h"
 #include "dns.h"
 #include "ip4.h"
@@ -50,31 +51,30 @@
     intervalTypeNtp = type;
 }
 
-void writeRequest(void* pPacket, int* pSize)
-{
-    struct NtpHeader* pHeader = (struct NtpHeader*)pPacket;
-    
-    pHeader->Mode             = NTP_CLIENT;
-    pHeader->VN               = 3;
-    pHeader->LI               = 0;
-    pHeader->Stratum          = 0;
-    pHeader->Poll             = 0;
-    pHeader->Precision        = 0;
-    pHeader->RootDelay        = 0;
-    pHeader->Dispersion       = 0;
-    pHeader->RefIdentifier[0] = 0;
-    pHeader->RefIdentifier[1] = 0;
-    pHeader->RefIdentifier[2] = 0;
-    pHeader->RefIdentifier[3] = 0;
-    pHeader->RefTimeStamp     = 0;
-    pHeader->OriTimeStamp     = 0;
-    pHeader->RecTimeStamp     = 0;
-    pHeader->TraTimeStamp     = NetToHost64(NtpTimeStampFromClkTime(ClkTimeGet())); //use the costly time this instant
+void writeRequest(char* pPacket, int* pSize)
+{   
+    NtpHdrSetMode(pPacket, NTP_CLIENT);
+    NtpHdrSetVersion     (pPacket, 3);
+    NtpHdrSetLI          (pPacket, 0);
+    NtpHdrSetStratum     (pPacket, 0);
+    NtpHdrSetPoll        (pPacket, 0);
+    NtpHdrSetPrecision   (pPacket, 0);
+    NtpHdrSetRootDelay   (pPacket, 0);
+    NtpHdrSetDispersion  (pPacket, 0);
+    char* p = NtpHdrPtrRefIdentifier(pPacket);
+    *p++ = 0;
+    *p++ = 0;
+    *p++ = 0;
+    *p   = 0;
+    NtpHdrSetRefTimeStamp(pPacket, 0);
+    NtpHdrSetOriTimeStamp(pPacket, 0);
+    NtpHdrSetRecTimeStamp(pPacket, 0);
+    NtpHdrSetTraTimeStamp(pPacket, NtpTimeStampFromClkTime(ClkTimeGet())); //use the costly time this instant
 
-    *pSize = sizeof(struct NtpHeader);
+    *pSize = NTP_HEADER_LENGTH;
 }
 
-int NtpClientQueryPoll(int type, void* pPacket, int* pSize)
+int NtpClientQueryPoll(int type, char* pPacket, int* pSize)
 {
     if (NtpClientQueryServerName[0]) //An empty name means ntp client is not enabled
     {