Socket::GetAddrInfo - a wrapper for Socket6's getaddrinfo and getaddrinfo, or emulation for platforms that do not support it
Socket::GetAddrInfo
getaddrinfo
use Socket::GetAddrInfo qw( getaddrinfo getnameinfo ); use IO::Socket; my $sock; my @res = getaddrinfo( "www.google.com", "www" ); while( @res >= 5 ) { my ( $family, $socktype, $proto, $addr, $canonname ) = splice @res, 0, 5; $sock = IO::Socket->new(); $sock->socket( $family, $socktype, $proto ) or next; $sock->connect( $addr ) or next; } if( $sock ) { my ( $host, $service ) = getnameinfo( $sock->peername ); print "Connected to $host:$service\n"; }
This module provides access to the getaddrinfo and getnameinfo functions of Socket6 on systems that have Socket6 installed, or provides emulations of them using the "legacy" functions such as gethostbyname() on systems that do not.
getnameinfo
Socket6
gethostbyname()
These emulations are not a complete replacement of Socket6, because they only support IPv4 (the AF_INET socket family). They do, however, implement the same interface as the Socket6 functions, so any code written to use this module can be used on systems that do not support Socket6, but will automatically make use of the extended abilities of Socket6 on systems that do support it.
AF_INET
If $family is supplied, it must be AF_INET. Any other value will result in an error thrown by croak.
$family
croak
The only supported $flags values are AI_PASSIVE, AI_CANONNAME and AI_NUMERICHOST.
$flags
AI_PASSIVE
AI_CANONNAME
AI_NUMERICHOST
If the sockaddr family of $addr is AF_INET, an error will be thrown with croak.
$addr
The only supported $flags values are NI_NUMERICHOST, NI_NUMERICSERV, NI_NAMEREQD and NI_DGRAM.
NI_NUMERICHOST
NI_NUMERICSERV
NI_NAMEREQD
NI_DGRAM
Socket6 - IPv6 related part of the C socket.h defines and structure manipulators
Paul Evans <leonerd@leonerd.org.uk>
To install Socket::GetAddrInfo, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Socket::GetAddrInfo
CPAN shell
perl -MCPAN -e shell install Socket::GetAddrInfo
For more information on module installation, please visit the detailed CPAN module installation guide.