Restore Perl 5.10 support

On Perl < 5.14, we can use Socket::GetAddrInfo from CPAN to replace the
missing getaddrinfo functionality of Socket.

Socket::GetAddrInfo < 0.22 requires :newapi in the import list, but 0.22
forbids it and enables the new API by default.

Signed-off-by: Anders Kaseorg <andersk@mit.edu>
This commit is contained in:
Anders Kaseorg
2016-11-10 04:37:50 -05:00
parent 04b03b41f6
commit df085e02dc
+9 -3
View File
@@ -30,18 +30,24 @@
# this exception statement from all source files in the program, then
# also delete it here.
use 5.14.0;
use 5.10.0;
use warnings;
use strict;
use Getopt::Long;
use IO::Socket;
use Text::ParseWords;
use Socket qw( getaddrinfo getnameinfo AI_CANONNAME AI_NUMERICHOST NI_NUMERICHOST
IPPROTO_IP IPPROTO_IPV6 IPPROTO_TCP IPPROTO_UDP );
use Socket qw( IPPROTO_IP IPPROTO_IPV6 IPPROTO_TCP IPPROTO_UDP );
use Errno qw(EINTR);
use POSIX qw(_exit);
BEGIN {
my @gai_reqs = qw( getaddrinfo getnameinfo AI_CANONNAME AI_NUMERICHOST NI_NUMERICHOST );
eval { Socket->import( @gai_reqs ); 1; }
|| eval { require Socket::GetAddrInfo; Socket::GetAddrInfo->import( ':newapi', @gai_reqs ); 1; }
|| eval { Socket::GetAddrInfo->import( '0.22', @gai_reqs ); 1; }
|| die "$0 error: requires Perl 5.14 or Socket::GetAddrInfo.\n";
}
my $have_ipv6 = eval {
require IO::Socket::IP;