Net::protoent(3perl)
π Net::protoent β the by-name bestie interface to Perl's built-in getproto*() functions π
okay so. bestie. you know how Perl has those built-in getproto*() functions? yeah. this module is the by-name interface to them. that's the whole vibe. it's in the Perl Programmers Reference Guide, section 3perl. let's GO. π¦
β¨ SYNOPSIS β¨
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";
like. look at it. two whole moods. one where you get a cute object back, one where the fields just appear in your namespace. both slay. π
πΈ DESCRIPTION πΈ
So here's the tea, bestie. This module's default exports override the core getprotoent(), getprotobyname(), and getnetbyport() functions. Yes, really. They get replaced with versions that hand you back "Net::protoent" objects instead of the plain old stuff. Iconic behaviour, tbh.
They take default second arguments of "tcp". So if you don't pass anything, tcp is what you get. defaults are giving convenient.
Now the object itself β it has methods that return the similarly named structure field name from the C's protoent structure from netdb.h. Namely:
namealiasesproto
The aliases method returns an array reference. The rest are scalars. that's the whole division of labour. no notes. π
π«Ά the :FIELDS import tag π«Ά
You may also import all the structure fields directly into your namespace as regular variables using the :FIELDS import tag. And ngl, heads up: this still overrides your core functions. the tag doesn't undo that. it's a package deal, fr fr.
Access these fields as variables named with a preceding "p_". So like:
"$proto_obj->name()"corresponds to$p_nameif you import the fields- Array references are available as regular array variables, so for example
"@{ $proto_obj->aliases() }"would be simply@p_aliases
the shorthand is giving main character energy. π
π§ the getproto() front-end π§
The getproto() function is a simple front-end that:
- forwards a numeric argument to
getprotobyport() - and forwards the rest to
getprotobyname()
just a lil dispatcher doing its thing. π«
π but what if I don't want my core overridden π
valid. 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. Good news though β the built-ins are still available via the "CORE::" pseudo-package. they're not gone, they're just chilling in a different namespace. safe. π
π NOTE π
While this class is currently implemented using the Class::Struct module to build a struct-like class, you shouldn't rely upon this.
like, it's an implementation detail, bestie. do not build your whole personality on it. π
β AUTHOR β
Tom Christiansen β king behaviour, honestly. π«Ά
and that's the whole page!! no cap, every option, every field, every caveat, all accounted for. π
perl v5.44.0 Β· 2026-10-17 Β· Net::protoent(3perl) β that's the version, the date, and where you found it. stan a manual page that tells you when it was written. mwah. πβ¨π¦πΈπ
π¦ where this page comes from
- arch rolling: perl 5.44.0-1 Β· Artistic-1.0-Perl AND 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