Install Perl 5.8.8
[msysgit.git] / mingw / html / lib / Net / netent.html
blob0193c25fd6e4210088a891454a31baf4986d4033
1 <?xml version="1.0" ?>
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">
4 <head>
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:" />
8 </head>
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">&nbsp;Net::netent - by-name interface to Perl's built-in getnet* functions</span></strong></big>
14 </td></tr>
15 </table>
17 <p><a name="__index__"></a></p>
18 <!-- INDEX BEGIN -->
20 <ul>
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>
28 </ul>
29 <!-- INDEX END -->
31 <hr />
32 <p>
33 </p>
34 <h1><a name="name">NAME</a></h1>
35 <p>Net::netent - by-name interface to Perl's built-in getnet*() functions</p>
36 <p>
37 </p>
38 <hr />
39 <h1><a name="synopsis">SYNOPSIS</a></h1>
40 <pre>
41 use Net::netent qw(:FIELDS);
42 getnetbyname(&quot;loopback&quot;) or die &quot;bad net&quot;;
43 printf &quot;%s is %08X\n&quot;, $n_name, $n_net;</pre>
44 <pre>
45 use Net::netent;</pre>
46 <pre>
47 $n = getnetbyname(&quot;loopback&quot;) or die &quot;bad net&quot;;
48 { # there's gotta be a better way, eh?
49 @bytes = unpack(&quot;C4&quot;, pack(&quot;N&quot;, $n-&gt;net));
50 shift @bytes while @bytes &amp;&amp; $bytes[0] == 0;
52 printf &quot;%s is %08X [%d.%d.%d.%d]\n&quot;, $n-&gt;name, $n-&gt;net, @bytes;</pre>
53 <p>
54 </p>
55 <hr />
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-&gt;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-&gt;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>
78 <p>
79 </p>
80 <hr />
81 <h1><a name="examples">EXAMPLES</a></h1>
82 <p>The <code>getnet()</code> functions do this in the Perl core:</p>
83 <pre>
84 sv_setiv(sv, (I32)nent-&gt;n_net);</pre>
85 <p>The <code>gethost()</code> functions do this in the Perl core:</p>
86 <pre>
87 sv_setpvn(sv, hent-&gt;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>
91 <pre>
92 use strict;
93 use Socket;
94 use Net::netent;</pre>
95 <pre>
96 @ARGV = ('loopback') unless @ARGV;</pre>
97 <pre>
98 my($n, $net);</pre>
99 <pre>
100 for $net ( @ARGV ) {</pre>
101 <pre>
102 unless ($n = getnetbyname($net)) {
103 warn &quot;$0: no such net: $net\n&quot;;
104 next;
105 }</pre>
106 <pre>
107 printf &quot;\n%s is %s%s\n&quot;,
108 $net,
109 lc($n-&gt;name) eq lc($net) ? &quot;&quot; : &quot;*really* &quot;,
110 $n-&gt;name;</pre>
111 <pre>
112 print &quot;\taliases are &quot;, join(&quot;, &quot;, @{$n-&gt;aliases}), &quot;\n&quot;
113 if @{$n-&gt;aliases};</pre>
114 <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(&quot;C4&quot;, pack(&quot;N&quot;, $n-&gt;net));
120 shift @a while @a &amp;&amp; $a[0] == 0;
121 printf &quot;\taddr is %s [%d.%d.%d.%d]\n&quot;, $n-&gt;net, @a;
122 }</pre>
123 <pre>
124 if ($n = getnetbyaddr($n-&gt;net)) {
125 if (lc($n-&gt;name) ne lc($net)) {
126 printf &quot;\tThat addr reverses to net %s!\n&quot;, $n-&gt;name;
127 $net = $n-&gt;name;
128 redo;
131 }</pre>
133 </p>
134 <hr />
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>
139 </p>
140 <hr />
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">&nbsp;Net::netent - by-name interface to Perl's built-in getnet* functions</span></strong></big>
146 </td></tr>
147 </table>
149 </body>
151 </html>