Install Perl 5.8.8
[msysgit.git] / mingw / html / lib / Net / hostent.html
blob68071e134bb495c6103266a3811b43bd7ec67b4c
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::hostent - by-name interface to Perl's built-in gethost* 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::hostent - by-name interface to Perl's built-in gethost* 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::hostent - by-name interface to Perl's built-in gethost*() functions</p>
36 <p>
37 </p>
38 <hr />
39 <h1><a name="synopsis">SYNOPSIS</a></h1>
40 <pre>
41 use Net::hostent;</pre>
42 <p>
43 </p>
44 <hr />
45 <h1><a name="description">DESCRIPTION</a></h1>
46 <p>This module's default exports override the core <a href="file://C|\msysgit\mingw\html/pod/perlfunc.html#item_gethostbyname"><code>gethostbyname()</code></a> and
47 <a href="file://C|\msysgit\mingw\html/pod/perlfunc.html#item_gethostbyaddr"><code>gethostbyaddr()</code></a> functions, replacing them with versions that return
48 ``Net::hostent'' objects. This object has methods that return the similarly
49 named structure field name from the C's hostent structure from <em>netdb.h</em>;
50 namely name, aliases, addrtype, length, and addr_list. The aliases and
51 addr_list methods return array reference, the rest scalars. The addr
52 method is equivalent to the zeroth element in the addr_list array
53 reference.</p>
54 <p>You may also import all the structure fields directly into your namespace
55 as regular variables using the :FIELDS import tag. (Note that this still
56 overrides your core functions.) Access these fields as variables named
57 with a preceding <code>h_</code>. Thus, <code>$host_obj-&gt;name()</code> corresponds to
58 $h_name if you import the fields. Array references are available as
59 regular array variables, so for example <code>@{ $host_obj-&gt;aliases()
60 }</code> would be simply @h_aliases.</p>
61 <p>The <code>gethost()</code> function is a simple front-end that forwards a numeric
62 argument to <a href="file://C|\msysgit\mingw\html/pod/perlfunc.html#item_gethostbyaddr"><code>gethostbyaddr()</code></a> by way of Socket::inet_aton, and the rest
63 to gethostbyname().</p>
64 <p>To access this functionality without the core overrides,
65 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
66 function functions with their full qualified names.
67 On the other hand, the built-ins are still available
68 via the <code>CORE::</code> pseudo-package.</p>
69 <p>
70 </p>
71 <hr />
72 <h1><a name="examples">EXAMPLES</a></h1>
73 <pre>
74 use Net::hostent;
75 use Socket;</pre>
76 <pre>
77 @ARGV = ('netscape.com') unless @ARGV;</pre>
78 <pre>
79 for $host ( @ARGV ) {</pre>
80 <pre>
81 unless ($h = gethost($host)) {
82 warn &quot;$0: no such host: $host\n&quot;;
83 next;
84 }</pre>
85 <pre>
86 printf &quot;\n%s is %s%s\n&quot;,
87 $host,
88 lc($h-&gt;name) eq lc($host) ? &quot;&quot; : &quot;*really* &quot;,
89 $h-&gt;name;</pre>
90 <pre>
91 print &quot;\taliases are &quot;, join(&quot;, &quot;, @{$h-&gt;aliases}), &quot;\n&quot;
92 if @{$h-&gt;aliases};</pre>
93 <pre>
94 if ( @{$h-&gt;addr_list} &gt; 1 ) {
95 my $i;
96 for $addr ( @{$h-&gt;addr_list} ) {
97 printf &quot;\taddr #%d is [%s]\n&quot;, $i++, inet_ntoa($addr);
99 } else {
100 printf &quot;\taddress is [%s]\n&quot;, inet_ntoa($h-&gt;addr);
101 }</pre>
102 <pre>
103 if ($h = gethostbyaddr($h-&gt;addr)) {
104 if (lc($h-&gt;name) ne lc($host)) {
105 printf &quot;\tThat addr reverses to host %s!\n&quot;, $h-&gt;name;
106 $host = $h-&gt;name;
107 redo;
110 }</pre>
112 </p>
113 <hr />
114 <h1><a name="note">NOTE</a></h1>
115 <p>While this class is currently implemented using the Class::Struct
116 module to build a struct-like class, you shouldn't rely upon this.</p>
118 </p>
119 <hr />
120 <h1><a name="author">AUTHOR</a></h1>
121 <p>Tom Christiansen</p>
122 <table border="0" width="100%" cellspacing="0" cellpadding="3">
123 <tr><td class="block" style="background-color: #cccccc" valign="middle">
124 <big><strong><span class="block">&nbsp;Net::hostent - by-name interface to Perl's built-in gethost* functions</span></strong></big>
125 </td></tr>
126 </table>
128 </body>
130 </html>