From ae33cc6557790a502a01b380b0926944ca2f3cfa Mon Sep 17 00:00:00 2001 From: Miguel Date: Wed, 26 Sep 2018 10:22:37 +0200 Subject: ntp and udp --- net/ntp.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 net/ntp.c (limited to 'net/ntp.c') diff --git a/net/ntp.c b/net/ntp.c new file mode 100644 index 0000000..137d677 --- /dev/null +++ b/net/ntp.c @@ -0,0 +1,36 @@ +#include "udp.h" +#include "ntp.h" + +uint32_t ntp_generic(struct netdev *dev, uint32_t ip, uint16_t src, uint16_t dst, uint8_t* pos,uint8_t *end) +{ + pos-=48; // we need 48 bytes + struct udp_v4_ntp *ntp=pos; + + ntp->li_vn_mode=0x1b; // Eight bits. li, vn, and mode. + // li. Two bits. Leap indicator. + // vn. Three bits. Version number of the protocol. + // mode. Three bits. Client will pick mode 3 for client. + + ntp->stratum=0; // Eight bits. Stratum level of the local clock. + ntp->poll=0; // Eight bits. Maximum interval between successive messages. + ntp->precision=0; // Eight bits. Precision of the local clock. + + ntp->rootDelay=0; // 32 bits. Total round trip delay time. + ntp->rootDispersion=0; // 32 bits. Max error aloud from primary clock source. + ntp->refId=0; // 32 bits. Reference clock identifier. + + ntp->refTm_s=0; // 32 bits. Reference time-stamp seconds. + ntp->refTm_f=0; // 32 bits. Reference time-stamp fraction of a second. + + ntp->origTm_s=0; // 32 bits. Originate time-stamp seconds. + ntp->origTm_f=0; // 32 bits. Originate time-stamp fraction of a second. + + ntp->rxTm_s=0; // 32 bits. Received time-stamp seconds. + ntp->rxTm_f=0; // 32 bits. Received time-stamp fraction of a second. + + ntp->txTm_s=0; // 32 bits and the most important field the client cares about. Transmit time-stamp seconds. + ntp->txTm_f=0; // 32 bits. Transmit time-stamp fraction of a second. + + return udp_generic(dev, ip, src, dst, pos,end); +} + -- cgit v1.2.3