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::netent.z / Net::netent
Encoding:
Text File  |  1998-10-30  |  5.0 KB  |  199 lines

  1.  
  2.  
  3.  
  4. NNNNeeeetttt::::::::nnnneeeetttteeeennnntttt((((3333))))                                                  NNNNeeeetttt::::::::nnnneeeetttteeeennnntttt((((3333))))
  5.  
  6.  
  7.  
  8. NNNNAAAAMMMMEEEE
  9.      Net::netent - by-name interface to Perl's built-in getnet*() functions
  10.  
  11. SSSSYYYYNNNNOOOOPPPPSSSSIIIISSSS
  12.       use Net::netent qw(:FIELDS);
  13.       getnetbyname("loopback")               or die "bad net";
  14.       printf "%s is %08X\n", $n_name, $n_net;
  15.  
  16.       use Net::netent;
  17.  
  18.       $n = getnetbyname("loopback")          or die "bad net";
  19.       { # there's gotta be a better way, eh?
  20.           @bytes = unpack("C4", pack("N", $n->net));
  21.           shift @bytes while @bytes && $bytes[0] == 0;
  22.       }
  23.       printf "%s is %08X [%d.%d.%d.%d]\n", $n->name, $n->net, @bytes;
  24.  
  25.  
  26. DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
  27.      This module's default exports override the core _g_e_t_n_e_t_b_y_n_a_m_e() and
  28.      _g_e_t_n_e_t_b_y_a_d_d_r() functions, replacing them with versions that return
  29.      "Net::netent" objects.  This object has methods that return the similarly
  30.      named structure field name from the C's netent structure from _n_e_t_d_b._h;
  31.      namely name, aliases, addrtype, and net.  The aliases method returns an
  32.      array reference, the rest scalars.
  33.  
  34.      You may also import all the structure fields directly into your namespace
  35.      as regular variables using the :FIELDS import tag.  (Note that this still
  36.      overrides your core functions.)  Access these fields as variables named
  37.      with a preceding n_.  Thus, $net_obj->_n_a_m_e() corresponds to $n_name if
  38.      you import the fields.  Array references are available as regular array
  39.      variables, so for example @{ $net_obj->_a_l_i_a_s_e_s() } would be simply
  40.      @n_aliases.
  41.  
  42.      The _g_e_t_n_e_t() funtion is a simple front-end that forwards a numeric
  43.      argument to _g_e_t_n_e_t_b_y_a_d_d_r(), and the rest to _g_e_t_n_e_t_b_y_n_a_m_e().
  44.  
  45.      To access this functionality without the core overrides, pass the use an
  46.      empty import list, and then access function functions with their full
  47.      qualified names.  On the other hand, the built-ins are still available
  48.      via the CORE:: pseudo-package.
  49.  
  50. EEEEXXXXAAAAMMMMPPPPLLLLEEEESSSS
  51.      The _g_e_t_n_e_t() functions do this in the Perl core:
  52.  
  53.          sv_setiv(sv, (I32)nent->n_net);
  54.  
  55.      The _g_e_t_h_o_s_t() functions do this in the Perl core:
  56.  
  57.          sv_setpvn(sv, hent->h_addr, len);
  58.  
  59.      That means that the address comes back in binary for the host functions,
  60.  
  61.  
  62.  
  63.                                                                         PPPPaaaaggggeeee 1111
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. NNNNeeeetttt::::::::nnnneeeetttteeeennnntttt((((3333))))                                                  NNNNeeeetttt::::::::nnnneeeetttteeeennnntttt((((3333))))
  71.  
  72.  
  73.  
  74.      and as a regular perl integer for the net ones.  This seems a bug, but
  75.      here's how to deal with it:
  76.  
  77.       use strict;
  78.       use Socket;
  79.       use Net::netent;
  80.  
  81.       @ARGV = ('loopback') unless @ARGV;
  82.  
  83.       my($n, $net);
  84.  
  85.       for $net ( @ARGV ) {
  86.  
  87.           unless ($n = getnetbyname($net)) {
  88.              warn "$0: no such net: $net\n";
  89.              next;
  90.           }
  91.  
  92.           printf "\n%s is %s%s\n",
  93.                  $net,
  94.                  lc($n->name) eq lc($net) ? "" : "*really* ",
  95.                  $n->name;
  96.  
  97.           print "\taliases are ", join(", ", @{$n->aliases}), "\n"
  98.                      if @{$n->aliases};
  99.  
  100.           # this is stupid; first, why is this not in binary?
  101.           # second, why am i going through these convolutions
  102.           # to make it looks right
  103.           {
  104.              my @a = unpack("C4", pack("N", $n->net));
  105.              shift @a while @a && $a[0] == 0;
  106.              printf "\taddr is %s [%d.%d.%d.%d]\n", $n->net, @a;
  107.           }
  108.  
  109.           if ($n = getnetbyaddr($n->net)) {
  110.              if (lc($n->name) ne lc($net)) {
  111.                  printf "\tThat addr reverses to net %s!\n", $n->name;
  112.                  $net = $n->name;
  113.                  redo;
  114.              }
  115.           }
  116.       }
  117.  
  118.  
  119. NNNNOOOOTTTTEEEE
  120.      While this class is currently implemented using the Class::Struct module
  121.      to build a struct-like class, you shouldn't rely upon this.
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.                                                                         PPPPaaaaggggeeee 2222
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136. NNNNeeeetttt::::::::nnnneeeetttteeeennnntttt((((3333))))                                                  NNNNeeeetttt::::::::nnnneeeetttteeeennnntttt((((3333))))
  137.  
  138.  
  139.  
  140. AUTHOR
  141.      Tom Christiansen
  142.  
  143.  
  144.  
  145.  
  146.  
  147.  
  148.  
  149.  
  150.  
  151.  
  152.  
  153.  
  154.  
  155.  
  156.  
  157.  
  158.  
  159.  
  160.  
  161.  
  162.  
  163.  
  164.  
  165.  
  166.  
  167.  
  168.  
  169.  
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.                                                                         PPPPaaaaggggeeee 3333
  196.  
  197.  
  198.  
  199.