Import of LUISMUNOZ/NetAddr-IP-3.08 from CPAN.
gitpan-cpan-distribution: NetAddr-IP
gitpan-cpan-version:      3.08
gitpan-cpan-path:         LUISMUNOZ/NetAddr-IP-3.08.tar.gz
gitpan-cpan-author:       LUISMUNOZ
gitpan-cpan-maturity:     released
1 parent 69d199d commit 4c5c01c0b28848142d63a89be34fbee700ac679e
@Luis Muñoz Luis Muñoz authored on 27 Apr 2002
Gitpan committed on 21 Oct 2014
Showing 4 changed files
View
30
IP.pm
# End of the overload methods.
#############################################
 
 
our $VERSION = '3.07';
our $VERSION = '3.08';
 
# Preloaded methods go here.
 
# This is a variant to ->new() that
vec($bmask, 2, 8) = 0;
vec($bmask, 3, 8) = 0;
}
elsif ($mask =~ m/^(\d+)\.(\d+)\.(\d+)\.(\d+)$/) {
 
for my $i ($1, $2, $3, $4) {
return undef
unless grep { $i == $_ }
(255, 254, 252, 248, 224, 192, 160, 128, 0);
}
 
return undef if ($1 < $2 or $2 < $3 or $3 < $4);
return undef if $2 != 0 and $1 != 255;
return undef if $3 != 0 and $2 != 255;
return undef if $4 != 0 and $3 != 255;
vec($bmask, 0, 8) = $1;
vec($bmask, 1, 8) = $2;
vec($bmask, 2, 8) = $3;
vec($bmask, 3, 8) = $4;
}
 
if (defined $_[2]) {
$mask = _parse_mask $_[2], 32;
return undef unless defined $mask;
}
elsif (defined $mask) {
$mask = _parse_mask $mask, 32;
return undef unless defined $mask;
}
else {
$hasmask = 0;
$mask = _parse_mask 32, 32;
return undef unless defined $mask;
}
 
my $self = _v4($ip, $mask, $hasmask);
 
return ~vec($self->{mask}, 0, $self->{bits}) & 0xFFFFFFFF;
}
 
1;
 
__END__
 
=head1 NAME
 
A small bug related to parsing of 'localhost' was fixed.
 
=back
 
=item 3.08
 
=over
 
=item *
 
By popular request, C<-E<gt>new()> now checks the sanity of the netmasks
it receives. If the netmask is invalid, C<undef> will be returned.
 
=back
 
=back
 
=head1 AUTHOR
 
View
1
■■■■
MANIFEST
t/v4-base.t
t/v4-cidr.t
t/over-arr.t
t/v4-range.t
t/v4-badnm.t
t/v4-basem.t
t/v4-first.t
t/wildcard.t
t/v4-compact.t
View
2
■■■
README
NetAddr::IP - Manages IPv4 (your traditional IP) addresses and subnets
 
* * * * THIS MODULE REQUIRES PERL 5.6.0 OR NEWER. * * * *
 
This module is designed as a help for managing (ranges of) IP
addresses. It includes efficient implementations for most common tasks
done to subnets or ranges of IP addresses, namely verifying if an
View
57
t/v4-badnm.t 0 → 100644
# I know this does not look like -*- perl -*-, but I swear it is...
 
use NetAddr::IP;
use strict;
 
$| = 1;
 
our @badnets = (
'10.10.10.10/255.255.0.255',
'10.10.10.10/255.0.255.255',
'10.10.10.10/0.255.255.255',
'10.10.10.10/128.255.0.255',
'10.10.10.10/255.128.0.255',
'10.10.10.10/255.255.255.129',
'10.10.10.10/255.255.129.0',
'10.10.10.10/255.255.255.130',
'10.10.10.10/255.255.130.0',
'10.10.10.10/255.0.0.1',
'10.10.10.10/255.129.0.1',
'10.10.10.10/0.255.0.255',
);
 
our @goodnets = ();
 
push @goodnets, "10.0.0.1/$_" for (0 .. 32);
push @goodnets, "10.0.0.1/255.255.255.255";
 
print '1..', (scalar @badnets + scalar @goodnets) , "\n";
 
my $count = 1;
 
for my $bad (@badnets) {
 
if (defined NetAddr::IP->new($bad)) {
print "not ok $count # $bad should fail but succeeded\n";
}
else {
print "ok $count # $bad must fail\n";
}
 
++ $count;
}
 
for my $good (@goodnets) {
 
if (defined NetAddr::IP->new($good)) {
print "ok $count # $good should not fail\n";
}
else {
print "not ok $count # $good must not fail\n";
}
 
++ $count;
}