diff options
author | David Heidelberg <david@ixit.cz> | 2017-07-30 23:51:39 +0200 |
---|---|---|
committer | David Heidelberg <david@ixit.cz> | 2017-07-30 23:51:39 +0200 |
commit | 9bdc33cc8a12170a00db33d39667c5fc1f53622c (patch) | |
tree | 18433e3fce7bd920234d8857d46775341b1d4d25 | |
parent | 944a4cf9dc5ee137d6a0c10f8c93adf4c3a33bb0 (diff) | |
download | iputils-accuracy_fix.tar.gz |
ping: fix incorrect packet loss calculationaccuracy_fix
Sadly, integer representation may lead to imprecise information about
packet loss. Mostly in cases, where number is near to 0 or 100 percent.
This fix does final calculation and representation in float, so output
will make sense.
Bug: https://github.com/iputils/iputils/issues/94
Signed-off-by: David Heidelberg <david@ixit.cz>
-rw-r--r-- | ping_common.c | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/ping_common.c b/ping_common.c index b0825e3..655ca7a 100644 --- a/ping_common.c +++ b/ping_common.c @@ -887,8 +887,11 @@ void finish(void) if (nerrors) printf(", +%ld errors", nerrors); if (ntransmitted) { - printf(", %d%% packet loss", - (int) ((((long long)(ntransmitted - nreceived)) * 100) / +#ifdef USE_IDN + setlocale(LC_ALL, "C"); +#endif + printf(", %g%% packet loss", + (float) ((((long long)(ntransmitted - nreceived)) * 100.0) / ntransmitted)); printf(", time %ldms", 1000*tv.tv_sec+tv.tv_usec/1000); } |