addrinfo(3)

πŸ“¦
version 2.2.3 Β· 3 versions
, in arch rolling

addrinfo(3) πŸ’…βœ¨

okay so bestie, this is addrinfo(3) from the User Contributed Perl Documentation section, and it's lowkey iconic for anyone messing with Perl + POSIX name-resolution vibes. no cap.

🌸 NAME 🌸

Net::addrinfo β€” an interface to POSIX getaddrinfo(3) and related constants, structures and functions. It's giving C-API energy but make it Perl 🫢.

✨ SYNOPSIS ✨

use Net::addrinfo;
my $ainfo = getaddrinfo("www.marzot.net");

πŸ’… DESCRIPTION πŸ’…

This Perl module is designed to implement and export functionality related to the POSIX getaddrinfo(3) system call. The Net::addrinfo data object comes with field-name accessor functions β€” yes, named similarly to the C data structure definition in netdb.h. The getaddrinfo(3), gai_strerror(3) calls, and related constants are exported. Periodt.

The getaddrinfo() routine mimics the POSIX documented function (peep the system man page getaddrinfo(3)). On success, getaddrinfo() returns an array of Net::addrinfo data objects. In scalar context, getaddrinfo() returns the first element from the Net::addrinfo array. In case of error, a numeric error code is returned. That error code may be passed to gai_strerror() to get a string representation of the error. So useful, fr fr.

New Net::addrinfo objects may be created with the package constructor, and any number (or none) of the fields may be specified:

          flags => scalar integer
          family => scalar integer (e.g., AF_INET,m AF_INET6, etc.)
          socktype => scalar integer (e.g., SOCK_DGRAM, SOCK_STREAM, etc.)
          protocol => scalar integer (e.g., IPPROTO_UDP, IPPROTO_TCP, etc.)
          addrlen => scalar integer (can be computed by length($self->addr))
          addr => packed bytes (e.g., $self->addr(inet_aton("192.168.1.1")); )

Flags may be set in the structure so that it may be used as a 'hint' parameter to the getaddrinfo() function. Peep exported @AI_FLAGS for the list of acceptable constants.

πŸ™ˆ tiny but important note: a special scalar integer field, val_status, is provided in support of DNSSEC aware addrinfo results (see Net::DNS::SEC::Validator). iykyk.

πŸŽ€ EXAMPLES πŸŽ€

        use Net::addrinfo;
        use Socket qw(:all);

        my $hint = new Net::addrinfo(flags => AI_CANONNAME,
                                     family => AF_INET,
                                     socktype => SOCK_DGRAM);

        my (@ainfo) = getaddrinfo("www.marzot.net", "http", $hint);

        foreach $ainfo (@ainfo) {
           if (ref $ainfo eq 'Net::addrinfo') {
              print $ainfo->stringify(), "\n";
              print "addr = ", inet_ntoa($ainfo->addr), "\n";
              ...
              connect(SH, $ainfo->addr);
            } else {
               print "Error($ainfo):", gai_strerror($ainfo), "\n";
            }
        }

πŸ™ˆ NOTE πŸ™ˆ

One should not rely on the internal representation of this class. Like, do not go poking around in there, bestie β€” treat it as a vibe, not a stable layout πŸ’€.

πŸ‘‘ AUTHOR πŸ‘‘

G. S. Marzot (marz@users.sourceforge.net) β€” iconic behavior.

Copyright (c) 2006 G. S. Marzot. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

Copyright (c) 2006-2008 SPARTA, Inc. All Rights Reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.


πŸ’– and that's the page, bestie: this one is from perl v5.44.0, dated 2026-10-17, and it's the addrinfo(3) manual β€” go be the main character of your terminal πŸŒˆπŸŽ€

πŸ“¦ where this page comes from