| 1 |
.\" -*- mode: troff; coding: utf-8 -*- |
| 2 |
.\" Automatically generated by Pod::Man 5.0102 (Pod::Simple 3.45) |
| 3 |
.\" |
| 4 |
.\" Standard preamble: |
| 5 |
.\" ======================================================================== |
| 6 |
.de Sp \" Vertical space (when we can't use .PP) |
| 7 |
.if t .sp .5v |
| 8 |
.if n .sp |
| 9 |
.. |
| 10 |
.de Vb \" Begin verbatim text |
| 11 |
.ft CW |
| 12 |
.nf |
| 13 |
.ne \\$1 |
| 14 |
.. |
| 15 |
.de Ve \" End verbatim text |
| 16 |
.ft R |
| 17 |
.fi |
| 18 |
.. |
| 19 |
.\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. |
| 20 |
.ie n \{\ |
| 21 |
. ds C` "" |
| 22 |
. ds C' "" |
| 23 |
'br\} |
| 24 |
.el\{\ |
| 25 |
. ds C` |
| 26 |
. ds C' |
| 27 |
'br\} |
| 28 |
.\" |
| 29 |
.\" Escape single quotes in literal strings from groff's Unicode transform. |
| 30 |
.ie \n(.g .ds Aq \(aq |
| 31 |
.el .ds Aq ' |
| 32 |
.\" |
| 33 |
.\" If the F register is >0, we'll generate index entries on stderr for |
| 34 |
.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index |
| 35 |
.\" entries marked with X<> in POD. Of course, you'll have to process the |
| 36 |
.\" output yourself in some meaningful fashion. |
| 37 |
.\" |
| 38 |
.\" Avoid warning from groff about undefined register 'F'. |
| 39 |
.de IX |
| 40 |
.. |
| 41 |
.nr rF 0 |
| 42 |
.if \n(.g .if rF .nr rF 1 |
| 43 |
.if (\n(rF:(\n(.g==0)) \{\ |
| 44 |
. if \nF \{\ |
| 45 |
. de IX |
| 46 |
. tm Index:\\$1\t\\n%\t"\\$2" |
| 47 |
.. |
| 48 |
. if !\nF==2 \{\ |
| 49 |
. nr % 0 |
| 50 |
. nr F 2 |
| 51 |
. \} |
| 52 |
. \} |
| 53 |
.\} |
| 54 |
.rr rF |
| 55 |
.\" ======================================================================== |
| 56 |
.\" |
| 57 |
.IX Title "Net::netent 3perl" |
| 58 |
.TH Net::netent 3perl 2025-11-16 "perl v5.40.1" "Perl Programmers Reference Guide" |
| 59 |
.\" For nroff, turn off justification. Always turn off hyphenation; it makes |
| 60 |
.\" way too many mistakes in technical documents. |
| 61 |
.if n .ad l |
| 62 |
.nh |
| 63 |
.SH NAME |
| 64 |
Net::netent \- by\-name interface to Perl's built\-in getnet*() functions |
| 65 |
.SH SYNOPSIS |
| 66 |
.IX Header "SYNOPSIS" |
| 67 |
.Vb 3 |
| 68 |
\& use Net::netent qw(:FIELDS); |
| 69 |
\& getnetbyname("loopback") or die "bad net"; |
| 70 |
\& printf "%s is %08X\en", $n_name, $n_net; |
| 71 |
\& |
| 72 |
\& use Net::netent; |
| 73 |
\& |
| 74 |
\& $n = getnetbyname("loopback") or die "bad net"; |
| 75 |
\& { # there\*(Aqs gotta be a better way, eh? |
| 76 |
\& @bytes = unpack("C4", pack("N", $n\->net)); |
| 77 |
\& shift @bytes while @bytes && $bytes[0] == 0; |
| 78 |
\& } |
| 79 |
\& printf "%s is %08X [%d.%d.%d.%d]\en", $n\->name, $n\->net, @bytes; |
| 80 |
.Ve |
| 81 |
.SH DESCRIPTION |
| 82 |
.IX Header "DESCRIPTION" |
| 83 |
This module's default exports override the core \fBgetnetbyname()\fR and |
| 84 |
\&\fBgetnetbyaddr()\fR functions, replacing them with versions that return |
| 85 |
"Net::netent" objects. This object has methods that return the similarly |
| 86 |
named structure field name from the C's netent structure from \fInetdb.h\fR; |
| 87 |
namely name, aliases, addrtype, and net. The aliases |
| 88 |
method returns an array reference, the rest scalars. |
| 89 |
.PP |
| 90 |
You may also import all the structure fields directly into your namespace |
| 91 |
as regular variables using the :FIELDS import tag. (Note that this still |
| 92 |
overrides your core functions.) Access these fields as variables named |
| 93 |
with a preceding \f(CW\*(C`n_\*(C'\fR. Thus, \f(CW\*(C`$net_obj\->name()\*(C'\fR corresponds to |
| 94 |
\&\f(CW$n_name\fR if you import the fields. Array references are available as |
| 95 |
regular array variables, so for example \f(CW\*(C`@{ $net_obj\->aliases() |
| 96 |
}\*(C'\fR would be simply \f(CW@n_aliases\fR. |
| 97 |
.PP |
| 98 |
The \fBgetnet()\fR function is a simple front-end that forwards a numeric |
| 99 |
argument to \fBgetnetbyaddr()\fR, and the rest |
| 100 |
to \fBgetnetbyname()\fR. |
| 101 |
.PP |
| 102 |
To access this functionality without the core overrides, |
| 103 |
pass the \f(CW\*(C`use\*(C'\fR an empty import list, and then access |
| 104 |
function functions with their full qualified names. |
| 105 |
On the other hand, the built-ins are still available |
| 106 |
via the \f(CW\*(C`CORE::\*(C'\fR pseudo-package. |
| 107 |
.SH EXAMPLES |
| 108 |
.IX Header "EXAMPLES" |
| 109 |
The \fBgetnet()\fR functions do this in the Perl core: |
| 110 |
.PP |
| 111 |
.Vb 1 |
| 112 |
\& sv_setiv(sv, (I32)nent\->n_net); |
| 113 |
.Ve |
| 114 |
.PP |
| 115 |
The \fBgethost()\fR functions do this in the Perl core: |
| 116 |
.PP |
| 117 |
.Vb 1 |
| 118 |
\& sv_setpvn(sv, hent\->h_addr, len); |
| 119 |
.Ve |
| 120 |
.PP |
| 121 |
That means that the address comes back in binary for the |
| 122 |
host functions, and as a regular perl integer for the net ones. |
| 123 |
This seems a bug, but here's how to deal with it: |
| 124 |
.PP |
| 125 |
.Vb 3 |
| 126 |
\& use strict; |
| 127 |
\& use Socket; |
| 128 |
\& use Net::netent; |
| 129 |
\& |
| 130 |
\& @ARGV = (\*(Aqloopback\*(Aq) unless @ARGV; |
| 131 |
\& |
| 132 |
\& my($n, $net); |
| 133 |
\& |
| 134 |
\& for $net ( @ARGV ) { |
| 135 |
\& |
| 136 |
\& unless ($n = getnetbyname($net)) { |
| 137 |
\& warn "$0: no such net: $net\en"; |
| 138 |
\& next; |
| 139 |
\& } |
| 140 |
\& |
| 141 |
\& printf "\en%s is %s%s\en", |
| 142 |
\& $net, |
| 143 |
\& lc($n\->name) eq lc($net) ? "" : "*really* ", |
| 144 |
\& $n\->name; |
| 145 |
\& |
| 146 |
\& print "\etaliases are ", join(", ", @{$n\->aliases}), "\en" |
| 147 |
\& if @{$n\->aliases}; |
| 148 |
\& |
| 149 |
\& # this is stupid; first, why is this not in binary? |
| 150 |
\& # second, why am i going through these convolutions |
| 151 |
\& # to make it looks right |
| 152 |
\& { |
| 153 |
\& my @a = unpack("C4", pack("N", $n\->net)); |
| 154 |
\& shift @a while @a && $a[0] == 0; |
| 155 |
\& printf "\etaddr is %s [%d.%d.%d.%d]\en", $n\->net, @a; |
| 156 |
\& } |
| 157 |
\& |
| 158 |
\& if ($n = getnetbyaddr($n\->net)) { |
| 159 |
\& if (lc($n\->name) ne lc($net)) { |
| 160 |
\& printf "\etThat addr reverses to net %s!\en", $n\->name; |
| 161 |
\& $net = $n\->name; |
| 162 |
\& redo; |
| 163 |
\& } |
| 164 |
\& } |
| 165 |
\& } |
| 166 |
.Ve |
| 167 |
.SH NOTE |
| 168 |
.IX Header "NOTE" |
| 169 |
While this class is currently implemented using the Class::Struct |
| 170 |
module to build a struct-like class, you shouldn't rely upon this. |
| 171 |
.SH AUTHOR |
| 172 |
.IX Header "AUTHOR" |
| 173 |
Tom Christiansen |