Debian Codegraph @

upstream/mageia-cauldron/man3pm/Net::netent.3pm

raw
1 .\" -*- mode: troff; coding: utf-8 -*-
2 .\" Automatically generated by Pod::Man v6.0.2 (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 .\" Required to disable full justification in groff 1.23.0.
57 .if n .ds AD l
58 .\" ========================================================================
59 .\"
60 .IX Title "Net::netent 3pm"
61 .TH Net::netent 3pm 2023-12-22 "perl v5.42.0" "Perl Programmers Reference Guide"
62 .\" For nroff, turn off justification. Always turn off hyphenation; it makes
63 .\" way too many mistakes in technical documents.
64 .if n .ad l
65 .nh
66 .SH NAME
67 Net::netent \- by\-name interface to Perl\*(Aqs built\-in getnet*() functions
68 .SH SYNOPSIS
69 .IX Header "SYNOPSIS"
70 .Vb 3
71 \& use Net::netent qw(:FIELDS);
72 \& getnetbyname("loopback") or die "bad net";
73 \& printf "%s is %08X\en", $n_name, $n_net;
74 \&
75 \& use Net::netent;
76 \&
77 \& $n = getnetbyname("loopback") or die "bad net";
78 \& { # there\*(Aqs gotta be a better way, eh?
79 \& @bytes = unpack("C4", pack("N", $n\->net));
80 \& shift @bytes while @bytes && $bytes[0] == 0;
81 \& }
82 \& printf "%s is %08X [%d.%d.%d.%d]\en", $n\->name, $n\->net, @bytes;
83 .Ve
84 .SH DESCRIPTION
85 .IX Header "DESCRIPTION"
86 This module\*(Aqs default exports override the core \fBgetnetbyname()\fR and
87 \&\fBgetnetbyaddr()\fR functions, replacing them with versions that return
88 "Net::netent" objects. This object has methods that return the similarly
89 named structure field name from the C\*(Aqs netent structure from \fInetdb.h\fR;
90 namely name, aliases, addrtype, and net. The aliases
91 method returns an array reference, the rest scalars.
92 .PP
93 You may also import all the structure fields directly into your namespace
94 as regular variables using the :FIELDS import tag. (Note that this still
95 overrides your core functions.) Access these fields as variables named
96 with a preceding \f(CW\*(C`n_\*(C'\fR. Thus, \f(CW\*(C`$net_obj\->name()\*(C'\fR corresponds to
97 \&\f(CW$n_name\fR if you import the fields. Array references are available as
98 regular array variables, so for example \f(CW\*(C`@{ $net_obj\->aliases()
99 }\*(C'\fR would be simply \f(CW@n_aliases\fR.
100 .PP
101 The \fBgetnet()\fR function is a simple front\-end that forwards a numeric
102 argument to \fBgetnetbyaddr()\fR, and the rest
103 to \fBgetnetbyname()\fR.
104 .PP
105 To access this functionality without the core overrides,
106 pass the \f(CW\*(C`use\*(C'\fR an empty import list, and then access
107 function functions with their full qualified names.
108 On the other hand, the built\-ins are still available
109 via the \f(CW\*(C`CORE::\*(C'\fR pseudo\-package.
110 .SH EXAMPLES
111 .IX Header "EXAMPLES"
112 The \fBgetnet()\fR functions do this in the Perl core:
113 .PP
114 .Vb 1
115 \& sv_setiv(sv, (I32)nent\->n_net);
116 .Ve
117 .PP
118 The \fBgethost()\fR functions do this in the Perl core:
119 .PP
120 .Vb 1
121 \& sv_setpvn(sv, hent\->h_addr, len);
122 .Ve
123 .PP
124 That means that the address comes back in binary for the
125 host functions, and as a regular perl integer for the net ones.
126 This seems a bug, but here\*(Aqs how to deal with it:
127 .PP
128 .Vb 3
129 \& use strict;
130 \& use Socket;
131 \& use Net::netent;
132 \&
133 \& @ARGV = (\*(Aqloopback\*(Aq) unless @ARGV;
134 \&
135 \& my($n, $net);
136 \&
137 \& for $net ( @ARGV ) {
138 \&
139 \& unless ($n = getnetbyname($net)) {
140 \& warn "$0: no such net: $net\en";
141 \& next;
142 \& }
143 \&
144 \& printf "\en%s is %s%s\en",
145 \& $net,
146 \& lc($n\->name) eq lc($net) ? "" : "*really* ",
147 \& $n\->name;
148 \&
149 \& print "\etaliases are ", join(", ", @{$n\->aliases}), "\en"
150 \& if @{$n\->aliases};
151 \&
152 \& # this is stupid; first, why is this not in binary?
153 \& # second, why am i going through these convolutions
154 \& # to make it looks right
155 \& {
156 \& my @a = unpack("C4", pack("N", $n\->net));
157 \& shift @a while @a && $a[0] == 0;
158 \& printf "\etaddr is %s [%d.%d.%d.%d]\en", $n\->net, @a;
159 \& }
160 \&
161 \& if ($n = getnetbyaddr($n\->net)) {
162 \& if (lc($n\->name) ne lc($net)) {
163 \& printf "\etThat addr reverses to net %s!\en", $n\->name;
164 \& $net = $n\->name;
165 \& redo;
166 \& }
167 \& }
168 \& }
169 .Ve
170 .SH NOTE
171 .IX Header "NOTE"
172 While this class is currently implemented using the Class::Struct
173 module to build a struct\-like class, you shouldn\*(Aqt rely upon this.
174 .SH AUTHOR
175 .IX Header "AUTHOR"
176 Tom Christiansen