tags:

views:

235

answers:

2

The following code ...

my $user_agent = LWP::UserAgent->new;
my $request = HTTP::Request->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)?
+1  A: 

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"

Harley Green
+5  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' );
cjm
Thanks! Net::INET6Glue did the trick!
knorv