mirror of
https://github.com/cesanta/mongoose.git
synced 2026-10-16 10:39:49 +00:00
Use time.windows.com too
This commit is contained in:
1 parent
2ae341cf5e
commit
7f8d12b9f7
3 files changed
+20
-15
No files matched your search
+5
-4
@@ -10,21 +10,22 @@
|
||||
int64_t mg_sntp_parse(const unsigned char *buf, size_t len) {
|
||||
int64_t res = -1;
|
||||
int mode = len > 0 ? buf[0] & 7 : 0;
|
||||
int version = len > 0 ? (buf[0] >> 3) & 7 : 0;
|
||||
if (len < 48) {
|
||||
MG_ERROR(("%s", "corrupt packet"));
|
||||
} else if ((buf[0] & 0x38) >> 3 != 4) {
|
||||
MG_ERROR(("%s", "wrong version"));
|
||||
} else if (mode != 4 && mode != 5) {
|
||||
MG_ERROR(("%s", "not a server reply"));
|
||||
} else if (buf[1] == 0) {
|
||||
MG_ERROR(("%s", "server sent a kiss of death"));
|
||||
} else {
|
||||
} 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]);
|
||||
// MG_DEBUG(("%lu %lu %lu", time(0), seconds, useconds));
|
||||
res = ((int64_t) seconds) * 1000 + (int64_t) ((useconds / 1000) % 1000);
|
||||
} else {
|
||||
MG_ERROR(("unexpected version: %d", version));
|
||||
}
|
||||
if (res == -1) mg_hexdump(buf, len);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user