From: Erik Auerswald Date: Sat, 30 Nov 2024 19:02:46 +0000 (+0100) Subject: ensure IPv4 is used with --icmp-timestamp X-Git-Url: https://git.gsnw.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8932ecd1435ae562dda146b04389da796975780f;p=fping.git ensure IPv4 is used with --icmp-timestamp The ICMP Timestamp message is defined for IPv4, but not for IPv6. Before, combining --icmp-timestamp with an IPv6 address or a DNS name for a dual-stacked target on a dual-stacked system resulted in sending ICMPv6 Echo over IPv6. Now, DNS names for dual-stacked hosts just work, i.e., fping uses IPv4 with --icmp-timestamp. Combining --icmp-timestamp with an IPv6 address or an IP6-only DNS name now fails. --- diff --git a/ci/test-04-options-a-b.pl b/ci/test-04-options-a-b.pl index 36e3acb..b9c0fe4 100755 --- a/ci/test-04-options-a-b.pl +++ b/ci/test-04-options-a-b.pl @@ -1,6 +1,6 @@ #!/usr/bin/perl -w -use Test::Command tests => 53; +use Test::Command tests => 62; use Test::More; use Time::HiRes qw(gettimeofday tv_interval); @@ -95,6 +95,17 @@ $cmd->stdout_like(qr{127\.0\.0\.1 is alive \(Timestamp Originate=\d+ Receive=\d+ $cmd->stderr_is_eq(""); } +# fping --icmp-timestamp ::1 +SKIP: { + if($ENV{SKIP_IPV6}) { + skip 'Skip IPv6 tests', 3; + } + my $cmd = Test::Command->new(cmd => "fping --icmp-timestamp ::1"); + $cmd->exit_is_num(2); + $cmd->stdout_is_eq(""); + $cmd->stderr_like(qr{^::1:.*(not supported|not known)}); +} + # fping --print-ttl with IPv6 SKIP: { if($ENV{SKIP_IPV6}) { @@ -146,6 +157,28 @@ $cmd->stdout_is_eq(""); $cmd->stderr_like(qr{cannot change ICMP Timestamp size}); } +# fping -6 --icmp-timestamp +SKIP: { + if($ENV{SKIP_IPV6}) { + skip 'Skip IPv6 tests', 3; + } + my $cmd = Test::Command->new(cmd => "fping -6 --icmp-timestamp ::1"); + $cmd->exit_is_num(1); + $cmd->stdout_is_eq(""); + $cmd->stderr_like(qr{ICMP Timestamp is IPv4 only}); +} + +# fping --icmp-timestamp -6 +SKIP: { + if($ENV{SKIP_IPV6}) { + skip 'Skip IPv6 tests', 3; + } + my $cmd = Test::Command->new(cmd => "fping --icmp-timestamp -6 ::1"); + $cmd->exit_is_num(1); + $cmd->stdout_is_eq(""); + $cmd->stderr_is_eq("fping: can't specify both -4 and -6\n"); +} + # fping -B SKIP: { if($^O eq 'darwin') { diff --git a/src/fping.c b/src/fping.c index 38fa0a3..7f26ad9 100644 --- a/src/fping.c +++ b/src/fping.c @@ -591,6 +591,13 @@ int main(int argc, char **argv) } else if (strstr(optparse_state.optlongname, "check-source") != NULL) { check_source_flag = 1; } else if (strstr(optparse_state.optlongname, "icmp-timestamp") != NULL) { +#ifdef IPV6 + if (hints_ai_family != AF_UNSPEC && hints_ai_family != AF_INET) { + fprintf(stderr, "%s: ICMP Timestamp is IPv4 only\n", prog); + exit(1); + } + hints_ai_family = AF_INET; +#endif icmp_request_typ = 13; ping_data_size = ICMP_TIMESTAMP_DATA_SIZE; } else if (strstr(optparse_state.optlongname, "print-tos") != NULL) {