summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Habets <thomas@habets.se>2014-05-18 13:03:38 +0100
committerThomas Habets <thomas@habets.se>2014-05-18 13:03:38 +0100
commit1f9c5aa6f7738cd240bd59b7fc235f45cd84684d (patch)
tree29eea7e0c1bff59c646a0dfaaec39b2c2aee9484
parentb03ea4693b5a3e1eed3c37e3482480536107eb04 (diff)
downloadarping-1f9c5aa6f7738cd240bd59b7fc235f45cd84684d.tar.gz
Fix negative percents in -D mode when seeing dups.
-rwxr-xr-xextra/testing.ex16
-rw-r--r--src/arping.c9
2 files changed, 13 insertions, 12 deletions
diff --git a/extra/testing.ex b/extra/testing.ex
index 5c26fcf..27eca67 100755
--- a/extra/testing.ex
+++ b/extra/testing.ex
@@ -129,23 +129,23 @@ expect eof
send_user -- "--------- Ping IP x 2 with inverted audio (-e -D) ------------\n"
spawn $bin -c 2 -e -D $ip
-expect -re "!!\t 0% packet loss\r\n"
+expect "!!\t 0% packet loss (0 extra)\r\n"
expect eof
send_user -- "--------- Ping IP x 2 with inverted audio, bad IP (-e -D) ------------\n"
# TODO: surely this should be \a.\a. ?
spawn $bin -c 2 -e -i eth0 -D 1.2.4.3
-expect "\a\a..\t100% packet loss\r\n"
+expect "\a\a..\t100% packet loss (0 extra)\r\n"
expect eof
send_user -- "--------------- Ping IP cisco style (-D) ------------------\n"
spawn $bin -c 3 -D $ip
-expect "!!!\t 0% packet loss\r\n"
+expect "!!!\t 0% packet loss (0 extra)\r\n"
expect eof
send_user -- "--------------- Ping IP cisco style with audio (-D -a) -----------\n"
spawn $bin -c 3 -D -a $ip
-expect "!\a!\a!\a\t 0% packet loss\r\n"
+expect "!\a!\a!\a\t 0% packet loss (0 extra)\r\n"
expect eof
send_user -- "--------------- Ping IP Targeted (-t) ------------------\n"
@@ -182,21 +182,21 @@ expect eof
send_user -- "--------------- Ping MAC cisco style (-D) ------------------\n"
spawn $bin -A -c 3 -D $mac -T $ip
-expect "!!!\t 0% packet loss\r\n"
+expect "!!!\t 0% packet loss (0 extra)\r\n"
expect eof
send_user -- "--------------- Ping MAC cisco style with audio (-D -a) -----------\n"
spawn $bin -A -c 3 -D -a $mac -T $ip
-expect "!\a!\a!\a\t 0% packet loss\r\n"
+expect "!\a!\a!\a\t 0% packet loss (0 extra)\r\n"
expect eof
send_user -- "--------- Ping MAC x 2 with inverted audio (-e -D) ------------\n"
spawn $bin -A -c 2 -D $mac -T $ip
-expect -re "!!\t 0% packet loss\r\n"
+expect "!!\t 0% packet loss (0 extra)\r\n"
expect eof
send_user -- "--------- Ping MAC x 2 with inverted audio, bad dest (-e -D) ------------\n"
# TODO: surely this should be \a.\a. ?
spawn $bin -A -c 2 -e -i eth0 -D 00:11:22:33:44:55 -T $ip
-expect "\a\a..\t100% packet loss\r\n"
+expect "\a\a..\t100% packet loss (0 extra)\r\n"
expect eof
diff --git a/src/arping.c b/src/arping.c
index 1b5ed55..407ce43 100644
--- a/src/arping.c
+++ b/src/arping.c
@@ -1465,12 +1465,13 @@ int main(int argc, char **argv)
}
}
if (display == DOT) {
+ const float succ = 100.0 - 100.0 * (float)(numrecvd)/(float)numsent;
count_missing_dots();
- printf("\t%3.0f%% packet loss\n",
- 100.0 - 100.0 * (float)(numrecvd)/(float)numsent);
+ printf("\t%3.0f%% packet loss (%d extra)\n",
+ (succ < 0.0) ? 0.0 : succ,
+ (succ < 0.0) ? (numrecvd - numsent): 0);
} else if (display == NORMAL) {
- float succ;
- succ = 100.0 - 100.0 * (float)(numrecvd)/(float)numsent;
+ const float succ = 100.0 - 100.0 * (float)(numrecvd)/(float)numsent;
printf("\n--- %s statistics ---\n"
"%d packets transmitted, "
"%d packets received, "