Skip to content

Commit

Permalink
allow combination of -a with --print-tos
Browse files Browse the repository at this point in the history
This is similar to how -e, --elapsed works.
Also adjust -h output regarding --print-tos.
  • Loading branch information
auerswal committed Sep 7, 2024
1 parent c8b8141 commit 7e9ce34
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 12 deletions.
10 changes: 9 additions & 1 deletion ci/test-05-options-c-e.pl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/perl -w

use Test::Command tests => 72;
use Test::Command tests => 75;
use Test::More;

# -c n count of pings to send to each target (default 1)
Expand Down Expand Up @@ -292,6 +292,14 @@
$cmd->exit_is_num(0);
$cmd->stdout_like(qr{127\.0\.0\.1 is alive \(\d\.\d+ ms\)
});
$cmd->stderr_is_eq("");
}

# fping -e -a
{
my $cmd = Test::Command->new(cmd => "fping -e -a 127.0.0.1");
$cmd->exit_is_num(0);
$cmd->stdout_like(qr{127\.0\.0\.1 \(\d\.\d+ ms\)
});
$cmd->stderr_is_eq("");
}
11 changes: 10 additions & 1 deletion ci/test-08-options-n-q.pl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/perl -w

use Test::Command tests => 45;
use Test::Command tests => 48;
use Test::More;

# -n show targets by name (-d is equivalent)
Expand Down Expand Up @@ -58,6 +58,15 @@
$cmd->stderr_is_eq("");
}

# fping -a -O --print-tos
{
my $cmd = Test::Command->new(cmd => "fping -a -O 32 --print-tos 127.0.0.1");
$cmd->exit_is_num(0);
$cmd->stdout_like(qr{127\.0\.0\.1 \(TOS \d+\)
});
$cmd->stderr_is_eq("");
}

# fping --print-tos
{
my $cmd = Test::Command->new(cmd => "fping --print-tos 127.0.0.1");
Expand Down
20 changes: 10 additions & 10 deletions src/fping.c
Original file line number Diff line number Diff line change
Expand Up @@ -2518,16 +2518,16 @@ int wait_for_reply(int64_t wait_time)
if (verbose_flag || alive_flag) {
printf("%s", h->host);

if (verbose_flag) {
if (verbose_flag)
printf(" is alive");
if(print_tos_flag) {
if(ip_header_tos != -1) {
printf(" (TOS %d)", ip_header_tos);
}
else {
printf(" (TOS unknown)");
}
}

if(print_tos_flag) {
if(ip_header_tos != -1) {
printf(" (TOS %d)", ip_header_tos);
}
else {
printf(" (TOS unknown)");
}
}

if (print_ttl_flag) {
Expand Down Expand Up @@ -3108,7 +3108,7 @@ void usage(int is_error)
fprintf(out, " -v, --version show version\n");
fprintf(out, " -x, --reachable=N shows if >=N hosts are reachable or not\n");
fprintf(out, " -X, --fast-reachable=N exits true immediately when N hosts are found\n");
fprintf(out, " --print-tos show tos value\n");
fprintf(out, " --print-tos show received TOS value\n");
fprintf(out, " --print-ttl show IP TTL value\n");
exit(is_error);
}

0 comments on commit 7e9ce34

Please sign in to comment.