Net::protoent(3pm)

✨ Net::protoent ✨

okay so bestie, welcome to the Net::protoent(3pm) page from the Perl Programmers Reference Guide β€” it's literally the by-name interface to Perl's built-in getproto*() functions. vibe check passed, let's go πŸ’…


πŸ’– NAME πŸ’–

Net::protoent β€” by-name interface to Perl's built-in getproto*() functions. periodt.

🌸 SYNOPSIS 🌸

here's the code, exactly as it's giving:

use Net::protoent;
my $p = getprotobyname(shift || 'tcp') || die "no proto";
printf "proto for %s is %d, aliases are %s\n",
   $p->name, $p->proto, "@{$p->aliases}";

use Net::protoent qw(:FIELDS);
getprotobyname(shift || 'tcp') || die "no proto";
print "proto for $p_name is $p_proto, aliases are @p_aliases\n";

πŸ¦‹ DESCRIPTION πŸ¦‹

okay so the default exports of this module override the core getprotoent(), getprotobyname(), and getnetbyport() functions β€” they replace them with versions that return Net::protoent objects. they take default second arguments of "tcp". this object has methods that return the similarly named structure field name from the C's protoent structure from netdb.h; namely name, aliases, and proto. the aliases method returns an array reference, the rest scalars. iykyk ✨

You may also import all the structure fields directly into your namespace as regular variables using the :FIELDS import tag. (note that this still overrides your core functions.) access these fields as variables named with a preceding p_. thus, $proto_obj->name() corresponds to $p_name if you import the fields. array references are available as regular array variables, so for example @{ $proto_obj->aliases() } would be simply @p_aliases. 🫢

The getproto() function is a simple front-end that forwards a numeric argument to getprotobyport(), and the rest to getprotobyname(). that's the exact function name on the page, bestie πŸ’€

To access this functionality without the core overrides, pass the use an empty import list, and then access function functions with their full qualified names. on the other hand, the built-ins are still available via the CORE:: pseudo-package. main character energy, no cap πŸ”₯

🧚 NOTE 🧚

while this class is currently implemented using the Class::Struct module to build a struct-like class, you shouldn't rely upon this. ngl, don't build your whole personality on that implementation detail β€” it could change πŸ’€

πŸ‘‘ AUTHOR πŸ‘‘

Tom Christiansen πŸ’–


mwah πŸ’‹ this page is from perl v5.42.3, dated 2026-11-03, and it's the Net::protoent(3pm) page. bye bestie 🫢

πŸ“¦ where this page comes from