gpt4 book ai didi

windows - Windows 上带有 perl 的 IPv6 无法正常工作

转载 作者:可可西里 更新时间:2023-11-01 09:38:30 24 4
gpt4 key购买 nike

交叉发布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 设置和路径,并从新安装了 perl 5.14.2 http://www.activestate.com/activeperl/downloads

然后我尝试了以下简单代码:

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 box,在我的另一个 windows box 上同样的运行也失败了。

我只是试图在 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 支持是否存在问题?

最佳答案

vinsworldcom on perlmonks.org 所述, 要使用 IPv6 套接字,您需要安装 Socket6 模块。只要您通过 cpan 安装它,代码片段就可以正常工作。

关于windows - Windows 上带有 perl 的 IPv6 无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11753595/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com