Always send timevals in cmdmon protocol in 64-bit format

This is to avoid incompatibility between 64/32-bit client/server.
While at it, convert all time values in the protocol to timeval
to avoid Y2K38 problem.
This commit is contained in:
Miroslav Lichvar
2009-10-09 15:31:59 +02:00
parent 8265ff2890
commit a7892a1a15
8 changed files with 93 additions and 42 deletions

37
util.c
View File

@@ -501,4 +501,41 @@ UTI_Int64ToTimeval(NTP_int64 *src,
dest->tv_usec = (int)(0.5 + (double)(ntohl(src->lo)) / 4294.967296);
}
/* ================================================== */
void
UTI_TimevalNetworkToHost(Timeval *src, struct timeval *dest)
{
uint32_t sec_low, sec_high;
dest->tv_usec = ntohl(src->tv_usec);
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;
struct timezone tz;
gettimeofday(&now, &tz);
sec_high = now.tv_sec >> 32;
}
dest->tv_sec = (time_t)sec_high << 16 << 16 | sec_low;
}
/* ================================================== */
void
UTI_TimevalHostToNetwork(struct timeval *src, Timeval *dest)
{
dest->tv_usec = htonl(src->tv_usec);
if (sizeof (time_t) > 4)
dest->tv_sec_high = htonl(src->tv_sec >> 32);
else
dest->tv_sec_high = htonl(TV_NOHIGHSEC);
dest->tv_sec_low = htonl(src->tv_sec);
}
/* ================================================== */