Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: oldheating gps motorhome heating
Diff: udp/ntp/ntpserver.c
- Revision:
- 138:5ff0c7069300
- Parent:
- 134:3aa1bc602b19
--- a/udp/ntp/ntpserver.c Sun Apr 07 11:05:16 2019 +0000
+++ b/udp/ntp/ntpserver.c Sun Apr 07 18:36:42 2019 +0000
@@ -7,6 +7,7 @@
#include "clkutc.h"
#include "ntptimestamp.h"
#include "ntp.h"
+#include "ntphdr.h"
#include "action.h"
#include "log.h"
#include "net.h"
@@ -62,7 +63,7 @@
{
return NtpTimeStampFromClkTime(ClkRefTai());
}
-int NtpServerRequest(void (*traceback)(void), struct NtpHeader* pHeaderRx, struct NtpHeader* pHeaderTx)
+int NtpServerRequest(void (*traceback)(void), char* pPacketRx, char* pPacketTx)
{
if (!NtpServerEnable) return DO_NOTHING;
@@ -71,7 +72,7 @@
if (NetTraceNewLine) Log("\r\n");
LogTimeF("NTP received request\r\n");
if (NetTraceStack) traceback();
- NtpLogHeader(pHeaderRx);
+ NtpLogHeader(pPacketRx);
}
uint64_t refNtp = getRefNtp();
@@ -81,24 +82,25 @@
int li = getLi();
int precision = getPrecision();
- pHeaderTx->Mode = NTP_SERVER;
- pHeaderTx->VN = pHeaderRx->VN;
- pHeaderTx->LI = li;
- pHeaderTx->Stratum = stratum;
- pHeaderTx->Poll = pHeaderRx->Poll;
- pHeaderTx->Precision = precision;
- pHeaderTx->RootDelay = 0;
- pHeaderTx->Dispersion = 0;
- pHeaderTx->RefIdentifier[0] = ident[0]; //For stratum 1 (reference clock), this is a four-octet, left-justified, zero-padded ASCII string.
- pHeaderTx->RefIdentifier[1] = ident[1];
- pHeaderTx->RefIdentifier[2] = ident[2];
- pHeaderTx->RefIdentifier[3] = ident[3];
- pHeaderTx->RefTimeStamp = NetToHost64(refNtp);
- pHeaderTx->OriTimeStamp = pHeaderRx->TraTimeStamp;
- pHeaderTx->RecTimeStamp = NetToHost64(nowNtp);
- pHeaderTx->TraTimeStamp = NetToHost64(nowNtp);
+ NtpHdrSetMode (pPacketTx, NTP_SERVER);
+ NtpHdrSetVersion (pPacketTx, NtpHdrGetVersion(pPacketRx));
+ NtpHdrSetLI (pPacketTx, li);
+ NtpHdrSetStratum (pPacketTx, stratum);
+ NtpHdrSetPoll (pPacketTx, NtpHdrGetPoll(pPacketRx));
+ NtpHdrSetPrecision (pPacketTx, precision);
+ NtpHdrSetRootDelay (pPacketTx, 0);
+ NtpHdrSetDispersion (pPacketTx, 0);
+ char* p = NtpHdrPtrRefIdentifier(pPacketTx);
+ *p++ = ident[0]; //For stratum 1 (reference clock), this is a four-octet, left-justified, zero-padded ASCII string.
+ *p++ = ident[1];
+ *p++ = ident[2];
+ *p = ident[3];
+ NtpHdrSetRefTimeStamp(pPacketTx, refNtp);
+ NtpHdrSetOriTimeStamp(pPacketTx, NtpHdrGetTraTimeStamp(pPacketRx));
+ NtpHdrSetRecTimeStamp(pPacketTx, nowNtp);
+ NtpHdrSetTraTimeStamp(pPacketTx, nowNtp);
- if (NtpTrace) NtpLogHeader(pHeaderTx);
+ if (NtpTrace) NtpLogHeader(pPacketTx);
return UNICAST;
}