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 as 0. don't leave it out, pass the literal 0. 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:

  1. the family
  2. the socktype
  3. the protocol
  4. the addr
  5. 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