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::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:" />
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::hostent - by-name interface to Perl's built-in gethost* 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::hostent - by-name interface to Perl's built-in gethost*() functions
</p>
39 <h1><a name=
"synopsis">SYNOPSIS
</a></h1>
41 use Net::hostent;
</pre>
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
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-
>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-
>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>
72 <h1><a name=
"examples">EXAMPLES
</a></h1>
77 @ARGV = ('netscape.com') unless @ARGV;
</pre>
79 for $host ( @ARGV ) {
</pre>
81 unless ($h = gethost($host)) {
82 warn
"$
0: no such host: $host\n
";
86 printf
"\n%s is %s%s\n
",
88 lc($h-
>name) eq lc($host) ?
"" :
"*really*
",
91 print
"\taliases are
", join(
",
", @{$h-
>aliases}),
"\n
"
92 if @{$h-
>aliases};
</pre>
94 if ( @{$h-
>addr_list}
> 1 ) {
96 for $addr ( @{$h-
>addr_list} ) {
97 printf
"\taddr #%d is [%s]\n
", $i++, inet_ntoa($addr);
100 printf
"\taddress is [%s]\n
", inet_ntoa($h-
>addr);
103 if ($h = gethostbyaddr($h-
>addr)) {
104 if (lc($h-
>name) ne lc($host)) {
105 printf
"\tThat addr reverses to host %s!\n
", $h-
>name;
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>
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"> Net::hostent - by-name interface to Perl's built-in gethost* functions
</span></strong></big>