diff --git a/src/containers.h b/src/containers.h index 58d0657..31eabea 100644 --- a/src/containers.h +++ b/src/containers.h @@ -6,9 +6,9 @@ #include #include +#include #include #include -#include #include #include "../uapi/wireguard.h" @@ -43,7 +43,7 @@ struct wgpeer { struct sockaddr_in6 addr6; } endpoint; - struct timeval last_handshake_time; + struct timespec last_handshake_time; uint64_t rx_bytes, tx_bytes; uint16_t persistent_keepalive_interval; diff --git a/src/ipc.c b/src/ipc.c index 2d24287..a88672f 100644 --- a/src/ipc.c +++ b/src/ipc.c @@ -427,7 +427,7 @@ static int userspace_get_device(struct wgdevice **out, const char *interface) } else if (peer && !strcmp(key, "last_handshake_time_sec")) peer->last_handshake_time.tv_sec = NUM(0xffffffffffffffffULL); else if (peer && !strcmp(key, "last_handshake_time_nsec")) - peer->last_handshake_time.tv_usec = NUM(0xffffffffffffffffULL) / 1000; + peer->last_handshake_time.tv_nsec = NUM(0xffffffffffffffffULL); else if (peer && !strcmp(key, "rx_bytes")) peer->rx_bytes = NUM(0xffffffffffffffffULL); else if (peer && !strcmp(key, "tx_bytes")) diff --git a/src/show.c b/src/show.c index 6ae5830..ebfdf5b 100644 --- a/src/show.c +++ b/src/show.c @@ -24,13 +24,13 @@ static int peer_cmp(const void *first, const void *second) time_t diff; const struct wgpeer *a = *(const void **)first, *b = *(const void **)second; - if (!a->last_handshake_time.tv_sec && !a->last_handshake_time.tv_usec && (b->last_handshake_time.tv_sec || b->last_handshake_time.tv_usec)) + if (!a->last_handshake_time.tv_sec && !a->last_handshake_time.tv_nsec && (b->last_handshake_time.tv_sec || b->last_handshake_time.tv_nsec)) return 1; - if (!b->last_handshake_time.tv_sec && !b->last_handshake_time.tv_usec && (a->last_handshake_time.tv_sec || a->last_handshake_time.tv_usec)) + if (!b->last_handshake_time.tv_sec && !b->last_handshake_time.tv_nsec && (a->last_handshake_time.tv_sec || a->last_handshake_time.tv_nsec)) return -1; diff = a->last_handshake_time.tv_sec - b->last_handshake_time.tv_sec; if (!diff) - diff = a->last_handshake_time.tv_usec - b->last_handshake_time.tv_usec; + diff = a->last_handshake_time.tv_nsec - b->last_handshake_time.tv_nsec; if (diff < 0) return 1; if (diff > 0) @@ -149,7 +149,7 @@ static size_t pretty_time(char *buf, const size_t len, unsigned long long left) return offset; } -static char *ago(const struct timeval *t) +static char *ago(const struct timespec *t) { static char buf[1024]; size_t offset;