#include "udp.h" #include "inet.h" #include "net_sys.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); } uint32_t ntp_incoming(uint8_t* start, uint8_t *pos) { struct udp_v4_ntp *ntp=pos; klog("0x%08X",ntohl(ntp->txTm_s)); // timestamp recevived klog("google's NTP says that %d seconds elapsed since 1 jan 1970",ntohl(ntp->txTm_s)); // timestamp recevived return 0; // all ok }