Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ping: Add support for IPv4-mapped IPv6 address format #356

Closed
wants to merge 1 commit into from
Closed
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
14 changes: 13 additions & 1 deletion ci/test-01-basics.pl
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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");
Expand Down
8 changes: 8 additions & 0 deletions src/fping.c
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
}
Expand Down
Loading