1
  0   ˆl–Ü4ý('Ð;â€ÆÛ¸ËŠbÑ¿Â„i–Þw_‹uÐb&=LV[(ÁÆ ?÷     #!/usr/bin/perl -w

package NetAddr::IP;

use strict;
#use diagnostics;
use Carp;
use NetAddr::IP::Lite 1.57 qw(Zero Zeros Ones V4mask V4net);
use NetAddr::IP::Util 1.53 qw(
	sub128
	inet_aton
	inet_any2n
	ipv6_aton
	isIPv4
	ipv4to6
	mask4to6
	shiftleft
	addconst
	hasbits
	notcontiguous
);

use AutoLoader qw(AUTOLOAD);

use vars qw(
	@EXPORT_OK
	@EXPORT_FAIL
	@ISA
	$VERSION
	$_netlimit
	$rfc3021
);
require Exporter;

@EXPORT_OK = qw(Compact Coalesce Zero Zeros Ones V4mask V4net netlimit);
@EXPORT_FAIL = qw($_netlimit);

@ISA = qw(Exporter NetAddr::IP::Lite);

$VERSION = do { sprintf " %d.%03d", (q$Revision: 4.79 $ =~ /\d+/g) };

$rfc3021 = 0;

=pod

=encoding UTF-8

=head1 NAME

NetAddr::IP - Manages IPv4 and IPv6 addresses and subnets

=head1 SYNOPSIS

  use NetAddr::IP qw(
	Compact
	Coalesce
	Zeros
	Ones
	V4mask
	V4net
	netlimit
	:aton		DEPRECATED
	:lower
	:upper
	:old_storable
	:old_nth
	:rfc3021
	:nofqdn
  );

  NOTE: NetAddr::IP::Util has a full complement of network address
	utilities to convert back and forth between binary and text.

	inet_aton, inet_ntoa, ipv6_aton, ipv6_ntoa 
	ipv6_n2x, ipv6_n2d inet_any2d, inet_n2dx, 
	inet_n2ad, inetanyto6, ipv6to4

See L<NetAddr::IP::Util>


  my $ip = new NetAddr::IP '127.0.0.1';
	 or if you prefer
  my $ip = NetAddr::IP->new('127.0.0.1);
	or from a packed IPv4 address
  my $ip = new_from_aton NetAddr::IP (inet_aton('127.0.0.1'));
	or from an octal filtered IPv4 address
  my $ip = new_no NetAddr::IP '127.012.0.0';

  print "The address is ", $ip->addr, " with mask ", $ip->mask, "\n" ;

  if ($ip->within(new NetAddr::IP "127.0.0.0", "255.0.0.0")) {
      print "Is a loopback address\n";
  }

				# This prints 127.0.0.1/32
  print "You can also say $ip...\n";

* The following four functions return ipV6 representations of:

  ::                                       = Zeros();
  FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF  = Ones();
  FFFF:FFFF:FFFF:FFFF:FFFF:FFFF::          = V4mask();
  ::FFFF:FFFF                              = V4net();

  Will also return an ipV4 or ipV6 representation of a
  resolvable Fully Qualified Domanin Name (FQDN).

###### DEPRECATED, will be remove in version 5 ############

  * To accept addresses in the format as returned by
  inet_aton, invoke the module as:

  use NetAddr::IP qw(:aton);

###### USE new_from_aton instead ##########################

* To enable usage of legacy data files containing NetAddr::IP
objects stored using the L<Storable> module.

  use NetAddr::IP qw(:old_storable);

* To compact many smaller subnets (see: C<$me-E<gt>compact($addr1,$addr2,...)>

  @compacted_object_list = Compact(@object_list)

* Return a reference to list of C<NetAddr::IP> subnets of
C<$masklen> mask length, when C<$number> or more addresses from
C<@list_of_subnets> are found to be contained in said subnet.

  $arrayref = Coalesce($masklen, $number, @list_of_subnets)

* By default B<NetAddr::IP> functions and methods return string IPv6
addresses in uppercase.  To change that to lowercase:

NOTE: the AUGUST 2010 RFC5952 states:

    4.3. Lowercase

      The characters "a", "b", "c", "d", "e", and "f" in an IPv6
      address MUST be represented in lowercase.

It is recommended that all NEW applications using NetAddr::IP be
invoked as shown on the next line.

  use NetAddr::IP qw(:lower);

* To ensure the current IPv6 string case behavior even if the default changes:

  use NetAddr::IP qw(:upper);

* To set a limit on the size of B<nets> processed or returned by NetAddr::IP.

Set the maximum number of nets beyond which NetAddr::IP will return
an error as a power of 2 (default 16 or 65536 nets). Each 2**16
consumes approximately 4 megs of memory. A 2**20 consumes 64 megs of
memory, A 2**24 consumes 1 gigabyte of memory.

  use NetAddr::IP qw(netlimit);
  netlimit 20;

The maximum B<netlimit> allowed is 2**24. Attempts to set limits below
the default of 16 or above the maximum of 24 are ignored.

Returns true on success, otherwise C<undef>.

=cut

$_netlimit = 2 ** 16;			# default

sub netlim