home *** CD-ROM | disk | FTP | other *** search
/ IRIX Base Documentation 2001 May / SGI IRIX Base Documentation 2001 May.iso / usr / share / catman / p_man / cat3 / perl5 / Net::hostent.z / Net::hostent
Encoding:
Text File  |  1998-10-30  |  3.9 KB  |  133 lines

  1.  
  2.  
  3.  
  4. NNNNeeeetttt::::::::hhhhoooosssstttteeeennnntttt((((3333))))                                                NNNNeeeetttt::::::::hhhhoooosssstttteeeennnntttt((((3333))))
  5.  
  6.  
  7.  
  8. NNNNAAAAMMMMEEEE
  9.      Net::hostent - by-name interface to Perl's built-in gethost*() functions
  10.  
  11. SSSSYYYYNNNNOOOOPPPPSSSSIIIISSSS
  12.       use Net::hostnet;
  13.  
  14.  
  15. DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
  16.      This module's default exports override the core _g_e_t_h_o_s_t_b_y_n_a_m_e() and
  17.      _g_e_t_h_o_s_t_b_y_a_d_d_r() functions, replacing them with versions that return
  18.      "Net::hostent" objects.  This object has methods that return the
  19.      similarly named structure field name from the C's hostent structure from
  20.      _n_e_t_d_b._h; namely name, aliases, addrtype, length, and addr_list.  The
  21.      aliases and addr_list methods return array reference, the rest scalars.
  22.      The addr method is equivalent to the zeroth element in the addr_list
  23.      array reference.
  24.  
  25.      You may also import all the structure fields directly into your namespace
  26.      as regular variables using the :FIELDS import tag.  (Note that this still
  27.      overrides your core functions.)  Access these fields as variables named
  28.      with a preceding h_.  Thus, $host_obj->_n_a_m_e() corresponds to $h_name if
  29.      you import the fields.  Array references are available as regular array
  30.      variables, so for example @{ $host_obj->_a_l_i_a_s_e_s() } would be simply
  31.      @h_aliases.
  32.  
  33.      The _g_e_t_h_o_s_t() funtion is a simple front-end that forwards a numeric
  34.      argument to _g_e_t_h_o_s_t_b_y_a_d_d_r() by way of Socket::inet_aton, and the rest to
  35.      _g_e_t_h_o_s_t_b_y_n_a_m_e().
  36.  
  37.      To access this functionality without the core overrides, pass the use an
  38.      empty import list, and then access function functions with their full
  39.      qualified names.  On the other hand, the built-ins are still available
  40.      via the CORE:: pseudo-package.
  41.  
  42. EEEEXXXXAAAAMMMMPPPPLLLLEEEESSSS
  43.       use Net::hostent;
  44.       use Socket;
  45.  
  46.       @ARGV = ('netscape.com') unless @ARGV;
  47.  
  48.       for $host ( @ARGV ) {
  49.  
  50.          unless ($h = gethost($host)) {
  51.              warn "$0: no such host: $host\n";
  52.              next;
  53.          }
  54.  
  55.          printf "\n%s is %s%s\n",
  56.                  $host,
  57.                  lc($h->name) eq lc($host) ? "" : "*really* ",
  58.                  $h->name;
  59.  
  60.  
  61.  
  62.  
  63.                                                                         PPPPaaaaggggeeee 1111
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. NNNNeeeetttt::::::::hhhhoooosssstttteeeennnntttt((((3333))))                                                NNNNeeeetttt::::::::hhhhoooosssstttteeeennnntttt((((3333))))
  71.  
  72.  
  73.  
  74.          print "\taliases are ", join(", ", @{$h->aliases}), "\n"
  75.                      if @{$h->aliases};
  76.  
  77.          if ( @{$h->addr_list} > 1 ) {
  78.              my $i;
  79.              for $addr ( @{$h->addr_list} ) {
  80.                  printf "\taddr #%d is [%s]\n", $i++, inet_ntoa($addr);
  81.              }
  82.          } else {
  83.              printf "\taddress is [%s]\n", inet_ntoa($h->addr);
  84.          }
  85.  
  86.          if ($h = gethostbyaddr($h->addr)) {
  87.              if (lc($h->name) ne lc($host)) {
  88.                  printf "\tThat addr reverses to host %s!\n", $h->name;
  89.                  $host = $h->name;
  90.                  redo;
  91.              }
  92.          }
  93.       }
  94.  
  95.  
  96. NNNNOOOOTTTTEEEE
  97.      While this class is currently implemented using the Class::Struct module
  98.      to build a struct-like class, you shouldn't rely upon this.
  99.  
  100. AAAAUUUUTTTTHHHHOOOORRRR
  101.      Tom Christiansen
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.                                                                         PPPPaaaaggggeeee 2222
  130.  
  131.  
  132.  
  133.