2 <!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3 <html xmlns=
"http://www.w3.org/1999/xhtml">
5 <title>Net::netent - by-name interface to Perl's built-in getnet* functions
</title>
6 <meta http-equiv=
"content-type" content=
"text/html; charset=utf-8" />
7 <link rev=
"made" href=
"mailto:" />
10 <body style=
"background-color: white">
11 <table border=
"0" width=
"100%" cellspacing=
"0" cellpadding=
"3">
12 <tr><td class=
"block" style=
"background-color: #cccccc" valign=
"middle">
13 <big><strong><span class=
"block"> Net::netent - by-name interface to Perl's built-in getnet* functions
</span></strong></big>
17 <p><a name=
"__index__"></a></p>
22 <li><a href=
"#name">NAME
</a></li>
23 <li><a href=
"#synopsis">SYNOPSIS
</a></li>
24 <li><a href=
"#description">DESCRIPTION
</a></li>
25 <li><a href=
"#examples">EXAMPLES
</a></li>
26 <li><a href=
"#note">NOTE
</a></li>
27 <li><a href=
"#author">AUTHOR
</a></li>
34 <h1><a name=
"name">NAME
</a></h1>
35 <p>Net::netent - by-name interface to Perl's built-in getnet*() functions
</p>
39 <h1><a name=
"synopsis">SYNOPSIS
</a></h1>
41 use Net::netent qw(:FIELDS);
42 getnetbyname(
"loopback
") or die
"bad net
";
43 printf
"%s is %
08X\n
", $n_name, $n_net;
</pre>
45 use Net::netent;
</pre>
47 $n = getnetbyname(
"loopback
") or die
"bad net
";
48 { # there's gotta be a better way, eh?
49 @bytes = unpack(
"C4
", pack(
"N
", $n-
>net));
50 shift @bytes while @bytes
&& $bytes[
0] ==
0;
52 printf
"%s is %
08X [%d.%d.%d.%d]\n
", $n-
>name, $n-
>net, @bytes;
</pre>
56 <h1><a name=
"description">DESCRIPTION
</a></h1>
57 <p>This module's default exports override the core
<a href=
"file://C|\msysgit\mingw\html/pod/perlfunc.html#item_getnetbyname"><code>getnetbyname()
</code></a> and
58 <a href=
"file://C|\msysgit\mingw\html/pod/perlfunc.html#item_getnetbyaddr"><code>getnetbyaddr()
</code></a> functions, replacing them with versions that return
59 ``Net::netent'' objects. This object has methods that return the similarly
60 named structure field name from the C's netent structure from
<em>netdb.h
</em>;
61 namely name, aliases, addrtype, and net. The aliases
62 method returns an array reference, the rest scalars.
</p>
63 <p>You may also import all the structure fields directly into your namespace
64 as regular variables using the :FIELDS import tag. (Note that this still
65 overrides your core functions.) Access these fields as variables named
66 with a preceding
<code>n_
</code>. Thus,
<code>$net_obj-
>name()
</code> corresponds to
67 $n_name if you import the fields. Array references are available as
68 regular array variables, so for example
<code>@{ $net_obj-
>aliases()
69 }
</code> would be simply @n_aliases.
</p>
70 <p>The
<code>getnet()
</code> function is a simple front-end that forwards a numeric
71 argument to getnetbyaddr(), and the rest
72 to getnetbyname().
</p>
73 <p>To access this functionality without the core overrides,
74 pass the
<a href=
"file://C|\msysgit\mingw\html/pod/perlfunc.html#item_use"><code>use
</code></a> an empty import list, and then access
75 function functions with their full qualified names.
76 On the other hand, the built-ins are still available
77 via the
<code>CORE::
</code> pseudo-package.
</p>
81 <h1><a name=
"examples">EXAMPLES
</a></h1>
82 <p>The
<code>getnet()
</code> functions do this in the Perl core:
</p>
84 sv_setiv(sv, (I32)nent-
>n_net);
</pre>
85 <p>The
<code>gethost()
</code> functions do this in the Perl core:
</p>
87 sv_setpvn(sv, hent-
>h_addr, len);
</pre>
88 <p>That means that the address comes back in binary for the
89 host functions, and as a regular perl integer for the net ones.
90 This seems a bug, but here's how to deal with it:
</p>
94 use Net::netent;
</pre>
96 @ARGV = ('loopback') unless @ARGV;
</pre>
100 for $net ( @ARGV ) {
</pre>
102 unless ($n = getnetbyname($net)) {
103 warn
"$
0: no such net: $net\n
";
107 printf
"\n%s is %s%s\n
",
109 lc($n-
>name) eq lc($net) ?
"" :
"*really*
",
112 print
"\taliases are
", join(
",
", @{$n-
>aliases}),
"\n
"
113 if @{$n-
>aliases};
</pre>
115 # this is stupid; first, why is this not in binary?
116 # second, why am i going through these convolutions
117 # to make it looks right
119 my @a = unpack(
"C4
", pack(
"N
", $n-
>net));
120 shift @a while @a
&& $a[
0] ==
0;
121 printf
"\taddr is %s [%d.%d.%d.%d]\n
", $n-
>net, @a;
124 if ($n = getnetbyaddr($n-
>net)) {
125 if (lc($n-
>name) ne lc($net)) {
126 printf
"\tThat addr reverses to net %s!\n
", $n-
>name;
135 <h1><a name=
"note">NOTE
</a></h1>
136 <p>While this class is currently implemented using the Class::Struct
137 module to build a struct-like class, you shouldn't rely upon this.
</p>
141 <h1><a name=
"author">AUTHOR
</a></h1>
142 <p>Tom Christiansen
</p>
143 <table border=
"0" width=
"100%" cellspacing=
"0" cellpadding=
"3">
144 <tr><td class=
"block" style=
"background-color: #cccccc" valign=
"middle">
145 <big><strong><span class=
"block"> Net::netent - by-name interface to Perl's built-in getnet* functions
</span></strong></big>