NTP reponse gives fractional (not micro-) seconds, per RFC5905

This commit is contained in:
John Brzustowski committed 2022-07-13 04:08:54 -03:00
1 parent 3f46ae7beb
commit d5fe3261f4
2 files changed
+4 -4

No files matched your search

+2 -2
View File
@@ -3797,8 +3797,8 @@ int64_t mg_sntp_parse(const unsigned char *buf, size_t len) {
} else if (version == 4 || version == 3) {
uint32_t *data = (uint32_t *) &buf[40];
unsigned long seconds = mg_ntohl(data[0]) - SNTP_TIME_OFFSET;
unsigned long useconds = mg_ntohl(data[1]);
res = ((int64_t) seconds) * 1000 + (int64_t) ((useconds / 1000) % 1000);
unsigned long fracseconds = mg_ntohl(data[1]);
res = ((int64_t) seconds) * 1000 + (((int64_t) (fracseconds) * 1000) >> 32);
} else {
MG_ERROR(("unexpected version: %d", version));
}
+2 -2
View File
@@ -20,8 +20,8 @@ int64_t mg_sntp_parse(const unsigned char *buf, size_t len) {
} else if (version == 4 || version == 3) {
uint32_t *data = (uint32_t *) &buf[40];
unsigned long seconds = mg_ntohl(data[0]) - SNTP_TIME_OFFSET;
unsigned long useconds = mg_ntohl(data[1]);
res = ((int64_t) seconds) * 1000 + (int64_t) ((useconds / 1000) % 1000);
unsigned long fracseconds = mg_ntohl(data[1]);
res = ((int64_t) seconds) * 1000 + (((int64_t) (fracseconds) * 1000) >> 32);
} else {
MG_ERROR(("unexpected version: %d", version));
}