交叉发布http://perlmonks.org/index.pl?node_id=984750
(perl windows IPv6的可能副本)我尝试了以下示例示例:https ://metacpan.org/module/IO::Socket::IP
use IO::Socket::IP -register;
my $sock = IO::Socket->new(
Domain => PF_INET6,
LocalHost => "::1",
Listen => 1,
) or die "Cannot create socket - $@\n";
print "Created a socket of type " . ref($sock) . "\n";
它给出的输出为:无法创建套接字 - 没有与节点名关联的地址
我正在使用 ActiveState perl 5.14.2 并在其上构建了 IO::Socket::IP 模块。
以下是 ping 结果:
c:\>ping ::1
Pinging ::1 with 32 bytes of data:
Reply from ::1: time<1ms
Reply from ::1: time<1ms
Reply from ::1: time<1ms
Reply from ::1: time<1ms
Ping statistics for ::1:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 0ms, Maximum = 0ms, Average = 0ms
如果我使用 IPv4 样式的环回地址 127.0.0.1,上面的代码运行良好。我想知道我错过了什么。
更新:
我刚刚清理了 perl 设置和路径,并从 http://www.activestate.com/activeperl/downloads新安装了 perl 5.14.2
然后我尝试了以下简单的代码:
use strict;
use warnings;
use Socket qw(getaddrinfo SOCK_STREAM AI_PASSIVE );
my ( $err, @res ) = getaddrinfo( "::", 8086, {
socktype => SOCK_STREAM,
flags => AI_PASSIVE,
} );
die $err if $err;
它以以下错误结束:在 c:\IPv6.pl 第 10 行没有与节点名关联的地址。
但是使用 127.0.0.1 它会返回正确的值。
我正在使用 windows 2008 R2 机器,在我的另一个 windows 机器上同样运行也失败了。
我只是试图在 Socket.pm 中跟踪这个调用,发现调用的是“fake_getaddrinfo”而不是真正的 getaddrinfo。似乎 XSLoader 要么无法从 Socket.dll 找到/加载 getaddrinfo,要么 Socket.dll 根本没有 getaddrinfo。可能是什么原因?
下面使用 Socket6 的类似代码在相同的设置上正常工作:
use Socket;
use Socket6;
@res = getaddrinfo('::', 8086, AF_UNSPEC, SOCK_STREAM);
while(scalar(@res)>=5){
($family, $socktype, $proto, $saddr, $canonname, @res) = @res;
($host, $port) = getnameinfo($saddr, NI_NUMERICHOST | NI_NUMERICSERV);
print ("\nhost= $host port = $port");
socket(Socket_Handle, $family, $socktype, $proto) || next;
bind(Socket_Handle,$saddr ) || die "bind: $!";
listen(Socket_Handle, 5) || die "listen: $!";
($host, $port) = getnameinfo($saddr, NI_NUMERICHOST | NI_NUMERICSERV);
print ("\nReady for connections \nhost= $host port = $port");
$paddr = accept(Client, Socket_Handle);
}
所以我什至不能责怪设置或系统 dll。perl 对 windows 的 activestate 构建的内置 IPv6 支持是否存在问题?