Prefer IO::Socket::INET6 over IO::Socket::IP

While IO::Socket::IP is a core perl module (since Perl v5.19.8, or so
says corelist), IO::Socket::INET6 has been around longer, is said to
be more widely deployed, and most importantly, seems to have less bugs
hitting us.  We therefore prefer IO::Socket::INET6, and only fall back
to IO::Socket::IP if the former doesn't exist on the local system.

Reviewed-by: Viktor Dukhovni <viktor@openssl.org>
This commit is contained in:
Richard Levitte
2016-02-14 07:10:38 +01:00
parent c8d1c9b067
commit 98ac876f2d

View File

@@ -98,21 +98,11 @@ sub new
message_list => [], message_list => [],
}; };
eval { # IO::Socket::IP is on the core module list, IO::Socket::INET6 isn't.
require IO::Socket::IP; # However, IO::Socket::INET6 is older and is said to be more widely
my $s = IO::Socket::IP->new( # deployed for the moment, and may have less bugs, so we try the latter
LocalAddr => "::1", # first, then fall back on the code modules. Worst case scenario, we
LocalPort => 0, # fall back to IO::Socket::INET, only supports IPv4.
Listen=>1,
);
$s or die "\n";
$s->close();
};
if ($@ eq "") {
# IO::Socket::IP supports IPv6 and is in the core modules list
$IP_factory = sub { IO::Socket::IP->new(@_); };
$have_IPv6 = 1;
} else {
eval { eval {
require IO::Socket::INET6; require IO::Socket::INET6;
my $s = IO::Socket::INET6->new( my $s = IO::Socket::INET6->new(
@@ -124,14 +114,23 @@ sub new
$s->close(); $s->close();
}; };
if ($@ eq "") { if ($@ eq "") {
# IO::Socket::INET6 supports IPv6 but isn't on the core modules list
# However, it's a bit older and said to be more widely deployed
# at the time of writing this comment.
$IP_factory = sub { IO::Socket::INET6->new(@_); }; $IP_factory = sub { IO::Socket::INET6->new(@_); };
$have_IPv6 = 1; $have_IPv6 = 1;
} else { } else {
# IO::Socket::INET doesn't support IPv6 but is a fallback in case eval {
# we have no other. require IO::Socket::IP;
my $s = IO::Socket::IP->new(
LocalAddr => "::1",
LocalPort => 0,
Listen=>1,
);
$s or die "\n";
$s->close();
};
if ($@ eq "") {
$IP_factory = sub { IO::Socket::IP->new(@_); };
$have_IPv6 = 1;
} else {
$IP_factory = sub { IO::Socket::INET->new(@_); }; $IP_factory = sub { IO::Socket::INET->new(@_); };
} }
} }