CIDR-Assign

 view release on metacpan or  search on metacpan

Assign.pm  view on Meta::CPAN


		#  *IF* this default causes a CIDR-alignment problem,
		#    then that's probably not what they wanted.  Try
		#    8, 16, 24, or 32 based on the number of octets 
		#    that they supplied when they typed the address.  
		#    E.g.,:
		#    35   ->  35/8
		#    35.1 -> 35/16
		#    193  -> 193/8
		#    193.128.2.15 -> 193.128.2.15/32

		$mask = &maskOfLength($length);
		$length = (8,16,24,32)[$#bytes] if ($mask & $ip) != $ip;
	}

	return ( $ip, $length );
}

sub printIP {
	return join('.', unpack('C4', pack('L', @_)));
}

sub overlap {
	my($old, $new) = @_;
	my(@old, @new);

	@old = &parseNet($old);
	@new = &parseNet($new);
	if ( $old[1] == $new[1] ) {
		return $old[0] == $new[0];
	} else { # different lengths so we need to see if one is inside other
		if ( $old[1] < $new[1] ) {
			$mask = &maskOfLength($old[1]);
		} else {
			$mask = &maskOfLength($new[1]);
		}
		return ($old[0] & $mask) == ($new[0] & $mask);
	}
}

1;

=head1 AUTHOR

Mark Prior <mrp@connect.com.au>

Original idea and code by Andrew Rutherford <andrewr@iagu.net>

=head1 NOTES
 
This module uses the following modules

=over 4

=item DB_File

The Berkeley DB is used for storage of the allocations, in B-Tree format.

=item File::lockf

The allocations file is locked with lockf to avoid problems with NFS.

=back

=cut



( run in 2.590 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )