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 be AF_INET. Any other value will result in an error thrown by croak.

  • The only supported $flags values are AI_PASSIVE, AI_CANONNAME and AI_NUMERICHOST.

( $node, $service ) = getnameinfo( $addr, $flags )

  • If the sockaddr family of $addr is AF_INET, an error will be thrown with croak.

  • The only supported $flags values are NI_NUMERICHOST, NI_NUMERICSERV, NI_NAMEREQD and NI_DGRAM.

SEE ALSO

  • Socket6 - IPv6 related part of the C socket.h defines and structure manipulators

AUTHOR

Paul Evans <leonerd@leonerd.org.uk>