diff options
author | David Heidelberg <david@ixit.cz> | 2017-07-30 23:51:39 +0200 |
---|---|---|
committer | David Heidelberg <david@ixit.cz> | 2017-08-07 13:21:01 +0200 |
commit | 4bdd2c3fdb95b312a57c268ea0be6ec1d64f76ef (patch) | |
tree | dd13bc517baac52ba2979f5936d2a36ae4a3445f | |
parent | 3fe987e93abb674cf6d40635ed510bd49b05b392 (diff) | |
download | iputils-4bdd2c3fdb95b312a57c268ea0be6ec1d64f76ef.tar.gz |
ping: fix incorrect packet loss calculation
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.
Fixes: 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 bc364e7..e40d1bf 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); } |