#!/usr/bin/perl -w
-use Test::Command tests => 32;
+use Test::Command tests => 41;
use Test::More;
use Time::HiRes qw(gettimeofday tv_interval);
$cmd->stderr_is_eq("");
}
+# fping -a --print-ttl
+{
+my $cmd = Test::Command->new(cmd => "fping -a --print-ttl 127.0.0.1 127.0.0.2");
+$cmd->exit_is_num(0);
+$cmd->stdout_like(qr{127\.0\.0\.1 \(TTL \d+\)\n127\.0\.0\.2 \(TTL \d+\)\n});
+$cmd->stderr_is_eq("");
+}
+
+# fping --print-ttl
+{
+my $cmd = Test::Command->new(cmd => "fping --print-ttl 127.0.0.1");
+$cmd->exit_is_num(0);
+$cmd->stdout_like(qr{127\.0\.0\.1 is alive \(TTL \d+\)});
+$cmd->stderr_is_eq("");
+}
+
+# fping --print-ttl with IPv6
+SKIP: {
+ if($ENV{SKIP_IPV6}) {
+ skip 'Skip IPv6 tests', 3;
+ }
+ my $cmd = Test::Command->new(cmd => "fping --print-ttl ::1");
+ $cmd->exit_is_num(0);
+ $cmd->stdout_like(qr{::1 is alive \(TTL unknown\)\n});
+ $cmd->stderr_is_eq("");
+}
+
# fping -A
{
my $cmd = Test::Command->new(cmd => "fping -4 -A localhost");
}
sub test_unprivileged_works {
- plan tests => 12;
+ plan tests => 15;
{
my $cmd = Test::Command->new(cmd => "$fping_copy 127.0.0.1");
$cmd->stdout_is_eq("127.0.0.1 is alive (TOS unknown)\n");
$cmd->stderr_is_eq("");
}
+ {
+ my $cmd = Test::Command->new(cmd => "$fping_copy --print-ttl 127.0.0.1");
+ $cmd->exit_is_num(0);
+ $cmd->stdout_is_eq("127.0.0.1 is alive (TTL unknown)\n");
+ $cmd->stderr_is_eq("");
+ }
SKIP: {
if($^O ne 'linux') {
skip '-k option is only supported on Linux', 3;
Set the IP TTL field (time to live hops).
+=item B<--print-ttl>
+
+Displays the IPv4 TTL value from the IP Header in the output.
+If B<fping> cannot read the TTL value, "(TTL unknown)" is returned.
+IPv4 only, requires root privileges or cap_net_raw.
+
=item B<-i>, B<--interval>=I<MSEC>
The minimum amount of time (in milliseconds) between sending a ping packet
int cumulative_stats_flag = 0;
int check_source_flag = 0;
int print_tos_flag = 0;
+int print_ttl_flag = 0;
#if defined(DEBUG) || defined(_DEBUG)
int randomly_lose_flag, trace_flag, print_per_system_flag;
int lose_factor;
{ "fast-reachable", 'X', OPTPARSE_REQUIRED },
{ "check-source", '0', OPTPARSE_NONE },
{ "print-tos", '0', OPTPARSE_NONE },
+ { "print-ttl", '0', OPTPARSE_NONE },
#if defined(DEBUG) || defined(_DEBUG)
{ NULL, 'z', OPTPARSE_REQUIRED },
#endif
check_source_flag = 1;
} else if (strstr(optparse_state.optlongname, "print-tos") != NULL) {
print_tos_flag = 1;
+ } else if (strstr(optparse_state.optlongname, "print-ttl") != NULL) {
+ print_ttl_flag = 1;
} else {
usage(1);
}
size_t reply_buf_len,
unsigned short *id,
unsigned short *seq,
- int *ip_header_tos)
+ int *ip_header_tos,
+ int *ip_header_ttl)
{
struct icmp *icp;
int hlen = 0;
if (!using_sock_dgram4) {
struct ip *ip = (struct ip *)reply_buf;
*ip_header_tos = ip->ip_tos;
+ *ip_header_ttl = ip->ip_ttl;
#if defined(__alpha__) && __STDC__ && !defined(__GLIBC__) && !defined(__NetBSD__) && !defined(__OpenBSD__)
/* The alpha headers are decidedly broken.
unsigned short id;
unsigned short seq;
int ip_header_tos = -1;
+ int ip_header_ttl = -1;
/* Receive packet */
result = receive_packet(wait_time, /* max. wait time, in ns */
sizeof(buffer),
&id,
&seq,
- &ip_header_tos);
+ &ip_header_tos,
+ &ip_header_ttl);
if (ip_hlen < 0) {
return 1;
}
}
}
+ if (print_ttl_flag) {
+ if(ip_header_ttl != -1) {
+ printf(" (TTL %d)", ip_header_ttl);
+ }
+ else {
+ printf(" (TTL unknown)");
+ }
+ }
+
if (elapsed_flag)
printf(" (%s ms)", sprint_tm(this_reply));
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-ttl show IP TTL value\n");
exit(is_error);
}