diff --git a/mongoose.c b/mongoose.c index 206b5b31..10beca39 100644 --- a/mongoose.c +++ b/mongoose.c @@ -3970,10 +3970,10 @@ void mg_sntp_request(struct mg_connection *c) { uint64_t now = mg_millis(); uint8_t buf[48] = {0}; uint32_t *t = (uint32_t *) &buf[40]; - double frac = ((double) (now % 1000)) / 1000.0; + double frac = ((double) (now % 1000)) / 1000.0 * SNTP_MAX_FRAC; buf[0] = (0 << 6) | (4 << 3) | 3; t[0] = mg_htonl((uint32_t) (now / 1000) + SNTP_TIME_OFFSET); - t[1] = mg_htonl((uint32_t) ((int32_t) (frac * SNTP_MAX_FRAC))); + t[1] = mg_htonl((uint32_t) frac); mg_send(c, buf, sizeof(buf)); } } diff --git a/src/sntp.c b/src/sntp.c index 4f4dff1b..a352622c 100644 --- a/src/sntp.c +++ b/src/sntp.c @@ -62,10 +62,10 @@ void mg_sntp_request(struct mg_connection *c) { uint64_t now = mg_millis(); uint8_t buf[48] = {0}; uint32_t *t = (uint32_t *) &buf[40]; - double frac = ((double) (now % 1000)) / 1000.0; + double frac = ((double) (now % 1000)) / 1000.0 * SNTP_MAX_FRAC; buf[0] = (0 << 6) | (4 << 3) | 3; t[0] = mg_htonl((uint32_t) (now / 1000) + SNTP_TIME_OFFSET); - t[1] = mg_htonl((uint32_t) ((int32_t) (frac * SNTP_MAX_FRAC))); + t[1] = mg_htonl((uint32_t) frac); mg_send(c, buf, sizeof(buf)); } }