mirror of
https://gitlab.com/chrony/chrony.git
synced 2025-12-04 03:35:06 -05:00
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:
37
util.c
37
util.c
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
/* ================================================== */
|
||||
|
||||
Reference in New Issue
Block a user