diff --git a/ci/test-01-basics.pl b/ci/test-01-basics.pl index e54bc225..acfc6aea 100755 --- a/ci/test-01-basics.pl +++ b/ci/test-01-basics.pl @@ -1,6 +1,6 @@ #!/usr/bin/perl -w -use Test::Command tests => 15; +use Test::Command tests => 18; use Test::More; # ping 127.0.0.1 @@ -35,6 +35,18 @@ $cmd->stderr_like(qr{ \[<- .*\]}); } +# ping ::ffff:127.0.0.1 +SKIP: { + if($ENV{SKIP_IPV6}) { + skip 'Skip IPv6 tests', 3; + } + my $cmd = Test::Command->new(cmd => "fping ::ffff:127.0.0.1"); + $cmd->exit_is_num(0); + $cmd->stdout_is_eq("IPv4-Mapped-in-IPv6 address, using IPv4 127.0.0.1 +127.0.0.1 is alive\n"); + $cmd->stderr_like(qr{ \[<- 127.0.0.1\]}); +} + # ping 3 times 127.0.0.1 { my $cmd = Test::Command->new(cmd => "fping -p 100 -C3 127.0.0.1"); diff --git a/src/fping.c b/src/fping.c index 87b5fb9e..d8c6a56d 100644 --- a/src/fping.c +++ b/src/fping.c @@ -1208,6 +1208,14 @@ int main(int argc, char **argv) * for each of them */ for (cursor = event_queue_ping.first; cursor; cursor = cursor->ev_next) { table[i] = cursor->host; + + struct in6_addr a6; + if (inet_pton(AF_INET6, cursor->host->host, &a6) && IN6_IS_ADDR_V4MAPPED(&a6)) { + cursor->host->host = strrchr(cursor->host->host, ':') + 1; + cursor->host->saddr.ss_family = AF_INET; + printf("IPv4-Mapped-in-IPv6 address, using IPv4 %s\n", cursor->host->host); + } + cursor->host->i = i; i++; }