in reply to Re: perl and getaddrinfo API
in thread perl and getaddrinfo API

Thanks for pointing out to problem. about the legacy subroutine i tried the new codes.
use Socket qw(:addrinfo SOCK_RAW); my ($err, @res) = getaddrinfo($hostname, "", {socktype => SOCK_RAW}); die "Cannot getaddrinfo - $err" if $err; while( my $ai = shift @res ) { my ($err, $ipaddr) = getnameinfo($ai->{addr}, NI_NUMERICHOST, NIx +_NOSERV); die "Cannot getnameinfo - $err" if $err; print "$ipaddr\n"; }

copied from http://perldoc.perl.org/Socket.html#(%24err%2c-%40result)-%3d-getaddrinfo-%24host%2c-%24service%2c-%5b%24hints%5d

it gives me error "addrinfo not defined in %Socket::EXPORT_TAGS

perl i am using is 5.8.4. is this because of perl version i am using? or it is something else?

Replies are listed 'Best First'.
Re^3: perl and getaddrinfo API
by Athanasius (Archbishop) on Apr 20, 2016 at 12:47 UTC

    Perl 5.8 is very old. Whether that’s the problem I don’t know; but when I add a line defining $hostname to the code you posted:

    #! perl use strict; use warnings; use Socket qw(:addrinfo SOCK_RAW); my $hostname = 'perlmonks.pair.com'; my ($err, @res) = getaddrinfo($hostname, "", { socktype => SOCK_RAW }) +; die "Cannot getaddrinfo - $err" if $err; while (my $ai = shift @res) { my ($err, $ipaddr) = getnameinfo($ai->{addr}, NI_NUMERICHOST, NIx_ +NOSERV); die "Cannot getnameinfo - $err" if $err; print "$ipaddr\n"; }

    it works correctly on my system:

    22:41 >perl 1602_SoPW.pl 209.197.123.153 22:42 >

    (Windows 8.1 64-bit, Strawberry Perl 5.22.1, Socket v2.021.)

    Hope that helps,

    Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

Re^3: perl and getaddrinfo API
by VinsWorldcom (Prior) on Apr 20, 2016 at 17:29 UTC

    Yes, the old Perl version is the problem. The core Socket module didn't start supporting IPv6 (and the address family independent routines get*info()) until at least 5.14 or so.

    Socket is now dual-lived so you can get the latest copy from CPAN, but not sure how a new version of Socket will work on such an old Perl.

    You could try Socket6 and / or Socket::GetAddrInfo. I've used in the past and the API was a bit different than the "standard" supplied directly in the new Socket module versions.