diff --git a/src/usr.sbin/ntpd/client.c b/src/usr.sbin/ntpd/client.c index bf7cdd0e..09681db2 100644 --- a/src/usr.sbin/ntpd/client.c +++ b/src/usr.sbin/ntpd/client.c @@ -1,4 +1,4 @@ -/* $OpenBSD: client.c,v 1.100 2015/02/12 01:54:57 reyk Exp $ */ +/* $OpenBSD: client.c,v 1.101 2015/03/28 03:49:01 bcook Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer @@ -258,7 +258,7 @@ client_dispatch(struct ntp_peer *p, u_int8_t settime) if (cmsg->cmsg_level == SOL_SOCKET && cmsg->cmsg_type == SCM_TIMESTAMP) { memcpy(&tv, CMSG_DATA(cmsg), sizeof(tv)); - T4 += tv.tv_sec + JAN_1970 + 1.0e-6 * tv.tv_usec; + T4 += gettime_from_timeval(&tv); break; } } diff --git a/src/usr.sbin/ntpd/util.c b/src/usr.sbin/ntpd/util.c index 6158b80e..60ea5ac1 100644 --- a/src/usr.sbin/ntpd/util.c +++ b/src/usr.sbin/ntpd/util.c @@ -1,4 +1,4 @@ -/* $OpenBSD: util.c,v 1.18 2015/02/10 11:46:39 reyk Exp $ */ +/* $OpenBSD: util.c,v 1.19 2015/03/28 03:49:01 bcook Exp $ */ /* * Copyright (c) 2004 Alexander Guy @@ -45,13 +45,16 @@ gettime(void) if (gettimeofday(&tv, NULL) == -1) fatal("gettimeofday"); - return (tv.tv_sec + JAN_1970 + 1.0e-6 * tv.tv_usec); + return (gettime_from_timeval(&tv)); } double gettime_from_timeval(struct timeval *tv) { - return (tv->tv_sec + JAN_1970 + 1.0e-6 * tv->tv_usec); + /* + * Account for overflow on OSes that have a 32-bit time_t. + */ + return ((uint64_t)tv->tv_sec + JAN_1970 + 1.0e-6 * tv->tv_usec); } time_t