VinsWorldcom has asked for the
wisdom of the Perl Monks concerning the following question:

I've done some research and come to the conclusion that I can't do name lookup for IPv4 *and* IPv6 addresses (address family independent) with the current version of Perl on my platform. This question is basically to confirm or set me straight.

Looking at http://www.perl.org/about/whitepapers/perl-ipv6.html, I successfully built a simple Perl web-server that listens on v4 *OR* v6 (not both at the same time) using IO::Socket::INET and IO::Socket::INET6 (also with IO::Socket::IP and some additional logic). All that worked fine using just IPv4/v6 addresses. I want to use names.

I have IPv6 enabled with a Hurricane Electric tunnel and can successfully ping ipv6.google.com (an IPv6 only site). In this case, I'm just looking to do name resolution.

I put together a simple script to test name lookup the 'old' way (gethostbyname() and inet_ntoa()) and the 'new' way (getaddrinfo() and inet_ntop()). I also successfully installed the Socket6 and Socket::GetAddrInfo modules with Strawberry.

Both addresses should be the v4 address. The inet_ntop function is converting to IPv6 even though it shouldn't - 72 = 48, 14 = 0e, 204 = cc, 105 = 69

With IPv6 name lookups, it doesn't work at all. I expect the runs without the '--new' switch to fail as gethostbyname() and inet_ntoa() don't support IPv6, but the runs with the '--new' switch also fail.

VinsWorldcom@C:\Users\VinsWorldcom\tmp> v4v6Lookup.pl ipv6.google.com
Usage: Socket::inet_ntoa(ip_address_sv) at C:\Users\VinsWorldcom\tmp\v+4v6Lookup.pl line 29.
VinsWorldcom@C:\Users\VinsWorldcom\tmp> v4v6Lookup.pl --new ipv6.googl+e.com
C:\Users\VinsWorldcom\tmp\v4v6Lookup.pl: The requested name is valid, +but no data of the requested type was found.
VinsWorldcom@C:\Users\VinsWorldcom\tmp> v4v6Lookup.pl 2001:4860:800f::+63
Usage: Socket::inet_ntoa(ip_address_sv) at C:\Users\VinsWorldcom\tmp\v+4v6Lookup.pl line 29.
VinsWorldcom@C:\Users\VinsWorldcom\tmp> v4v6Lookup.pl --new 2001:4860:+800f::63
Bad arg length for Socket6::inet_ntop, length is 28, should be 16 at C+:\Users\VinsWorldcom\tmp\v4v6Lookup.pl line 40.

As you can see, the gethostbyname() and inet_ntoa() worked well for host or IP resolution to an IP address in the IPv4 address family - and that's how I've always done it. Trying to extend that to let my scripts accommodate IPv4 and IPv6 is proving problematic. According to the above web link, Perl 5.14 will fix this and Strawberry just released 5.14 - I haven't tried that yet.

You almost certainly don't want to be using Socket6 for this. Core's Socket has had getaddrinfo for quite some time now, and I keep improving it.
Also, your uses of inet_ntop are suspect. You shouldn't need to use those. This is what getnameinfo is for.

You shouldn't ever need to use inet_ntop, inet_pton, gethostby*, or any of those other legacies. Any time you want to turn something human-readable into something binary, use getaddrinfo. Any time you want to turn something binary into something human-readable, use getnameinfo.
Simple. :)

BRILLIANT! Thanks for your work on this. I'm doing quite a lot of IPv6 testing now as I'm seeing it pop up here and there. I'd like to be prepared knowing not just the networking aspect, but also the application development (C and Perl at least) angles to retrofitting IPv6 capabilities into existing applications.