home *** CD-ROM | disk | FTP | other *** search
/ Chip 2000 May / Chip_2000-05_cd1.bin / zkuste / Perl / ActivePerl-5.6.0.613.msi / 䆊䌷䈹䈙䏵-䞅䞆䞀㡆䞃䄦䠥 / _b2a49a04d698cbc689b2f9a7afec02d4 < prev    next >
Text File  |  2000-03-23  |  5KB  |  132 lines

  1.  
  2. <HTML>
  3. <HEAD>
  4. <TITLE>Net::hostent - by-name interface to Perl's built-in gethost* functions</TITLE>
  5. <LINK REL="stylesheet" HREF="../../Active.css" TYPE="text/css">
  6. <LINK REV="made" HREF="mailto:">
  7. </HEAD>
  8.  
  9. <BODY>
  10. <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
  11. <TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc">
  12. <STRONG><P CLASS=block> Net::hostent - by-name interface to Perl's built-in gethost* functions</P></STRONG>
  13. </TD></TR>
  14. </TABLE>
  15.  
  16. <A NAME="__index__"></A>
  17. <!-- INDEX BEGIN -->
  18.  
  19. <UL>
  20.  
  21.     <LI><A HREF="#name">NAME</A></LI><LI><A HREF="#supportedplatforms">SUPPORTED PLATFORMS</A></LI>
  22.  
  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 -->
  30.  
  31. <HR>
  32. <P>
  33. <H1><A NAME="name">NAME</A></H1>
  34. <P>Net::hostent - by-name interface to Perl's built-in gethost*() functions</P>
  35. <P>
  36. <HR>
  37. <H1><A NAME="supportedplatforms">SUPPORTED PLATFORMS</A></H1>
  38. <UL>
  39. <LI>Linux</LI>
  40. <LI>Solaris</LI>
  41. <LI>Windows</LI>
  42. </UL>
  43. <HR>
  44. <H1><A NAME="synopsis">SYNOPSIS</A></H1>
  45. <PRE>
  46.  use Net::hostnet;</PRE>
  47. <P>
  48. <HR>
  49. <H1><A NAME="description">DESCRIPTION</A></H1>
  50. <P>This module's default exports override the core <A HREF="../../lib/Pod/perlfunc.html#item_gethostbyname"><CODE>gethostbyname()</CODE></A> and
  51. <A HREF="../../lib/Pod/perlfunc.html#item_gethostbyaddr"><CODE>gethostbyaddr()</CODE></A> functions, replacing them with versions that return
  52. ``Net::hostent'' objects.  This object has methods that return the similarly
  53. named structure field name from the C's hostent structure from <EM>netdb.h</EM>;
  54. namely name, aliases, addrtype, length, and addr_list.  The aliases and
  55. addr_list methods return array reference, the rest scalars.  The addr
  56. method is equivalent to the zeroth element in the addr_list array
  57. reference.</P>
  58. <P>You may also import all the structure fields directly into your namespace
  59. as regular variables using the :FIELDS import tag.  (Note that this still
  60. overrides your core functions.)  Access these fields as variables named
  61. with a preceding <CODE>h_</CODE>.  Thus, <CODE>$host_obj->name()</CODE> corresponds to
  62. $h_name if you import the fields.  Array references are available as
  63. regular array variables, so for example <CODE>@{ $host_obj->aliases()
  64. }</CODE> would be simply @h_aliases.</P>
  65. <P>The <CODE>gethost()</CODE> function is a simple front-end that forwards a numeric
  66. argument to <A HREF="../../lib/Pod/perlfunc.html#item_gethostbyaddr"><CODE>gethostbyaddr()</CODE></A> by way of Socket::inet_aton, and the rest
  67. to gethostbyname().</P>
  68. <P>To access this functionality without the core overrides,
  69. pass the <A HREF="../../lib/Pod/perlfunc.html#item_use"><CODE>use</CODE></A> an empty import list, and then access
  70. function functions with their full qualified names.
  71. On the other hand, the built-ins are still available
  72. via the <CODE>CORE::</CODE> pseudo-package.</P>
  73. <P>
  74. <HR>
  75. <H1><A NAME="examples">EXAMPLES</A></H1>
  76. <PRE>
  77.  use Net::hostent;
  78.  use Socket;</PRE>
  79. <PRE>
  80.  @ARGV = ('netscape.com') unless @ARGV;</PRE>
  81. <PRE>
  82.  for $host ( @ARGV ) {</PRE>
  83. <PRE>
  84.     unless ($h = gethost($host)) {
  85.         warn "$0: no such host: $host\n";
  86.         next;
  87.     }</PRE>
  88. <PRE>
  89.     printf "\n%s is %s%s\n", 
  90.             $host, 
  91.             lc($h->name) eq lc($host) ? "" : "*really* ",
  92.             $h->name;</PRE>
  93. <PRE>
  94.     print "\taliases are ", join(", ", @{$h->aliases}), "\n"
  95.                 if @{$h->aliases};</PRE>
  96. <PRE>
  97.     if ( @{$h->addr_list} > 1 ) { 
  98.         my $i;
  99.         for $addr ( @{$h->addr_list} ) {
  100.             printf "\taddr #%d is [%s]\n", $i++, inet_ntoa($addr);
  101.         } 
  102.     } else {
  103.         printf "\taddress is [%s]\n", inet_ntoa($h->addr);
  104.     }</PRE>
  105. <PRE>
  106.     if ($h = gethostbyaddr($h->addr)) {
  107.         if (lc($h->name) ne lc($host)) {
  108.             printf "\tThat addr reverses to host %s!\n", $h->name;
  109.             $host = $h->name;
  110.             redo;
  111.         } 
  112.     }
  113.  }</PRE>
  114. <P>
  115. <HR>
  116. <H1><A NAME="note">NOTE</A></H1>
  117. <P>While this class is currently implemented using the Class::Struct
  118. module to build a struct-like class, you shouldn't rely upon this.</P>
  119. <P>
  120. <HR>
  121. <H1><A NAME="author">AUTHOR</A></H1>
  122. <P>Tom Christiansen</P>
  123. <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
  124. <TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc">
  125. <STRONG><P CLASS=block> Net::hostent - by-name interface to Perl's built-in gethost* functions</P></STRONG>
  126. </TD></TR>
  127. </TABLE>
  128.  
  129. </BODY>
  130.  
  131. </HTML>
  132.