NAME
    IP::Address - Manipulate IP Addresses easily

SYNOPSIS
      use IP::Address qw($Use_CIDR_Notation $Always_Display_Mask);

      # Initialization of IP::Address objects
      my $ip = new IP::Address "10.0.0.1";
      my $subnet = new IP::Address("10.0.0.0", "255.255.255.0");
      my $othersubnet = new IP::Address("10.0.0.0", "24");
      my $yetanothersubnet = new IP::Address "10.0.0.0/24";

      # A proper subnet (or undef if any host but is set)
      my $subnet_ok = new_subnet IP::Address("10.0.0.0", "24");
      my $subnet_undef = new_subnet IP::Address("10.0.0.1", "24");

      # A string representation of an address or subnet
      print "My ip address is ", $ip->to_string, "\n";

      # Just the string or the mask part...
      print "My ip address alone is ", $ip->addr_to_string, "\n";
      print "and my netmask is ", $ip->mask_to_string, "\n";

      # Enumeration of all the addresses within a given subnet, keeping
      # the original mask
      my @hosts = $subnet->enum;
      for $i (@hosts) {
          print "address ", $i->to_string, 
          " belongs to subnet ", $subnet->to_string, "\n";
      }

      # You can also produce the list of host addresses in a given subnet
      my @hosts = $subnet->host_enum;
      for $i (@hosts) {
          print "Host ", $i->to_string, 
          " is in subnet ", $subnet->to_string, "\n";
      }

      # This calculates network and broadcast addresses for a subnet
      my $network = $subnet->network;
      my $broadcast = $subnet->broadcast;
      print "Subnet ", $subnet->to_string, " has broadcast address ",
        $broadcast->to_string, " and network number ", $network->to_string,
        "\n";

      # Checks to see if a host address or subnet is contained within another
      # subnet
      if ($subnet->contains $ip) {
          print "Host ", $ip->to_string, " is contained in ",
          $subnet->to_string, "\n";
      }

      # Masks and address components can be copied from object to object
      $ip1->set_addr($ip2);
      $ip1->set_mask($subnet);

      # Ammount of hosts in a subnet can also be easily calculated
      $max_hosts_in_subnet = $subnet->how_many - 2;

      # A range of IP Addresses
      @range = $ip->range($final_ip); # From $ip to $final_ip
      @range = $ip->range(@dont_know_which_is_larger);
                                    # From the smallest on the list + $ip to
                                    # the largest

      # Usable addresses in a subnet
      $first_address = $subnet->first;
      $last_address = $subnet->last;

DESCRIPTION
    This module provides a simple interface to the tedious bit manipulation
    involved when handling IP address calculations. It also helps by
    performing range comparisons between subnets as well as other frequently
    used functions.

    Most of the primitive functions return an IP::Address object.

    The variables $Use_CIDR_Notation and $Always_Display_Mask affect how the
    ->to_string function will present its result. The names are hopefully
    intuitive enough. Note that IP addresses are not properly compacted (ie,
    200.44.0/18 is written as 200.44.0.0/18) because this adapts to the
    widely adopted but incorrect notation. Perhaps a later version will
    include a variable to change this.

    This code has not been widely tested yet. Endianness problems might very
    well exist. Please email the author if such problems are found.

    This software is (c) Luis E. Munoz. It can be used under the terms of
    the perl artistic license provided that proper credit is preserved and
    that the original documentation is not removed.

    This software comes with the same warranty as perl itself (ie, none), so
    by using it you accept any and all the liability.

AUTHOR
    Luis E. Munoz <lem@cantv.net>

SEE ALSO
    perl(1).




































12/Jul/99       Last change: perl 5.005, patch 02               3






