/usr/share/perl5/Socket/GetAddrInfo/Socket6api.pm is in libsocket-getaddrinfo-perl 0.20-2build2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 | # You may distribute under the terms of either the GNU General Public License
# or the Artistic License (the same terms as Perl itself)
#
# (C) Paul Evans, 2010 -- leonerd@leonerd.org.uk
package Socket::GetAddrInfo::Socket6api;
use strict;
use warnings;
use Carp;
our $VERSION = '0.20';
use Exporter 'import';
our @EXPORT = qw(
getaddrinfo
getnameinfo
);
use Socket::GetAddrInfo ();
# Re-export all the AI_*, EAI_* and NI_* constants
my @constants = grep m/^(E?A|N)I_/, @Socket::GetAddrInfo::EXPORT;
push @EXPORT, @constants;
Socket::GetAddrInfo->import( @constants );
=head1 NAME
C<Socket::GetAddrInfo::Socket6api> - Provide L<Socket::GetAddrInfo> functions
using L<Socket6> API
=head1 SYNOPSIS
use Socket qw( AF_UNSPEC SOCK_STREAM );
use Socket::GetAddrInfo::Socket6api qw( getaddrinfo getnameinfo );
my $sock;
my @res = getaddrinfo( "www.google.com", "www", AF_UNSPEC, SOCK_STREAM );
die "Cannot resolve name - $res[0]" if @res == 1;
while( @res >= 5 ) {
my ( $family, $socktype, $protocol, $addr, undef ) = splice @res, 0, 5, ();
$sock = IO::Socket->new();
$sock->socket( $family, $socktype, $protocol ) or
undef $sock, next;
$sock->connect( $addr ) or undef $sock, next;
last;
}
if( $sock ) {
my ( $host, $service ) = getnameinfo( $sock->peername );
print "Connected to $host:$service\n" if defined $host;
}
=head1 DESCRIPTION
L<Socket::GetAddrInfo> provides the RFC 2553-specified functions of
C<getaddrinfo> and C<getnameinfo>, using a convenient interface where hints
and address structures are represented as hashes. L<Socket6> also provides
these functions, in a form taking and returning flat lists of values.
This module wraps the functions provided by C<Socket::GetAddrInfo> to provide
them in an identical API to C<Socket6>. It is intended to stand as a utility
for existing code written for the C<Socket6> API to use these functions
instead.
These functions can also be obtained by importing from C<Socket::GetAddrInfo>
using a special tag:
use Socket::GetAddrInfo qw( :Socket6api getaddrinfo );
=cut
=head1 FUNCTIONS
=cut
=head2 @res = getaddrinfo( $host, $service, $family, $socktype, $protocol, $flags )
This version of the API takes the hints values as separate ordered parameters.
Unspecified parameters should be passed as C<0>.
If successful, this function returns a flat list of values, five for each
returned address structure. Each group of five elements will contain, in
order, the C<family>, C<socktype>, C<protocol>, C<addr> and C<canonname>
values of the address structure.
If unsuccessful, it will return a single value, containing the string error
message. To remain compatible with the C<Socket6> interface, this value does
not have the error integer part.
=cut
sub getaddrinfo
{
@_ >= 2 and @_ <= 6 or
croak "Usage: getaddrinfo(host, service, family=0, socktype=0, protocol=0, flags=0)";
my ( $host, $service, $family, $socktype, $protocol, $flags ) = @_;
my ( $err, @res ) = Socket::GetAddrInfo::getaddrinfo( $host, $service, {
flags => $flags || 0,
family => $family || 0,
socktype => $socktype || 0,
protocol => $protocol || 0,
} );
return "$err" if $err;
return map { $_->{family}, $_->{socktype}, $_->{protocol}, $_->{addr}, $_->{canonname} } @res;
}
=head2 ( $host, $service ) = getnameinfo( $addr, $flags )
This version of the API returns only the host name and service name, if
successfully resolved. On error, it will return an empty list. To remain
compatible with the C<Socket6> interface, no error information will be
supplied.
=cut
sub getnameinfo
{
@_ >= 1 and @_ <= 2 or
croak "Usage: getnameinfo(addr, flags=0)";
my ( $addr, $flags ) = @_;
my ( $err, $host, $service ) = Socket::GetAddrInfo::getnameinfo( $addr, $flags );
return () if $err;
return ( $host, $service );
}
# Keep perl happy; keep Britain tidy
1;
__END__
=head1 AUTHOR
Paul Evans <leonerd@leonerd.org.uk>
|