aboutsummaryrefslogtreecommitdiff
path: root/toys
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2018-07-08 01:16:16 -0500
committerRob Landley <rob@landley.net>2018-07-08 01:16:16 -0500
commit66d1776fb85530b446dcc1f68929231849a5ad44 (patch)
tree7d9653d2af47f4ce7d6a599316172608d9f6cc38 /toys
parentd2e317a622c672109ed25176044a3920a1167466 (diff)
downloadtoybox-66d1776fb85530b446dcc1f68929231849a5ad44.tar.gz
Fix division by zero errors and double summary in ping.
Diffstat (limited to 'toys')
-rw-r--r--toys/net/ping.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/toys/net/ping.c b/toys/net/ping.c
index 86384794..36933939 100644
--- a/toys/net/ping.c
+++ b/toys/net/ping.c
@@ -76,9 +76,9 @@ static void summary(int sig)
if (!(toys.optflags&FLAG_q) && TT.sent && TT.sa) {
printf("\n--- %s ping statistics ---\n", ntop(TT.sa));
printf("%lu packets transmitted, %lu received, %ld%% packet loss\n",
- TT.sent, TT.recv, ((TT.sent-TT.recv)*100)/TT.sent);
+ TT.sent, TT.recv, ((TT.sent-TT.recv)*100)/(TT.sent?TT.sent:1));
printf("round-trip min/avg/max = %lu/%lu/%lu ms\n",
- TT.min, TT.max, TT.fugit/TT.recv);
+ TT.min, TT.max, TT.fugit/(TT.recv?TT.recv:1));
}
TT.sa = 0;
}
@@ -278,6 +278,7 @@ void ping_main(void)
toys.exitval = 0;
}
+ sigatexit(0);
summary(0);
if (CFG_TOYBOX_FREE) {