NAME
Socket::GetAddrInfo
- a wrapper for Socket6's getaddrinfo
and getaddrinfo
, or emulation for platforms that do not support it
SYNOPSIS
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";
}
DESCRIPTION
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.
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.
LIMITS OF EMULATION
@res = getaddrinfo( $node, $service, $family, $socktype, $protocol, $flags )
If
$family
is supplied, it must beAF_INET
. Any other value will result in an error thrown bycroak
.The only supported
$flags
values areAI_PASSIVE
,AI_CANONNAME
andAI_NUMERICHOST
.
( $node, $service ) = getnameinfo( $addr, $flags )
If the sockaddr family of
$addr
isAF_INET
, an error will be thrown withcroak
.The only supported
$flags
values areNI_NUMERICHOST
,NI_NUMERICSERV
,NI_NAMEREQD
andNI_DGRAM
.
SEE ALSO
Socket6 - IPv6 related part of the C socket.h defines and structure manipulators
AUTHOR
Paul Evans <leonerd@leonerd.org.uk>