sntp change
This commit is contained in:
@ -24,7 +24,7 @@ extern const uint8_t SNTP_SOCK;
|
|||||||
|
|
||||||
|
|
||||||
const uint8_t SEND_LI_VN_MODE = 0xe3; // LI: unknown (3), VN: 4, Mode: Client (3)
|
const uint8_t SEND_LI_VN_MODE = 0xe3; // LI: unknown (3), VN: 4, Mode: Client (3)
|
||||||
typedef struct {
|
typedef struct __attribute__((__packed__)) {
|
||||||
uint8_t li_vn_mode;
|
uint8_t li_vn_mode;
|
||||||
uint8_t stratum;
|
uint8_t stratum;
|
||||||
uint8_t poll;
|
uint8_t poll;
|
||||||
@ -32,10 +32,18 @@ typedef struct {
|
|||||||
uint32_t rootdelay;
|
uint32_t rootdelay;
|
||||||
uint32_t rootdisp;
|
uint32_t rootdisp;
|
||||||
uint32_t refid;
|
uint32_t refid;
|
||||||
uint64_t reftime;
|
//uint64_t reftime;
|
||||||
uint64_t org;
|
uint32_t reftime_h;
|
||||||
uint64_t rec;
|
uint32_t reftime_l;
|
||||||
uint64_t xmt;
|
//uint64_t org;
|
||||||
|
uint32_t org_h;
|
||||||
|
uint32_t org_l;
|
||||||
|
//uint64_t rec;
|
||||||
|
uint32_t rec_h;
|
||||||
|
uint32_t rec_l;
|
||||||
|
//uint64_t xmt;
|
||||||
|
uint32_t xmt_h;
|
||||||
|
uint32_t xmt_l;
|
||||||
} ntpMsg_t;
|
} ntpMsg_t;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
@ -108,11 +116,11 @@ void networkSntpEngine(void *handle) {
|
|||||||
memset(&(localHandle->ntpMsg), 0, sizeof(localHandle->ntpMsg));
|
memset(&(localHandle->ntpMsg), 0, sizeof(localHandle->ntpMsg));
|
||||||
uint8_t srcAddr[4];
|
uint8_t srcAddr[4];
|
||||||
uint16_t srcPort;
|
uint16_t srcPort;
|
||||||
/*
|
|
||||||
recvfrom(SNTP_SOCK, (uint8_t*)(&(localHandle->ntpMsg)),
|
recvfrom(SNTP_SOCK, (uint8_t*)(&(localHandle->ntpMsg)),
|
||||||
sizeof(localHandle->ntpMsg), srcAddr, &srcPort);
|
sizeof(localHandle->ntpMsg), srcAddr, &srcPort);
|
||||||
*/
|
|
||||||
|
|
||||||
|
/*
|
||||||
uint8_t buf[90];
|
uint8_t buf[90];
|
||||||
memset(buf, 0, sizeof(buf));
|
memset(buf, 0, sizeof(buf));
|
||||||
recvfrom(SNTP_SOCK, buf, sizeof(buf), srcAddr, &srcPort);
|
recvfrom(SNTP_SOCK, buf, sizeof(buf), srcAddr, &srcPort);
|
||||||
@ -132,19 +140,14 @@ void networkSntpEngine(void *handle) {
|
|||||||
coloredMsg(LOG_BLUE, "%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x",
|
coloredMsg(LOG_BLUE, "%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x",
|
||||||
buf[x+0], buf[x+1], buf[x+2], buf[x+3], buf[x+4], buf[x+5], buf[x+6], buf[x+7],
|
buf[x+0], buf[x+1], buf[x+2], buf[x+3], buf[x+4], buf[x+5], buf[x+6], buf[x+7],
|
||||||
buf[x+8], buf[x+9], buf[x+10], buf[x+11], buf[x+12], buf[x+13], buf[x+14], buf[x+15]);
|
buf[x+8], buf[x+9], buf[x+10], buf[x+11], buf[x+12], buf[x+13], buf[x+14], buf[x+15]);
|
||||||
|
*/
|
||||||
|
|
||||||
close(SNTP_SOCK);
|
close(SNTP_SOCK);
|
||||||
coloredMsg(LOG_BLUE, "nes, msg received from %d.%d.%d.%d:%d",
|
coloredMsg(LOG_BLUE, "nes, msg received from %d.%d.%d.%d:%d",
|
||||||
srcAddr[0], srcAddr[1], srcAddr[2], srcAddr[3],
|
srcAddr[0], srcAddr[1], srcAddr[2], srcAddr[3],
|
||||||
srcPort);
|
srcPort);
|
||||||
coloredMsg(LOG_BLUE, "nes, received in the %d. cycles", localHandle->retryCount);
|
coloredMsg(LOG_BLUE, "nes, received in the %d. cycles", localHandle->retryCount);
|
||||||
uint32_t xmtTopHalf = (localHandle->ntpMsg.xmt >> 32) & 0x0ffffffff;
|
localHandle->seconds = localHandle->ntpMsg.xmt_h - UNIX_NTP_EPOCH_DIFF;
|
||||||
uint32_t rawSeconds =
|
|
||||||
(xmtTopHalf & 0x0000000ff) << 24 |
|
|
||||||
(xmtTopHalf & 0x00000ff00) << 8 |
|
|
||||||
(xmtTopHalf & 0x000ff0000) >> 8 |
|
|
||||||
(xmtTopHalf & 0x0ff000000) >> 24;
|
|
||||||
localHandle->seconds = rawSeconds - UNIX_NTP_EPOCH_DIFF;
|
|
||||||
coloredMsg(LOG_BLUE, "nes, seconds: %lu", localHandle->seconds);
|
coloredMsg(LOG_BLUE, "nes, seconds: %lu", localHandle->seconds);
|
||||||
localHandle->sntpState = SNTP_STATE_DONE;
|
localHandle->sntpState = SNTP_STATE_DONE;
|
||||||
} else {
|
} else {
|
||||||
|
Reference in New Issue
Block a user