diff options
author | David Gwynne <dlg@cvs.openbsd.org> | 2015-03-11 03:38:57 +0000 |
---|---|---|
committer | David Gwynne <dlg@cvs.openbsd.org> | 2015-03-11 03:38:57 +0000 |
commit | 52cb0728241d3024374b45efdd26990e070e7b22 (patch) | |
tree | 5f0fe2a9a763caaaf612917df6c994590eb56ce3 /sbin/ping6/ping6.c | |
parent | 8a3f8e114db44bc43da2974929da4707f6ac65be (diff) |
port src/sbin/ping/ping.c r1.115.
> use clock_gettime(CLOCK_MONOTONIC) to get timestamps to measure the
> interval between sending a ping and getting a reply for it.
>
> this makes it resistant against local wall clock changes, which can
> skew the intervals reported or make them go negative.
requested by deraadt@ florian@
Diffstat (limited to 'sbin/ping6/ping6.c')
-rw-r--r-- | sbin/ping6/ping6.c | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/sbin/ping6/ping6.c b/sbin/ping6/ping6.c index 812a10a489e..4b9fe1f07b3 100644 --- a/sbin/ping6/ping6.c +++ b/sbin/ping6/ping6.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ping6.c,v 1.101 2015/01/16 06:40:00 deraadt Exp $ */ +/* $OpenBSD: ping6.c,v 1.102 2015/03/11 03:38:56 dlg Exp $ */ /* $KAME: ping6.c,v 1.163 2002/10/25 02:19:06 itojun Exp $ */ /* @@ -1072,10 +1072,13 @@ pinger(void) icp->icmp6_id = htons(ident); icp->icmp6_seq = ntohs(seq); if (timing) { + struct timespec ts; struct timeval tv; struct tv32 tv32; - (void)gettimeofday(&tv, NULL); + if (clock_gettime(CLOCK_MONOTONIC, &ts) == -1) + err(1, "clock_gettime(CLOCK_MONOTONIC)"); + TIMESPEC_TO_TIMEVAL(&tv, &ts); tv32.tv32_sec = htonl(tv.tv_sec); /* XXX 2038 */ tv32.tv32_usec = htonl(tv.tv_usec); bcopy(&tv32, &outpack[ICMP6ECHOLEN], sizeof(tv32)); @@ -1206,6 +1209,7 @@ pr_pack(u_char *buf, int cc, struct msghdr *mhdr) int fromlen; u_char *cp = NULL, *dp, *end = buf + cc; struct in6_pktinfo *pktinfo = NULL; + struct timespec ts; struct timeval tv, tp; struct tv32 tv32; double triptime = 0; @@ -1215,7 +1219,9 @@ pr_pack(u_char *buf, int cc, struct msghdr *mhdr) u_int16_t seq; char dnsname[MAXDNAME + 1]; - (void)gettimeofday(&tv, NULL); + if (clock_gettime(CLOCK_MONOTONIC, &ts) == -1) + err(1, "clock_gettime(CLOCK_MONOTONIC)"); + TIMESPEC_TO_TIMEVAL(&tv, &ts); if (!mhdr || !mhdr->msg_name || mhdr->msg_namelen != sizeof(struct sockaddr_in6) || |