问题
I have a Perl/Windows app that uses TCP/IP sockets and I need to add IPv6 support.
I have a Windows 7 64-bit machine that is running IPv6 with a Hurricane Electric tunnel and it scores 10 out 10 on http://test-ipv6.com/ and will access IPv6-only sites such as http://loopsofzen.co.uk/.
It has ActivePerl 5.14.2 (I also tried Strawberry Perl 5.16.0.1).
Here's a simple test script:
use Socket qw( getaddrinfo );
$host = 'loopsofzen.co.uk';
$port = 80;
$hints = (socktype => SOCK_STREAM, family -> Socket::AF_INET6);
($err, @addrs) = getaddrinfo($host, 0);
die $err if $err;
and this produces the error:
no address associated with nodename at ip.pl line 6.
The (new) getaddrinfo()
function appears to be available and it does work if I set $host
to use an IPv4 hostname. But IPv6 doesn't appear to work at all.
What am I missing? Or is Perl/Windows/IPv6 still a lost cause for the time being?
回答1:
The following "works for me" on OSX, which can successfully ping -6 loopsofzen.co.uk
.
$ perl -lE'use Socket qw( getaddrinfo );
($err, @addrs) = getaddrinfo(q{loopsofzen.co.uk}, 0);
die $err if $err; print map { "@{[ %$_ ]}" } @addrs;'
protocol 17 canonname addr ?? socktype 2 family 30protocol 6 canonname addr ?? socktype 1 family 30
I think your problem isn't the Perl bit, as the same code Works For Me.
回答2:
So I threw a copy of Linux (Ubuntu) onto an old laptop and the same code works just fine.
It seems that IPv6 support is present but broken in ActivePerl and Strawberry Perl on Windows.
It has been suggested that the compiler headers and libraries used to make the Windows builds have not yet been updated for IPv6. Hopefully that will get resolved in due course. In the meantime, I can continue development on Linux.
回答3:
You could compile your own Perl 5.16 from source on Windows.
I did it with VC10 (Microsoft Visual Studio 2010) using the "Visual Studio x64 Win64 Command Prompt (2010)". It's basically regular command prompt but with all the environment prepared for x64 builds.
I think there are some "express" free versions of Visual Studio, but I don't know if those lack of something compared to the commercial version.
I really had no trouble building Perl, just read the README and INSTALL files. I actually did the same for Apache 2.2, mod_perl and for all modules I use/need from CPAN from source. If you run things like cpan and cpanm from the same VS command prompt, everything builds great as long as the module is compatible with Win32 (95% of modules are compatible).
The function "getaddrinfo" works perfectly for me.
来源:https://stackoverflow.com/questions/11348206/perl-windows-ipv6