Subject: bin/20885: ping6 does integer division & rouds down when calculating packet loss
To: None <gnats-bugs@gnats.netbsd.org>
From: None <kre@munnari.OZ.AU>
List: netbsd-bugs
Date: 03/25/2003 14:22:23
>Number: 20885
>Category: bin
>Synopsis: ping6 does integer division & rouds down when calculating packet loss
>Confidential: no
>Severity: non-critical
>Priority: medium
>Responsible: bin-bug-people
>State: open
>Class: change-request
>Submitter-Id: net
>Arrival-Date: Mon Mar 24 23:24:00 PST 2003
>Closed-Date:
>Last-Modified:
>Originator: Robert Elz
>Release: NetBSD 1.6L (-current sources of 2003-03-24)
>Organization:
Prince of Songkla University
>Environment:
System: NetBSD delta.cs.mu.OZ.AU 1.6L NetBSD 1.6L (DELTA) #29: Fri Jan 10 11:40:50 ICT 2003 kre@fuchsia.cs.mu.OZ.AU:/usr/obj/sys/DELTA i386
Architecture: i386
Machine: i386
>Description:
Run ping6 in an environment where packets are lost.
Calculate the packet loss percentage based upon the number
of received and transmitted packets, and notice that the
answer from ping is correct only to the nearest whole number
rounded down (a 1.99% packet loss is printed as 1%).
On the other hand, ping (for v4) prints the packet loss to
1/10 of a percent, which is much more useful. V6 should be
at least as good as v4 in all respects, hence this bug report!
(This change request really)
>How-To-Repeat:
UTSL is the easiest... But running pin6 in the correct
environment and observing the output works too.
>Fix:
Apply the appended patch. This is actually marginally better
than the code in ping, in that it rounds to the nearest tenth of
a percentage point, instead of truncating to the next lower
(a 1.99% packet loss will be printed as 2.0% instead of 1.9%)
It would be good to update ping6 to something closer to the current
state of ping, lots of ping6 looks to be based on horribly ancient
ping code (the %f way of printing the packet loss percentage was
added to ping in 1998...)
Index: ping6.c
===================================================================
RCS file: /local/NetBSD/repository/src/sbin/ping6/ping6.c,v
retrieving revision 1.53
diff -u -r1.53 ping6.c
--- ping6.c 2002/12/05 02:07:03 1.53
+++ ping6.c 2003/03/25 07:12:24
@@ -2179,8 +2179,8 @@
if (nreceived > ntransmitted)
(void)printf("-- somebody's duplicating packets!");
else
- (void)printf("%d%% packet loss",
- (int) (((ntransmitted - nreceived) * 100) /
+ (void)printf("%.1f%% packet loss", 0.05 +
+ (((ntransmitted - nreceived) * 100.0) /
ntransmitted));
}
(void)putchar('\n');
>Release-Note:
>Audit-Trail:
>Unformatted: