diff options
author | Sami Kerola <kerolasa@iki.fi> | 2018-10-30 21:36:10 +0000 |
---|---|---|
committer | Sami Kerola <kerolasa@iki.fi> | 2018-11-11 10:43:58 +0000 |
commit | 18ec515bdaf27f093aadfa597ec8ab6cf74cb42d (patch) | |
tree | 939998d82a634f8d48792b7f49e0aa9c2e878d1b | |
parent | a123c2534f3e75195d7523848777a9fe367482a0 (diff) | |
download | iputils-18ec515bdaf27f093aadfa597ec8ab6cf74cb42d.tar.gz |
tracepath: calculate milliseconds in output carefully
Use appropriate function to substract timeval data format, and be more
cautious to avoid integer overflow.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
-rw-r--r-- | tracepath.c | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/tracepath.c b/tracepath.c index 17382ab..337a2aa 100644 --- a/tracepath.c +++ b/tracepath.c @@ -285,9 +285,10 @@ static int recverr(struct run_state *ctl, int fd, struct addrinfo *ai, int ttl) } if (rettv) { - int diff = (tv.tv_sec - rettv->tv_sec) * 1000000 + - (tv.tv_usec - rettv->tv_usec); - printf("%3d.%03dms ", diff / 1000, diff % 1000); + struct timeval res; + + timersub(&tv, rettv, &res); + printf("%3ld.%03ldms ", res.tv_sec * 1000 + res.tv_usec / 1000, res.tv_usec % 1000); if (broken_router) printf("(This broken router returned corrupted payload) "); } |