When run with the argument -c NN, ping will wait for the last response
for approximately twice the maximum RTT of the previous
pings. However, an unfortunate integer division means that this
approximation is not always accurate. For example, in a network where
every RTT is 1.04 seconds (tmax = 1040000) the division by 512*1024
will result in an expire time of 1.98 seconds, which rounds down to
1 second - shorter than the RTT of the last ping. ping will print stats
and report a missing response, even if it is not actually late.

Add 1 second to the expire timer to avoid this issue and better
approximate 2*RTT. This has the added benefit of removing an additional
if statement because the result will always be non-zero.

Signed-off-by: Lewis O'Flynn <[email protected]>
---
 networking/ping.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/networking/ping.c b/networking/ping.c
index b7e6955a9..817321026 100644
--- a/networking/ping.c
+++ b/networking/ping.c
@@ -548,9 +548,7 @@ static void sendping_tail(void (*sp)(int), int size_pkt)
 
                if (G.nreceived) {
                        /* approx. 2*tmax, in seconds (2 RTT) */
-                       expire = tmax / (512*1024);
-                       if (expire == 0)
-                               expire = 1;
+                       expire = tmax / (512*1024) + 1;
                }
                signal(SIGALRM, print_stats_and_exit);
                alarm(expire);
-- 
2.47.3

_______________________________________________
busybox mailing list
[email protected]
https://lists.busybox.net/mailman/listinfo/busybox

Reply via email to