Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions ci/test-04-options-a-b.pl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/perl -w

use Test::Command tests => 62;
use Test::Command tests => 68;
use Test::More;
use Time::HiRes qw(gettimeofday tv_interval);

Expand Down Expand Up @@ -76,6 +76,17 @@
$cmd->stderr_is_eq("");
}

# fping -a --icmp-timestamp
SKIP: {
if($^O eq 'darwin') {
skip 'On macOS, this test is unreliable', 3;
}
my $cmd = Test::Command->new(cmd => "fping -a --icmp-timestamp 127.0.0.1");
$cmd->exit_is_num(0);
$cmd->stdout_like(qr{127\.0\.0\.1 timestamps: Originate=\d+ Receive=\d+ Transmit=\d+ Localreceive=\d+});
$cmd->stderr_is_eq("");
}

# fping --print-ttl
{
my $cmd = Test::Command->new(cmd => "fping --print-ttl 127.0.0.1");
Expand All @@ -91,7 +102,18 @@
}
my $cmd = Test::Command->new(cmd => "fping --icmp-timestamp 127.0.0.1");
$cmd->exit_is_num(0);
$cmd->stdout_like(qr{127\.0\.0\.1 is alive \(Timestamp Originate=\d+ Receive=\d+ Transmit=\d+ Localreceive=\d+\)});
$cmd->stdout_like(qr{127\.0\.0\.1 is alive, timestamps: Originate=\d+ Receive=\d+ Transmit=\d+ Localreceive=\d+});
$cmd->stderr_is_eq("");
}

# fping --icmp-timestamp --print-tos --print-ttl -e
SKIP: {
if($^O eq 'darwin') {
skip 'On macOS, this test is unreliable', 3;
}
my $cmd = Test::Command->new(cmd => "fping --icmp-timestamp --print-tos --print-ttl -e 127.0.0.1");
$cmd->exit_is_num(0);
$cmd->stdout_like(qr{127\.0\.0\.1 is alive, timestamps: Originate=\d+ Receive=\d+ Transmit=\d+ Localreceive=\d+ \(TOS \d+\) \(TTL \d+\) \(\d+(\.\d*)? ms\)});
$cmd->stderr_is_eq("");
}

Expand Down
21 changes: 18 additions & 3 deletions 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 => 84;
use Test::Command tests => 87;
use Test::More;

# -c n count of pings to send to each target (default 1)
Expand Down Expand Up @@ -99,8 +99,23 @@
}
my $cmd = Test::Command->new(cmd => "fping -4 --icmp-timestamp -c 2 127.0.0.1");
$cmd->exit_is_num(0);
$cmd->stdout_like(qr{127\.0\.0\.1 : \[0\], 20 bytes, \d\.\d+ ms \(\d\.\d+ avg, 0% loss\), ICMP timestamp: Originate=\d+ Receive=\d+ Transmit=\d+ Localreceive=\d+
127\.0\.0\.1 : \[1\], 20 bytes, \d\.\d+ ms \(\d\.\d+ avg, 0% loss\), ICMP timestamp: Originate=\d+ Receive=\d+ Transmit=\d+ Localreceive=\d+
$cmd->stdout_like(qr{127\.0\.0\.1 : \[0\], 20 bytes, \d\.\d+ ms \(\d\.\d+ avg, 0% loss\), timestamps: Originate=\d+ Receive=\d+ Transmit=\d+ Localreceive=\d+
127\.0\.0\.1 : \[1\], 20 bytes, \d\.\d+ ms \(\d\.\d+ avg, 0% loss\), timestamps: Originate=\d+ Receive=\d+ Transmit=\d+ Localreceive=\d+
});

$cmd->stderr_like(qr{127\.0\.0\.1 : xmt/rcv/%loss = 2/2/0%, min/avg/max = \d\.\d+/\d\.\d+/\d\.\d+
});
}

# fping --icmp-timestamp --print-tos --print-ttl -c n 127.0.0.1
SKIP: {
if($^O eq 'darwin') {
skip 'On macOS, this test is unreliable', 3;
}
my $cmd = Test::Command->new(cmd => "fping -4 --icmp-timestamp --print-tos --print-ttl -p 100 -c 2 127.0.0.1");
$cmd->exit_is_num(0);
$cmd->stdout_like(qr{127\.0\.0\.1 : \[0\], 20 bytes, \d\.\d+ ms \(\d\.\d+ avg, 0% loss\), timestamps: Originate=\d+ Receive=\d+ Transmit=\d+ Localreceive=\d+ \(TOS \d+\) \(TTL \d+\)
127\.0\.0\.1 : \[1\], 20 bytes, \d\.\d+ ms \(\d\.\d+ avg, 0% loss\), timestamps: Originate=\d+ Receive=\d+ Transmit=\d+ Localreceive=\d+ \(TOS \d+\) \(TTL \d+\)
});

$cmd->stderr_like(qr{127\.0\.0\.1 : xmt/rcv/%loss = 2/2/0%, min/avg/max = \d\.\d+/\d\.\d+/\d\.\d+
Expand Down
2 changes: 2 additions & 0 deletions doc/fping.pod
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ Set the interface (requires SO_BINDTODEVICE support).
=item B<--icmp-timestamp>

Send ICMP timestamp requests (ICMP type 13) instead of ICMP Echo requests.
Print ICMP timestamps for originate, receive, and transmit, together with
the local receive time in the same format, in addition to normal output.
Cannot be used together with B<-b> because ICMP timestamp messages have a fixed size.
IPv4 only, requires root privileges or cap_net_raw.

Expand Down
42 changes: 20 additions & 22 deletions src/fping.c
Original file line number Diff line number Diff line change
Expand Up @@ -2605,31 +2605,29 @@ int wait_for_reply(int64_t wait_time)
fprintf(stderr, " [<- %s]", buf);
}

if(print_tos_flag) {
if(ip_header_tos != -1) {
printf(" (TOS %d)", ip_header_tos);
}
else {
printf(" (TOS unknown)");
}
}
if (icmp_request_typ == 13) {
printf("%s timestamps: Originate=%u Receive=%u Transmit=%u Localreceive=%u",
alive_flag ? "" : ",",
ip_header_otime_ms, ip_header_rtime_ms, ip_header_ttime_ms,
ms_since_midnight_utc(recv_time));
}

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

if (icmp_request_typ == 13) {
printf("%simestamp%s Originate=%u Receive=%u Transmit=%u Localreceive=%u%s",
per_recv_flag ? ", ICMP t" : " (T",
per_recv_flag ? ":" : "",
ip_header_otime_ms, ip_header_rtime_ms, ip_header_ttime_ms,
ms_since_midnight_utc(recv_time),
per_recv_flag ? "" : ")");
if (print_ttl_flag) {
if(ip_header_ttl != -1) {
printf(" (TTL %d)", ip_header_ttl);
}
else {
printf(" (TTL unknown)");
}
}

if (elapsed_flag && !per_recv_flag)
Expand Down
Loading