Socket...ket6api(3pm)
π Socket::GetAddrInfo::Socket6api(3pm) π
okay bestie, welcome to the manual page for Socket::GetAddrInfo::Socket6api β it's a Perl module, it's in the 3pm section (User Contributed Perl Documentation, if you're being fancy about it), and it's genuinely so useful. sit with me, we're doing this. π«Ά
β¨ NAME β¨
Socket::GetAddrInfo::Socket6api β it gives you all the Socket::GetAddrInfo functions but dressed in the Socket6 API instead. glow up, but make it backwards compatible. π
πΈ SYNOPSIS πΈ
here's the whole vibe, copy-paste ready:
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;
}
likeβ¦ it resolves the name, walks the results, connects to the first one that actually works, and then tells you who you're talking to. main character energy, no notes. π
π¦ DESCRIPTION π¦
okay so, context. Socket::GetAddrInfo gives you the functions getaddrinfo and getnameinfo with a very cute interface β hints and address structures are represented as hashes, which is honestly so readable.
Socket6 also provides these functions, but its whole thing is taking and returning flat lists of values instead.
So what does this module do? It wraps the functions that Socket::GetAddrInfo provides, and serves them up in an API that's identical to Socket6. The whole point is that existing code written for the Socket6 API can justβ¦ use these functions instead. a drop-in situation. the way that it just works. πβ¨
π FUNCTIONS π
π @res = getaddrinfo( $host, $service, $family, $socktype, $protocol, $flags )
@res = getaddrinfo( $host, $service, $family, $socktype, $protocol, $flags )
so in this version of the API, the hints values come in as separate ordered parameters. very demure, very mindful, very positional.
β οΈ any parameter you don't wanna specify? pass it as0. don't leave it out, pass the literal0. bestie I'm serious.
if it succeeds, you get back a flat list β and here's the math: five values for every address structure returned. every group of five has, in this exact order:
- the
family - the
socktype - the
protocol - the
addr - the
canonname
if it's not successful, it returns a single value containing the string error message. and listen β to stay compatible with the Socket6 interface, that value does not have the error integer part. that's just how it is. π
π ( $host, $service ) = getnameinfo( $addr, $flags )
( $host, $service ) = getnameinfo( $addr, $flags )
this version of the API returns only the host name and the service name, and only if it resolved successfully. slay.
on error? it returns an empty list. and again, for Socket6 compatibility, no error information will be supplied. so likeβ¦ no error message, no integer, nothing. just vibes and silence. π
π AUTHOR π
Paul Evans <leonerd@leonerd.org.uk> β the icon, the moment, the legend. π
and that's the whole page, bestie!! this was perl v5.40.0, dated 2025-02-01, from the Socket...ket6api(3pm) manual. go forth and resolve some names, you've got this. ππ¦π
π¦ where this page comes from
- debian trixie: libsocket-getaddrinfo-perl 0.22-6 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libsocket-getaddrinfo-perl 0.22-6 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libsocket-getaddrinfo-perl 0.22-6 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms