Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: IPv6 Name Resolution

by Anonymous Monk
on Nov 22, 2011 at 16:00 UTC ( #939480=note: print w/ replies, xml ) Need Help??


in reply to IPv6 Name Resolution

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.

use Socket qw( getaddrinfo getnameinfo ); my ( $err, @addrs ) = getaddrinfo( $ARGV[0], 0 ); die $err if $err; my ( $err, $hostname ) = getnameinfo( $addrs[0]->{addr} ); die $err if $err;
If you dislike that error-in-first-result API style, try Socket::GetAddrInfo::Strict:
use Socket::GetAddrInfo::Strict qw( getaddrinfo, getnameinfo ); my @addrs = getaddrinfo( $ARGV[0], 0 ); my ( $hostname ) = getnameinfo( $addrs[0]->{addr} );
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. :)


Comment on Re: IPv6 Name Resolution
Select or Download Code
Re^2: IPv6 Name Resolution
by VinsWorldcom (Priest) on Nov 22, 2011 at 18:22 UTC

    It seemed to good to be true and it was:

    VinsWorldcom@C:\Users\VinsWorldcom\tmp> cat test.pl use Socket qw( getaddrinfo getnameinfo ); my ( $err, @addrs ) = getaddrinfo( $ARGV[0], 0 ); die $err if $err; my ( $err, $hostname ) = getnameinfo( $addrs[0]->{addr} ); die $err if $err; VinsWorldcom@C:\Users\VinsWorldcom\tmp> test.pl "getaddrinfo" is not exported by the Socket module "getnameinfo" is not exported by the Socket module Can't continue after import errors at C:\Users\VinsWorldcom\tmp\test.p +l line 1 BEGIN failed--compilation aborted at C:\Users\VinsWorldcom\tmp\test.pl + line 1. VinsWorldcom@C:\Users\VinsWorldcom\tmp> perldoc Socket | grep getnamei +nfo VinsWorldcom@C:\Users\VinsWorldcom\tmp> perldoc Socket | grep getaddri +nfo VinsWorldcom@C:\Users\VinsWorldcom\tmp> perl -MSocket -e "print $Socke +t::VERSION" 1.87_01

    While the latest version of Perl Socket (5.14.x) seems to support getXXXXinfo functions; remember, my original query asked for Windows 7, Strawberry Perl 5.12.3.

      In that case, simply install Socket::GetAddrInfo; it's backed by the same XS and PP code that was copied into core Perl at 5.14.0.

      Also note that I'm in the process of making Socket dual-life, so you can install the current development version of that

      • http://search.cpan.org/~pevans/Socket-1.94_07/
      This is known to work back at least as far as Perl 5.10.0, and hopefully soon this will reach a real 1.95 release. This will mean your code continues to work unchanged on later Perls too.

      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.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://939480]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (7)
As of 2014-09-17 06:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (60 votes), past polls