summaryrefslogtreecommitdiff
path: root/src/tools/oping/oping_client.c
diff options
context:
space:
mode:
authordimitri staessens <dimitri.staessens@intec.ugent.be>2016-08-04 16:59:31 +0200
committerdimitri staessens <dimitri.staessens@intec.ugent.be>2016-08-04 17:24:40 +0200
commit2164c4ce67acde4282a579937a784647b66f4d72 (patch)
tree6d003ae03c321840d81a07ce0e10d906395a68fc /src/tools/oping/oping_client.c
parentdd808dd6cd7eb4690bfc009eb8dd8150944f75b6 (diff)
downloadouroboros-2164c4ce67acde4282a579937a784647b66f4d72.tar.gz
ouroboros-2164c4ce67acde4282a579937a784647b66f4d72.zip
tools: oping: Fix division by zero
When killing the oping client before it sent an SDU, some bad operations were being performed.
Diffstat (limited to 'src/tools/oping/oping_client.c')
-rw-r--r--src/tools/oping/oping_client.c23
1 files changed, 14 insertions, 9 deletions
diff --git a/src/tools/oping/oping_client.c b/src/tools/oping/oping_client.c
index 23a57549..7693ce41 100644
--- a/src/tools/oping/oping_client.c
+++ b/src/tools/oping/oping_client.c
@@ -212,16 +212,21 @@ int client_main()
printf("--- %s ping statistics ---\n", client.s_apn);
printf("%d SDU's transmitted, ", client.sent);
printf("%d received, ", client.rcvd);
- printf("%d%% packet loss, ", 100 - ((100 * client.rcvd) / client.sent));
+ printf("%d%% packet loss, ", client.sent == 0 ? 0 :
+ 100 - ((100 * client.rcvd) / client.sent));
printf("time: %.3f ms\n", ts_diff_us(&tic, &toc) / 1000.0);
- printf("rtt min/avg/max/mdev = %.3f/%.3f/%.3f/",
- client.rtt_min,
- client.rtt_avg,
- client.rtt_max);
- client.rcvd > 1 ?
- printf("%.3f ms\n",
- sqrt(client.rtt_m2 / (float) (client.rcvd - 1))) :
- printf("Nan ms\n");
+
+ if (client.rcvd > 0) {
+ printf("rtt min/avg/max/mdev = %.3f/%.3f/%.3f/",
+ client.rtt_min,
+ client.rtt_avg,
+ client.rtt_max);
+ if (client.rcvd > 1)
+ printf("%.3f ms\n",
+ sqrt(client.rtt_m2 / (float) (client.rcvd - 1)));
+ else
+ printf("NaN ms\n");
+ }
pthread_mutex_lock(&client.lock);
free(client.times);