Socket::GetAddrInfo::Strict(3pm)

Socket::GetAddrInfo::Strict3pm

Provide socket::getaddrinfo functions which throw exceptions

Usage

 use Socket qw( SOCK_STREAM );
 use Socket::GetAddrInfo::Strict qw( getaddrinfo getnameinfo );
 use IO::Socket;
 my $sock;
 my %hints = ( socktype => SOCK_STREAM );
 my @res = getaddrinfo( "www.google.com", "www", \%hints );
 while( my $ai = shift @res ) {
    $sock = IO::Socket->new();
    $sock->socket( $ai->{family}, $ai->{socktype}, $ai->{protocol} ) or
       undef $sock, next;
    $sock->connect( $ai->{addr} ) or undef $sock, next;
    last;
 }
 if( $sock ) {
    my ( $host, $service ) = getnameinfo( $sock->peername );
    print "Connected to $host:$service\n";
 }

Overview

Socket::GetAddrInfo provides the functions of "getaddrinfo" and "getnameinfo", which return lists whose first element is error value, or false indicating no error occurred.

This module wraps the functions provided by "Socket::GetAddrInfo" to check this error value, and throw an exception (using "die") if an error occurred. If not, then the remaining values are returned as normal. This can simplify the logic of a program which otherwise simply throws its own exception on failure anyway.

Functions

@res = getaddrinfo( $host, $service, $hints )

After a successful lookup, returns the list of address structures, as documented in Socket::GetAddrInfo. If the lookup fails, an exception containing the string form of the error is thrown instead.

( $host, $service ) = getnameinfo( $addr, $flags, $xflags )

After a successful lookup, returns the host and service name, as documented in Socket::GetAddrInfo. If the lookup fails, an exception containing the string form of the error is thrown instead.

Releases

7 releases since Debian 7 (Wheezy); the text changed 4 times.

  1. 7
  2. 8
  3. 9–11
  4. 12
  5. 13

Author

Paul Evans <[email protected]>

From libsocket-getaddrinfo-perl 0.22-6 in Debian 13 (Trixie). Parsed by carta from the page's man source.