1Socket::GetAddrInfo::StUrsiecrt(C3o)ntributed Perl DocumSeonctkaetti:o:nGetAddrInfo::Strict(3)
2
3
4

NAME

6       "Socket::GetAddrInfo::Strict" - Provide Socket::GetAddrInfo functions
7       which throw exceptions
8

SYNOPSIS

10        use Socket qw( SOCK_STREAM );
11        use Socket::GetAddrInfo::Strict qw( getaddrinfo getnameinfo );
12        use IO::Socket;
13
14        my $sock;
15
16        my %hints = ( socktype => SOCK_STREAM );
17        my @res = getaddrinfo( "www.google.com", "www", \%hints );
18
19        while( my $ai = shift @res ) {
20
21           $sock = IO::Socket->new();
22           $sock->socket( $ai->{family}, $ai->{socktype}, $ai->{protocol} ) or
23              undef $sock, next;
24
25           $sock->connect( $ai->{addr} ) or undef $sock, next;
26
27           last;
28        }
29
30        if( $sock ) {
31           my ( $host, $service ) = getnameinfo( $sock->peername );
32           print "Connected to $host:$service\n";
33        }
34

DESCRIPTION

36       Socket::GetAddrInfo provides the functions of "getaddrinfo" and
37       "getnameinfo", which return lists whose first element is error value,
38       or false indicating no error occured.
39
40       This module wraps the functions provided by "Socket::GetAddrInfo" to
41       check this error value, and throw an exception (using "die") if an
42       error occured.  If not, then the remaining values are returned as
43       normal. This can simplify the logic of a program which otherwise simply
44       throws its own exception on failure anyway.
45

FUNCTIONS

47   @res = getaddrinfo( $host, $service, $hints )
48       After a successful lookup, returns the list of address structures, as
49       documented in Socket::GetAddrInfo. If the lookup fails, an exception
50       containing the string form of the error is thrown instead.
51
52   ( $host, $service ) = getnameinfo( $addr, $flags, $xflags )
53       After a successful lookup, returns the host and service name, as
54       documented in Socket::GetAddrInfo. If the lookup fails, an exception
55       containing the string form of the error is thrown instead.
56

AUTHOR

58       Paul Evans <leonerd@leonerd.org.uk>
59
60
61
62perl v5.36.0                      2022-07-22    Socket::GetAddrInfo::Strict(3)
Impressum