util: update functions converting cmdmon timestamps

This commit is contained in:
Miroslav Lichvar 2014-08-18 14:52:07 +02:00
parent 09d039fba6
commit 713153b610

22
util.c
View file

@ -556,15 +556,14 @@ UTI_TimevalNetworkToHost(Timeval *src, struct timeval *dest)
sec_high = ntohl(src->tv_sec_high); sec_high = ntohl(src->tv_sec_high);
sec_low = ntohl(src->tv_sec_low); sec_low = ntohl(src->tv_sec_low);
/* get the missing bits from current time when received timestamp #ifdef HAVE_LONG_TIME_T
is only 32-bit */ if (sec_high == TV_NOHIGHSEC)
if (sizeof (time_t) > 4 && sec_high == TV_NOHIGHSEC) { sec_high = 0;
struct timeval now;
gettimeofday(&now, NULL); dest->tv_sec = (uint64_t)sec_high << 32 | sec_low;
sec_high = now.tv_sec >> 16 >> 16; #else
} dest->tv_sec = sec_low;
dest->tv_sec = (time_t)sec_high << 16 << 16 | sec_low; #endif
} }
/* ================================================== */ /* ================================================== */
@ -573,10 +572,11 @@ void
UTI_TimevalHostToNetwork(struct timeval *src, Timeval *dest) UTI_TimevalHostToNetwork(struct timeval *src, Timeval *dest)
{ {
dest->tv_nsec = htonl(src->tv_usec * 1000); dest->tv_nsec = htonl(src->tv_usec * 1000);
if (sizeof (time_t) > 4) #ifdef HAVE_LONG_TIME_T
dest->tv_sec_high = htonl(src->tv_sec >> 16 >> 16); dest->tv_sec_high = htonl((uint64_t)src->tv_sec >> 32);
else #else
dest->tv_sec_high = htonl(TV_NOHIGHSEC); dest->tv_sec_high = htonl(TV_NOHIGHSEC);
#endif
dest->tv_sec_low = htonl(src->tv_sec); dest->tv_sec_low = htonl(src->tv_sec);
} }