开发者

How do I enable IPv6 support in LWP?

The following code ...

my $user_agent = LWP::UserAgent->new;
my $request = HTTP::Reque开发者_JS百科st->new(GET => $url);
my $response = $user_agent->request($request);
if ($response->is_success) {
    print "OK\n";
} else {
    die($response->status_line);
}

.. will fail with ..

500 Can't connect to <hostname> (Bad hostname '<hostname>')

.. if the hostname in $url is an IPv6 only address (that is: presence of an AAAA record, but no A record).

My questions are:

  • How do I enable IPv6 support in LWP?
  • How do I configure LWP's settings for "prefer-IPv4-over-IPv6" (A vs. AAAA) / "prefer-IPv6-over-IPv4" (AAAA vs. A)?


It looks like you just need to use Net::INET6Glue::INET_is_INET6. To quote its example:

 use Net::INET6Glue::INET_is_INET6;
 use LWP::Simple;
 print get( 'http://[::1]:80' );
 print get( 'http://ipv6.google.com' );


I believe you'll have to change the module to use the IPV6 net module. By default it does not have this enabled: http://eintr.blogspot.com/2009/03/bad-state-of-ipv6-in-perl.html. I don't believe there is something as simple as "prefer-ipv6"


Debian Wheezy (perl 5.14)

Work nice:

use LWP::Simple;
print get( 'http://ip6-localhost:80' );

Not working (1)

use LWP::Simple;
print get( 'http://[::1]:80' );

Not working (2) [Return: Bad hostname]

use LWP::Simple;
$ua = new LWP::UserAgent();
my $req = new HTTP::Request("GET", "http://[::1]/");
my $res = $ua->request($req);

Not working (3) [Return: Connection refused]

use Net::INET6Glue::INET_is_INET6;
use LWP::Simple;
$ua = new LWP::UserAgent();
my $req = new HTTP::Request("GET", "http://[::1]/");
my $res = $ua->request($req);

Soo, if you don't need IPv6 address in http request, it's fine. :(

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜