From 9f4bd58bc9f2606421d0fcccc9e0f7f0360728b8 Mon Sep 17 00:00:00 2001 From: Pecius Date: Tue, 29 Nov 2022 22:24:06 +0100 Subject: [PATCH] Change TAI64N timestamp source to gettimeofday --- src/wireguard-platform.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/wireguard-platform.c b/src/wireguard-platform.c index 01131a3..91a829f 100644 --- a/src/wireguard-platform.c +++ b/src/wireguard-platform.c @@ -1,6 +1,7 @@ #include "wireguard-platform.h" #include +#include #include #include #include @@ -73,11 +74,11 @@ void wireguard_tai64n_now(uint8_t *output) { // 64 bit seconds from 1970 = 8 bytes // 32 bit nano seconds from current second - uint64_t millis = sys_now(); + struct timeval tv; + gettimeofday(&tv, NULL); - // Split into seconds offset + nanos - uint64_t seconds = 0x400000000000000aULL + (millis / 1000); - uint32_t nanos = (millis % 1000) * 1000; + uint64_t seconds = 0x400000000000000aULL + tv.tv_sec; + uint32_t nanos = tv.tv_usec * 1000; U64TO8_BIG(output + 0, seconds); U32TO8_BIG(output + 8, nanos); }