From 713153b610a4e8a1ed640202d78a179c0e9e41bb Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Mon, 18 Aug 2014 14:52:07 +0200 Subject: [PATCH] util: update functions converting cmdmon timestamps --- util.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/util.c b/util.c index e1d314e..5fecd25 100644 --- a/util.c +++ b/util.c @@ -556,15 +556,14 @@ UTI_TimevalNetworkToHost(Timeval *src, struct timeval *dest) sec_high = ntohl(src->tv_sec_high); sec_low = ntohl(src->tv_sec_low); - /* get the missing bits from current time when received timestamp - is only 32-bit */ - if (sizeof (time_t) > 4 && sec_high == TV_NOHIGHSEC) { - struct timeval now; +#ifdef HAVE_LONG_TIME_T + if (sec_high == TV_NOHIGHSEC) + sec_high = 0; - gettimeofday(&now, NULL); - sec_high = now.tv_sec >> 16 >> 16; - } - dest->tv_sec = (time_t)sec_high << 16 << 16 | sec_low; + dest->tv_sec = (uint64_t)sec_high << 32 | sec_low; +#else + dest->tv_sec = sec_low; +#endif } /* ================================================== */ @@ -573,10 +572,11 @@ void UTI_TimevalHostToNetwork(struct timeval *src, Timeval *dest) { dest->tv_nsec = htonl(src->tv_usec * 1000); - if (sizeof (time_t) > 4) - dest->tv_sec_high = htonl(src->tv_sec >> 16 >> 16); - else - dest->tv_sec_high = htonl(TV_NOHIGHSEC); +#ifdef HAVE_LONG_TIME_T + dest->tv_sec_high = htonl((uint64_t)src->tv_sec >> 32); +#else + dest->tv_sec_high = htonl(TV_NOHIGHSEC); +#endif dest->tv_sec_low = htonl(src->tv_sec); }