diff --git a/Changes b/Changes
index b9823d5..aa631bf 100644
--- a/Changes
+++ b/Changes
@@ -1,5 +1,10 @@
Revision history for Perl extension NetAddr::IP
+4.054 Thu Oct 27 12:48:55 PDT 2011
+ In Lite.pm v1.37, remove Calc.pm
+ add detection of early Math::Bigint object structure
+ fix bug 71869 - a failed test routine
+
4.053 Wed Oct 26 08:52:34 PDT 2011
In Lite.pm v1.36
fix bug #71925. A a sub-varient of #62521 that showed up only for
diff --git a/IP.pm b/IP.pm
index a42d33b..e1f7264 100644
--- a/IP.pm
+++ b/IP.pm
@@ -4,7 +4,7 @@
use strict;
#use diagnostics;
-use NetAddr::IP::Lite 1.36 qw(Zero Zeros Ones V4mask V4net);
+use NetAddr::IP::Lite 1.37 qw(Zero Zeros Ones V4mask V4net);
use NetAddr::IP::Util 1.43 qw(
sub128
inet_aton
@@ -35,7 +35,7 @@
@ISA = qw(Exporter NetAddr::IP::Lite);
-$VERSION = do { sprintf " %d.%03d", (q$Revision: 4.53 $ =~ /\d+/g) };
+$VERSION = do { sprintf " %d.%03d", (q$Revision: 4.54 $ =~ /\d+/g) };
=pod
diff --git a/Lite/Calc.pm b/Lite/Calc.pm
deleted file mode 100644
index 43aad3d..0000000
--- a/Lite/Calc.pm
+++ /dev/null
@@ -1,162 +0,0 @@
-package NetAddr::IP::Calc;
-
-use diagnostics;
-use strict;
-use vars qw($VERSION);
-
-$VERSION = '1.997';
-
-# Package to store unsigned big integers in decimal and do math with them
-
-# Internally the numbers are stored in an array with at least 1 element, no
-# leading zero parts (except the first) and in base 1eX where X is determined
-# automatically at loading time to be the maximum possible value
-
-# todo:
-# - fully remove funky $# stuff in div() (maybe - that code scares me...)
-
-# USE_MUL: due to problems on certain os (os390, posix-bc) "* 1e-5" is used
-# instead of "/ 1e5" at some places, (marked with USE_MUL). Other platforms
-# BS2000, some Crays need USE_DIV instead.
-# The BEGIN block is used to determine which of the two variants gives the
-# correct result.
-
-# Beware of things like:
-# $i = $i * $y + $car; $car = int($i / $BASE); $i = $i % $BASE;
-# This works on x86, but fails on ARM (SA1100, iPAQ) due to whoknows what
-# reasons. So, use this instead (slower, but correct):
-# $i = $i * $y + $car; $car = int($i / $BASE); $i -= $BASE * $car;
-
-##############################################################################
-# global constants, flags and accessory
-
-# announce that we are compatible with MBI v1.83 and up
-sub api_version () { 2; }
-
-# constants for easier life
-my ($BASE,$BASE_LEN,$RBASE);
-
-sub _base_len
- {
- # Set/get the BASE_LEN and assorted other, connected values.
- # Used only by the testsuite, the set variant is used only by the BEGIN
- # block below:
- shift;
-
- my ($b, $int) = @_;
- if (defined $b)
- {
- if ($] >= 5.008 && $int && $b > 7)
- {
- $BASE_LEN = $b;
- $BASE = int("1e".$BASE_LEN);
- return $BASE_LEN;
- }
-
- # find whether we can use mul or div in mul()/div()
- $BASE_LEN = $b+1;
- my $caught = 0;
- while (--$BASE_LEN > 5)
- {
- $BASE = int("1e".$BASE_LEN);
- $RBASE = abs('1e-'.$BASE_LEN); # see USE_MUL
- $caught = 0;
- $caught += 1 if (int($BASE * $RBASE) != 1); # should be 1
- $caught += 2 if (int($BASE / $BASE) != 1); # should be 1
- last if $caught != 3;
- }
- }
- return $BASE_LEN;
- }
-
-sub _new
- {
- # (ref to string) return ref to num_array
- # Convert a number from string format (without sign) to internal base
- # 1ex format. Assumes normalized value as input.
- my $il = length($_[1])-1;
-
- # < BASE_LEN due len-1 above
- return [ int($_[1]) ] if $il < $BASE_LEN; # shortcut for short numbers
-
- # this leaves '00000' instead of int 0 and will be corrected after any op
- [ reverse(unpack("a" . ($il % $BASE_LEN+1)
- . ("a$BASE_LEN" x ($il / $BASE_LEN)), $_[1])) ];
- }
-
-BEGIN
- {
- # from Daniel Pfeiffer: determine largest group of digits that is precisely
- # multipliable with itself plus carry
- # Test now changed to expect the proper pattern, not a result off by 1 or 2
- my ($e, $num) = 3; # lowest value we will use is 3+1-1 = 3
- do
- {
- $num = ('9' x ++$e) + 0;
- $num *= $num + 1.0;
- } while ("$num" =~ /9{$e}0{$e}/); # must be a certain pattern
- $e--; # last test failed, so retract one step
- # the limits below brush the problems with the test above under the rug:
- # the test should be able to find the proper $e automatically
- $e = 5 if $^O =~ /^uts/; # UTS get's some special treatment
- $e = 5 if $^O =~ /^unicos/; # unicos is also problematic (6 seems to work
- # there, but we play safe)
-
- my $int = 0;
- if ($e > 7)
- {
- use integer;
- my $e1 = 7;
- $num = 7;
- do
- {
- $num = ('9' x ++$e1) + 0;
- $num *= $num + 1;
- } while ("$num" =~ /9{$e1}0{$e1}/); # must be a certain pattern
- $e1--; # last test failed, so retract one step
- if ($e1 > 7)
- {
- $int = 1; $e = $e1;
- }
- }
-
- __PACKAGE__->_base_len($e,$int); # set and store
- }
-
-=head1 LICENSE
-
-This program is free software; you may redistribute it and/or modify it under
-the same terms as Perl itself.
-
-=head1 AUTHORS
-
-=over 4
-
-=item *
-
-Original math code by Mark Biggar, rewritten by Tels L
-in late 2000.
-
-=item *
-
-Separated from BigInt and shaped API with the help of John Peacock.
-
-=item *
-
-Fixed, speed-up, streamlined and enhanced by Tels 2001 - 2007.
-
-=item *
-
-API documentation corrected and extended by Peter John Acklam,
-Epjacklam@online.noE
-
-=item *
-
-Shortened to base length check only for use with NetAddr::IP by
-Michael Robinton emichael@bizsystems.comE
-
-=back
-
-=cut
-
-1;
diff --git a/Lite/Changes b/Lite/Changes
index 88ba6ca..c1e72e8 100644
--- a/Lite/Changes
+++ b/Lite/Changes
@@ -1,5 +1,13 @@
Revision history for Perl extension NetAddr::IP::Lite
+1.37 Thu Oct 27 12:48:55 PDT 2011
+ add detection of early Math::Bigint 0.01 object structures
+ circa perl 5.6.1
+
+ remove Calc.pm as part of above
+
+ fix bug 71869 - a failed test routine
+
1.36 Wed Oct 26 08:52:34 PDT 2011
fix bug #71925. A a sub-varient of #62521 that showed up only for
short notation for IPv4. i.e. 127/n, 127.0/n, 127.0.0/n but
diff --git a/Lite/Lite.pm b/Lite/Lite.pm
index 2897f38..7c46956 100644
--- a/Lite/Lite.pm
+++ b/Lite/Lite.pm
@@ -11,7 +11,6 @@
isIPv4
inet_n2dx
inet_aton
-inet_ntoa
ipv6_aton
ipv6_n2x
);
@@ -32,7 +31,7 @@
use vars qw(@ISA @EXPORT_OK $VERSION $Accept_Binary_IP $Old_nth $AUTOLOAD *Zero);
-$VERSION = do { my @r = (q$Revision: 1.36 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r };
+$VERSION = do { my @r = (q$Revision: 1.37 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r };
require Exporter;
@@ -718,6 +717,16 @@
return sprintf("%d.%d.%d.%d",$1,$2,$3,$4);
}
+# function to stringify various flavors of Math::BigInt objects
+# tests to see if the object is a hash or a signed scalar
+#
+sub retMBIstring {
+ local *MBI = $_[0];
+ return (defined *MBI{HASH}) # recent version ?
+ ? join('',reverse @{$_[0]->{value}})
+ : do { ${$_[0]} =~ /(\d+)/; $1 };
+}
+
sub _xnew($$;$$) {
my $noctal = 0;
my $isV6 = shift;
@@ -727,15 +736,18 @@
}
my $proto = shift;
my $class = ref $proto || $proto || __PACKAGE__;
- my $ip = lc shift;
+ my $ip = shift;
+
$ip = 'default' unless defined $ip;
- $ip = join('',reverse @{$ip->{value}}) # treat as big bcd string
- if ref $ip && ref $ip eq 'Math::BigInt' && # can /CIDR notation
- ($ip->{sign} eq '+' ||
- die 'NetAddr::IP does not accept negative Math::BigInt numbers');
+ $ip = retMBIstring($ip) # treat as big bcd string
+ if ref $ip && ref $ip eq 'Math::BigInt'; # can /CIDR notation
my $hasmask = 1;
my($mask,$tmp);
+# IP to lower case AFTER ref test for Math::BigInt. 'lc' strips blessing
+
+ $ip = lc $ip;
+
while (1) {
# process IP's with no CIDR or that have the CIDR as part of the IP argument string
unless (@_) {
@@ -776,7 +788,7 @@
# $mask = lc $_[0];
}
# extract mask
- $mask = lc $_[0];
+ $mask = $_[0];
}
###
### process mask
@@ -801,10 +813,13 @@
# if either of the above conditions is true, $try contains the NetAddr 128 bit address
# checkfor Math::BigInt mask
- $mask = join('',reverse @{$mask->{value}}) # treat as big bcd string
- if ref $mask && ref $mask eq 'Math::BigInt' &&
- ($mask->{sign} eq '+' ||
- die 'NetAddr::IP does not accept negative Math::BigInt numbers');
+ $mask = retMBIstring($mask) # treat as big bcd string
+ if ref $mask && ref $mask eq 'Math::BigInt';
+
+# MASK to lower case AFTER ref test for Math::BigInt, 'lc' strips blessing
+
+ $mask = lc $mask;
+
if ($mask !~ /\D/) { # bcd or CIDR notation
my $isCIDR = length($mask) < 4 && $mask < 129;
if ($isV6) {
@@ -1192,29 +1207,39 @@
=cut
-my $biloaded;
-my $biapi;
+# as of this writing there are three known flavors of Math::BigInt
+# v0.01 MBI::new returns a scalar ref
+# v1.?? - 1.69 CALC::_new takes a reference to a scalar, returns an array, MBI returns a hash ref
+# v1.70 and up CALC::_new takes a scalar, returns and array, MBI returns a hash ref
-sub _biValue {
- unless ($biloaded) {
- if (eval {require Math::BigInt::Calc}) {
- $biloaded = \&Math::BigInt::Calc::_new;
- $biapi = eval {Math::BigInt::Calc::api_version()};
+my $biloaded;
+my $no_mbi_emu = 1;
+
+# function to force into test development mode
+#
+sub _force_bi_emu {
+ undef $biloaded;
+ $no_mbi_emu = 0;
+ print STDERR "\n\n\tWARNING: test development mode, this
+\tmessage SHOULD NEVER BE SEEN IN PRODUCTION!
+set my \$no_mbi_emu = 1 in t/bigint.t to remove this warning\n\n";
+}
+
+# from bi string like Math::BigInt 0.01
+#
+sub _bi_fake {
+ bless \('+'. $_[1]), 'Math::BigInt';
+}
+
+sub _biRef {
+ unless ($biloaded) { # load Math::BigInt on demand
+ if (eval {$no_mbi_emu && require Math::BigInt}) { # any version should work, three known
+ $biloaded = \&Math::BigInt::new;
} else {
- require NetAddr::IP::Calc;
- $biloaded = \&NetAddr::IP::Calc::_new;
- $biapi = 99;
+ $biloaded = \&_bi_fake;
}
}
-print "BIAPI=$biapi\n";
- my $biarray = $biapi
- ? $biloaded->(undef,$_[0])
- : $biloaded->(undef,\$_[0]); # versions before 1.70 expect a reference
-
- bless {
- sign => '+',
- value => $biarray,
- }, 'Math::BigInt';
+ $biloaded->('Math::BigInt',$_[0]);
}
sub bigint($) {
@@ -1236,7 +1261,7 @@
? bin2bcd($_[0]->{mask})
: 0;
}
- (_biValue($addr),_biValue($mask));
+ (_biRef($addr),_biRef($mask));
} else { # not wantarray
@@ -1249,7 +1274,7 @@
? bin2bcd($_[0]->{addr})
: 0;
}
- _biValue($addr);
+ _biRef($addr);
}
}
diff --git a/Lite/MANIFEST b/Lite/MANIFEST
index 57a22da..600fe4c 100644
--- a/Lite/MANIFEST
+++ b/Lite/MANIFEST
@@ -1,7 +1,6 @@
MANIFEST
MANIFEST.SKIP
Changes
-Calc.pm
Lite.pm
Makefile.PL
META.yml
diff --git a/Lite/t/bigint.t b/Lite/t/bigint.t
index ae4e702..b854558 100644
--- a/Lite/t/bigint.t
+++ b/Lite/t/bigint.t
@@ -4,662 +4,167 @@
use Test::More;
use NetAddr::IP::Lite;
+use NetAddr::IP::Util qw(
+ bcd2bin
+ bin2bcd
+ addconst
+ shiftleft
+);
use Data::Dumper;
-BEGIN {
- unless ( eval { require Math::BigInt::Calc }) {
- print "1..1\n";
- print "ok 1 # skip all tests, Math::BigInt::Calc not found!\n";
+sub badd { # function to add a small int to bignum string
+ my($n,$i) = @_;
+ my $v = bcd2bin($n);
+ (undef,$v) = addconst($v,$i);
+ bin2bcd($v);
+}
+
+sub xpo2 { # function to do a n^2 multiplication
+ my($n,$x) = @_;
+ my $v = bcd2bin($n);
+ my $c = 0;
+ while ($x >>= 1) {$c++}
+ $v = shiftleft($v,$c);
+ bin2bcd($v);
+}
+
+my $no_mbi_emu = 1; # set this to "1" for normal, "0" for development
+
+unless (eval{ $no_mbi_emu && require Math::BigInt }) {
+ if ($no_mbi_emu) {
+ print "1..1\nok 1 # skipped all, Math::BigInt not found\n";
exit;
}
+
+ &NetAddr::IP::Lite::_force_bi_emu;
+
+ package Math::BigInt;
+ my $badd = \&main::badd;
+ require overload;
+ import overload
+ '""' => sub {
+ ${$_[0]} =~ /(\d+)/;
+ return $1;
+ },
+ '+' => sub {
+ ${$_[0]} =~ /(\d+)/;
+ $b = '+'. main::badd($1,$_[1]);
+ bless \$b;
+ };
+ *new = \&NetAddr::IP::Lite::_bi_fake;
}
-# good test results go here
-my $build = q|
-not ok 1
-# Failed test in test.pl at line 39.
-# got: '4294967294'
-# expected: undef
-not ok 2
-# Failed test in test.pl at line 41.
-# got: '255.255.255.254/32'
-# expected: undef
-not ok 3
-# Failed test in test.pl at line 39.
-# got: '4294967295'
-# expected: undef
-not ok 4
-# Failed test in test.pl at line 41.
-# got: '255.255.255.255/32'
-# expected: undef
-not ok 5
-# Failed test in test.pl at line 39.
-# got: '4294967296'
-# expected: undef
-not ok 6
-# Failed test in test.pl at line 41.
-# got: '0:0:0:0:0:1:0:0/128'
-# expected: undef
-not ok 7
-# Failed test in test.pl at line 39.
-# got: '4294967297'
-# expected: undef
-not ok 8
-# Failed test in test.pl at line 41.
-# got: '0:0:0:0:0:1:0:1/128'
-# expected: undef
-not ok 9
-# Failed test in test.pl at line 39.
-# got: '4294967298'
-# expected: undef
-not ok 10
-# Failed test in test.pl at line 41.
-# got: '0:0:0:0:0:1:0:2/128'
-# expected: undef
-not ok 11
-# Failed test in test.pl at line 39.
-# got: '340282366920938463463374607431768211454'
-# expected: undef
-not ok 12
-# Failed test in test.pl at line 41.
-# got: 'FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFE/128'
-# expected: undef
-not ok 13
-# Failed test in test.pl at line 39.
-# got: '340282366920938463463374607431768211455'
-# expected: undef
-not ok 14
-# Failed test in test.pl at line 41.
-# got: 'FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF/128'
-# expected: undef
-not ok 15
-# Failed test in test.pl at line 39.
-# got: '340282366920938463463374607431768211456'
-# expected: undef
-not ok 16
-# Failed test in test.pl at line 41.
-# got: '0.0.0.0/32'
-# expected: undef
-not ok 17
-# Failed test in test.pl at line 39.
-# got: '1'
-# expected: undef
-not ok 18
-# Failed test in test.pl at line 41.
-# got: '0.0.0.1/32'
-# expected: undef
-not ok 19
-# Failed test in test.pl at line 39.
-# got: '2'
-# expected: undef
-not ok 20
-# Failed test in test.pl at line 41.
-# got: '0.0.0.2/32'
-# expected: undef
-not ok 21
-# Failed test in test.pl at line 63.
-# got: '2066563929'
-# expected: undef
-not ok 22
-# Failed test in test.pl at line 64.
-# got: '4294967295'
-# expected: undef
-not ok 23
-# Failed test in test.pl at line 65.
-# got: '123.45.67.89/32'
-# expected: undef
-not ok 24
-# Failed test in test.pl at line 63.
-# got: '2066563929'
-# expected: undef
-not ok 25
-# Failed test in test.pl at line 64.
-# got: '4294967280'
-# expected: undef
-not ok 26
-# Failed test in test.pl at line 65.
-# got: '123.45.67.89/28'
-# expected: undef
-not ok 27
-# Failed test in test.pl at line 63.
-# got: '2066563929'
-# expected: undef
-not ok 28
-# Failed test in test.pl at line 64.
-# got: '4294967040'
-# expected: undef
-not ok 29
-# Failed test in test.pl at line 65.
-# got: '123.45.67.89/24'
-# expected: undef
-not ok 30
-# Failed test in test.pl at line 63.
-# got: '2066563929'
-# expected: undef
-not ok 31
-# Failed test in test.pl at line 64.
-# got: '4294963200'
-# expected: undef
-not ok 32
-# Failed test in test.pl at line 65.
-# got: '123.45.67.89/20'
-# expected: undef
-not ok 33
-# Failed test in test.pl at line 63.
-# got: '2066563929'
-# expected: undef
-not ok 34
-# Failed test in test.pl at line 64.
-# got: '4294901760'
-# expected: undef
-not ok 35
-# Failed test in test.pl at line 65.
-# got: '123.45.67.89/16'
-# expected: undef
-not ok 36
-# Failed test in test.pl at line 63.
-# got: '2066563929'
-# expected: undef
-not ok 37
-# Failed test in test.pl at line 64.
-# got: '4293918720'
-# expected: undef
-not ok 38
-# Failed test in test.pl at line 65.
-# got: '123.45.67.89/12'
-# expected: undef
-not ok 39
-# Failed test in test.pl at line 63.
-# got: '2066563929'
-# expected: undef
-not ok 40
-# Failed test in test.pl at line 64.
-# got: '4278190080'
-# expected: undef
-not ok 41
-# Failed test in test.pl at line 65.
-# got: '123.45.67.89/8'
-# expected: undef
-not ok 42
-# Failed test in test.pl at line 63.
-# got: '2066563929'
-# expected: undef
-not ok 43
-# Failed test in test.pl at line 64.
-# got: '4026531840'
-# expected: undef
-not ok 44
-# Failed test in test.pl at line 65.
-# got: '123.45.67.89/4'
-# expected: undef
-not ok 45
-# Failed test in test.pl at line 63.
-# got: '2066563929'
-# expected: undef
-not ok 46
-# Failed test in test.pl at line 64.
-# got: '0'
-# expected: undef
-not ok 47
-# Failed test in test.pl at line 65.
-# got: '123.45.67.89/0'
-# expected: undef
-not ok 48
-# Failed test in test.pl at line 63.
-# got: '170145699920964442595609400891477785294'
-# expected: undef
-not ok 49
-# Failed test in test.pl at line 64.
-# got: '340282366920938463463374607431768211455'
-# expected: undef
-not ok 50
-# Failed test in test.pl at line 65.
-# got: '8000:DEAD:BEEF:4:CAFE:BAD:2:FACE/128'
-# expected: undef
-not ok 51
-# Failed test in test.pl at line 63.
-# got: '170145699920964442595609400891477785294'
-# expected: undef
-not ok 52
-# Failed test in test.pl at line 64.
-# got: '340282366920938463463374607431768211440'
-# expected: undef
-not ok 53
-# Failed test in test.pl at line 65.
-# got: '8000:DEAD:BEEF:4:CAFE:BAD:2:FACE/124'
-# expected: undef
-not ok 54
-# Failed test in test.pl at line 63.
-# got: '170145699920964442595609400891477785294'
-# expected: undef
-not ok 55
-# Failed test in test.pl at line 64.
-# got: '340282366920938463463374607431768211200'
-# expected: undef
-not ok 56
-# Failed test in test.pl at line 65.
-# got: '8000:DEAD:BEEF:4:CAFE:BAD:2:FACE/120'
-# expected: undef
-not ok 57
-# Failed test in test.pl at line 63.
-# got: '170145699920964442595609400891477785294'
-# expected: undef
-not ok 58
-# Failed test in test.pl at line 64.
-# got: '340282366920938463463374607431768207360'
-# expected: undef
-not ok 59
-# Failed test in test.pl at line 65.
-# got: '8000:DEAD:BEEF:4:CAFE:BAD:2:FACE/116'
-# expected: undef
-not ok 60
-# Failed test in test.pl at line 63.
-# got: '170145699920964442595609400891477785294'
-# expected: undef
-not ok 61
-# Failed test in test.pl at line 64.
-# got: '340282366920938463463374607431768145920'
-# expected: undef
-not ok 62
-# Failed test in test.pl at line 65.
-# got: '8000:DEAD:BEEF:4:CAFE:BAD:2:FACE/112'
-# expected: undef
-not ok 63
-# Failed test in test.pl at line 63.
-# got: '170145699920964442595609400891477785294'
-# expected: undef
-not ok 64
-# Failed test in test.pl at line 64.
-# got: '340282366920938463463374607431767162880'
-# expected: undef
-not ok 65
-# Failed test in test.pl at line 65.
-# got: '8000:DEAD:BEEF:4:CAFE:BAD:2:FACE/108'
-# expected: undef
-not ok 66
-# Failed test in test.pl at line 63.
-# got: '170145699920964442595609400891477785294'
-# expected: undef
-not ok 67
-# Failed test in test.pl at line 64.
-# got: '340282366920938463463374607431751434240'
-# expected: undef
-not ok 68
-# Failed test in test.pl at line 65.
-# got: '8000:DEAD:BEEF:4:CAFE:BAD:2:FACE/104'
-# expected: undef
-not ok 69
-# Failed test in test.pl at line 63.
-# got: '170145699920964442595609400891477785294'
-# expected: undef
-not ok 70
-# Failed test in test.pl at line 64.
-# got: '340282366920938463463374607431499776000'
-# expected: undef
-not ok 71
-# Failed test in test.pl at line 65.
-# got: '8000:DEAD:BEEF:4:CAFE:BAD:2:FACE/100'
-# expected: undef
-not ok 72
-# Failed test in test.pl at line 63.
-# got: '170145699920964442595609400891477785294'
-# expected: undef
-not ok 73
-# Failed test in test.pl at line 64.
-# got: '340282366920938463463374607427473244160'
-# expected: undef
-not ok 74
-# Failed test in test.pl at line 65.
-# got: '8000:DEAD:BEEF:4:CAFE:BAD:2:FACE/96'
-# expected: undef
-not ok 75
-# Failed test in test.pl at line 63.
-# got: '170145699920964442595609400891477785294'
-# expected: undef
-not ok 76
-# Failed test in test.pl at line 64.
-# got: '340282366920938463463374607363048734720'
-# expected: undef
-not ok 77
-# Failed test in test.pl at line 65.
-# got: '8000:DEAD:BEEF:4:CAFE:BAD:2:FACE/92'
-# expected: undef
-not ok 78
-# Failed test in test.pl at line 63.
-# got: '170145699920964442595609400891477785294'
-# expected: undef
-not ok 79
-# Failed test in test.pl at line 64.
-# got: '340282366920938463463374606332256583680'
-# expected: undef
-not ok 80
-# Failed test in test.pl at line 65.
-# got: '8000:DEAD:BEEF:4:CAFE:BAD:2:FACE/88'
-# expected: undef
-not ok 81
-# Failed test in test.pl at line 63.
-# got: '170145699920964442595609400891477785294'
-# expected: undef
-not ok 82
-# Failed test in test.pl at line 64.
-# got: '340282366920938463463374589839582167040'
-# expected: undef
-not ok 83
-# Failed test in test.pl at line 65.
-# got: '8000:DEAD:BEEF:4:CAFE:BAD:2:FACE/84'
-# expected: undef
-not ok 84
-# Failed test in test.pl at line 63.
-# got: '170145699920964442595609400891477785294'
-# expected: undef
-not ok 85
-# Failed test in test.pl at line 64.
-# got: '340282366920938463463374325956791500800'
-# expected: undef
-not ok 86
-# Failed test in test.pl at line 65.
-# got: '8000:DEAD:BEEF:4:CAFE:BAD:2:FACE/80'
-# expected: undef
-not ok 87
-# Failed test in test.pl at line 63.
-# got: '170145699920964442595609400891477785294'
-# expected: undef
-not ok 88
-# Failed test in test.pl at line 64.
-# got: '340282366920938463463370103832140840960'
-# expected: undef
-not ok 89
-# Failed test in test.pl at line 65.
-# got: '8000:DEAD:BEEF:4:CAFE:BAD:2:FACE/76'
-# expected: undef
-not ok 90
-# Failed test in test.pl at line 63.
-# got: '170145699920964442595609400891477785294'
-# expected: undef
-not ok 91
-# Failed test in test.pl at line 64.
-# got: '340282366920938463463302549837730283520'
-# expected: undef
-not ok 92
-# Failed test in test.pl at line 65.
-# got: '8000:DEAD:BEEF:4:CAFE:BAD:2:FACE/72'
-# expected: undef
-not ok 93
-# Failed test in test.pl at line 63.
-# got: '170145699920964442595609400891477785294'
-# expected: undef
-not ok 94
-# Failed test in test.pl at line 64.
-# got: '340282366920938463462221685927161364480'
-# expected: undef
-not ok 95
-# Failed test in test.pl at line 65.
-# got: '8000:DEAD:BEEF:4:CAFE:BAD:2:FACE/68'
-# expected: undef
-not ok 96
-# Failed test in test.pl at line 63.
-# got: '170145699920964442595609400891477785294'
-# expected: undef
-not ok 97
-# Failed test in test.pl at line 64.
-# got: '340282366920938463444927863358058659840'
-# expected: undef
-not ok 98
-# Failed test in test.pl at line 65.
-# got: '8000:DEAD:BEEF:4:CAFE:BAD:2:FACE/64'
-# expected: undef
-not ok 99
-# Failed test in test.pl at line 63.
-# got: '170145699920964442595609400891477785294'
-# expected: undef
-not ok 100
-# Failed test in test.pl at line 64.
-# got: '340282366920938463168226702252415385600'
-# expected: undef
-not ok 101
-# Failed test in test.pl at line 65.
-# got: '8000:DEAD:BEEF:4:CAFE:BAD:2:FACE/60'
-# expected: undef
-not ok 102
-# Failed test in test.pl at line 63.
-# got: '170145699920964442595609400891477785294'
-# expected: undef
-not ok 103
-# Failed test in test.pl at line 64.
-# got: '340282366920938458741008124562122997760'
-# expected: undef
-not ok 104
-# Failed test in test.pl at line 65.
-# got: '8000:DEAD:BEEF:4:CAFE:BAD:2:FACE/56'
-# expected: undef
-not ok 105
-# Failed test in test.pl at line 63.
-# got: '170145699920964442595609400891477785294'
-# expected: undef
-not ok 106
-# Failed test in test.pl at line 64.
-# got: '340282366920938387905510881517444792320'
-# expected: undef
-not ok 107
-# Failed test in test.pl at line 65.
-# got: '8000:DEAD:BEEF:4:CAFE:BAD:2:FACE/52'
-# expected: undef
-not ok 108
-# Failed test in test.pl at line 63.
-# got: '170145699920964442595609400891477785294'
-# expected: undef
-not ok 109
-# Failed test in test.pl at line 64.
-# got: '340282366920937254537554992802593505280'
-# expected: undef
-not ok 110
-# Failed test in test.pl at line 65.
-# got: '8000:DEAD:BEEF:4:CAFE:BAD:2:FACE/48'
-# expected: undef
-not ok 111
-# Failed test in test.pl at line 63.
-# got: '170145699920964442595609400891477785294'
-# expected: undef
-not ok 112
-# Failed test in test.pl at line 64.
-# got: '340282366920919120650260773364972912640'
-# expected: undef
-not ok 113
-# Failed test in test.pl at line 65.
-# got: '8000:DEAD:BEEF:4:CAFE:BAD:2:FACE/44'
-# expected: undef
-not ok 114
-# Failed test in test.pl at line 63.
-# got: '170145699920964442595609400891477785294'
-# expected: undef
-not ok 115
-# Failed test in test.pl at line 64.
-# got: '340282366920628978453553262363043430400'
-# expected: undef
-not ok 116
-# Failed test in test.pl at line 65.
-# got: '8000:DEAD:BEEF:4:CAFE:BAD:2:FACE/40'
-# expected: undef
-not ok 117
-# Failed test in test.pl at line 63.
-# got: '170145699920964442595609400891477785294'
-# expected: undef
-not ok 118
-# Failed test in test.pl at line 64.
-# got: '340282366915986703306233086332171714560'
-# expected: undef
-not ok 119
-# Failed test in test.pl at line 65.
-# got: '8000:DEAD:BEEF:4:CAFE:BAD:2:FACE/36'
-# expected: undef
-not ok 120
-# Failed test in test.pl at line 63.
-# got: '170145699920964442595609400891477785294'
-# expected: undef
-not ok 121
-# Failed test in test.pl at line 64.
-# got: '340282366841710300949110269838224261120'
-# expected: undef
-not ok 122
-# Failed test in test.pl at line 65.
-# got: '8000:DEAD:BEEF:4:CAFE:BAD:2:FACE/32'
-# expected: undef
-not ok 123
-# Failed test in test.pl at line 63.
-# got: '170145699920964442595609400891477785294'
-# expected: undef
-not ok 124
-# Failed test in test.pl at line 64.
-# got: '340282365653287863235145205935065006080'
-# expected: undef
-not ok 125
-# Failed test in test.pl at line 65.
-# got: '8000:DEAD:BEEF:4:CAFE:BAD:2:FACE/28'
-# expected: undef
-not ok 126
-# Failed test in test.pl at line 63.
-# got: '170145699920964442595609400891477785294'
-# expected: undef
-not ok 127
-# Failed test in test.pl at line 64.
-# got: '340282346638528859811704183484516925440'
-# expected: undef
-not ok 128
-# Failed test in test.pl at line 65.
-# got: '8000:DEAD:BEEF:4:CAFE:BAD:2:FACE/24'
-# expected: undef
-not ok 129
-# Failed test in test.pl at line 63.
-# got: '170145699920964442595609400891477785294'
-# expected: undef
-not ok 130
-# Failed test in test.pl at line 64.
-# got: '340282042402384805036647824275747635200'
-# expected: undef
-not ok 131
-# Failed test in test.pl at line 65.
-# got: '8000:DEAD:BEEF:4:CAFE:BAD:2:FACE/20'
-# expected: undef
-not ok 132
-# Failed test in test.pl at line 63.
-# got: '170145699920964442595609400891477785294'
-# expected: undef
-not ok 133
-# Failed test in test.pl at line 64.
-# got: '340277174624079928635746076935438991360'
-# expected: undef
-not ok 134
-# Failed test in test.pl at line 65.
-# got: '8000:DEAD:BEEF:4:CAFE:BAD:2:FACE/16'
-# expected: undef
-not ok 135
-# Failed test in test.pl at line 63.
-# got: '170145699920964442595609400891477785294'
-# expected: undef
-not ok 136
-# Failed test in test.pl at line 64.
-# got: '340199290171201906221318119490500689920'
-# expected: undef
-not ok 137
-# Failed test in test.pl at line 65.
-# got: '8000:DEAD:BEEF:4:CAFE:BAD:2:FACE/12'
-# expected: undef
-not ok 138
-# Failed test in test.pl at line 63.
-# got: '170145699920964442595609400891477785294'
-# expected: undef
-not ok 139
-# Failed test in test.pl at line 64.
-# got: '338953138925153547590470800371487866880'
-# expected: undef
-not ok 140
-# Failed test in test.pl at line 65.
-# got: '8000:DEAD:BEEF:4:CAFE:BAD:2:FACE/8'
-# expected: undef
-not ok 141
-# Failed test in test.pl at line 63.
-# got: '170145699920964442595609400891477785294'
-# expected: undef
-not ok 142
-# Failed test in test.pl at line 64.
-# got: '319014718988379809496913694467282698240'
-# expected: undef
-not ok 143
-# Failed test in test.pl at line 65.
-# got: '8000:DEAD:BEEF:4:CAFE:BAD:2:FACE/4'
-# expected: undef
-not ok 144
-# Failed test in test.pl at line 63.
-# got: '170145699920964442595609400891477785294'
-# expected: undef
-not ok 145
-# Failed test in test.pl at line 64.
-# got: '0'
-# expected: undef
-not ok 146
-# Failed test in test.pl at line 65.
-# got: '8000:DEAD:BEEF:4:CAFE:BAD:2:FACE/0'
-# expected: undef
-
-|;
-
-my @exp;
-
-my @build = split("\n",$build);
-foreach (@build) {
- next unless $_ =~ /got:\s+'(.+)'/;
- push @exp, $1;
-}
+my @exp = (qw(
+ 255.255.255.253/32 4294967293 4294967295
+ 255.255.255.254/32 4294967294 4294967295
+ 255.255.255.255/32 4294967295 4294967295
+ 0:0:0:0:0:1:0:0/128 4294967296 4294967295
+ 0:0:0:0:0:1:0:1/128 4294967297 4294967295
+ 0:0:0:0:0:1:0:2/128 4294967298 4294967295
+ FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFD/128 340282366920938463463374607431768211453 340282366920938463463374607431768211455
+ FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFE/128 340282366920938463463374607431768211454 340282366920938463463374607431768211455
+ FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF/128 340282366920938463463374607431768211455 340282366920938463463374607431768211455
+ 0.0.0.0/32 0 4294967295
+ 0.0.0.1/32 1 4294967295
+ 0.0.0.2/32 2 4294967295
+ 123.45.67.89/32 2066563929 4294967295
+ 123.45.67.89/28 2066563929 4294967280
+ 123.45.67.89/24 2066563929 4294967040
+ 123.45.67.89/20 2066563929 4294963200
+ 123.45.67.89/16 2066563929 4294901760
+ 123.45.67.89/12 2066563929 4293918720
+ 123.45.67.89/8 2066563929 4278190080
+ 123.45.67.89/4 2066563929 4026531840
+ 123.45.67.89/0 2066563929 0
+ 8000:DEAD:BEEF:4:CAFE:BAD:2:FACE/128 170145699920964442595609400891477785294 340282366920938463463374607431768211455
+ 8000:DEAD:BEEF:4:CAFE:BAD:2:FACE/124 170145699920964442595609400891477785294 340282366920938463463374607431768211440
+ 8000:DEAD:BEEF:4:CAFE:BAD:2:FACE/120 170145699920964442595609400891477785294 340282366920938463463374607431768211200
+ 8000:DEAD:BEEF:4:CAFE:BAD:2:FACE/116 170145699920964442595609400891477785294 340282366920938463463374607431768207360
+ 8000:DEAD:BEEF:4:CAFE:BAD:2:FACE/112 170145699920964442595609400891477785294 340282366920938463463374607431768145920
+ 8000:DEAD:BEEF:4:CAFE:BAD:2:FACE/108 170145699920964442595609400891477785294 340282366920938463463374607431767162880
+ 8000:DEAD:BEEF:4:CAFE:BAD:2:FACE/104 170145699920964442595609400891477785294 340282366920938463463374607431751434240
+ 8000:DEAD:BEEF:4:CAFE:BAD:2:FACE/100 170145699920964442595609400891477785294 340282366920938463463374607431499776000
+ 8000:DEAD:BEEF:4:CAFE:BAD:2:FACE/96 170145699920964442595609400891477785294 340282366920938463463374607427473244160
+ 8000:DEAD:BEEF:4:CAFE:BAD:2:FACE/92 170145699920964442595609400891477785294 340282366920938463463374607363048734720
+ 8000:DEAD:BEEF:4:CAFE:BAD:2:FACE/88 170145699920964442595609400891477785294 340282366920938463463374606332256583680
+ 8000:DEAD:BEEF:4:CAFE:BAD:2:FACE/84 170145699920964442595609400891477785294 340282366920938463463374589839582167040
+ 8000:DEAD:BEEF:4:CAFE:BAD:2:FACE/80 170145699920964442595609400891477785294 340282366920938463463374325956791500800
+ 8000:DEAD:BEEF:4:CAFE:BAD:2:FACE/76 170145699920964442595609400891477785294 340282366920938463463370103832140840960
+ 8000:DEAD:BEEF:4:CAFE:BAD:2:FACE/72 170145699920964442595609400891477785294 340282366920938463463302549837730283520
+ 8000:DEAD:BEEF:4:CAFE:BAD:2:FACE/68 170145699920964442595609400891477785294 340282366920938463462221685927161364480
+ 8000:DEAD:BEEF:4:CAFE:BAD:2:FACE/64 170145699920964442595609400891477785294 340282366920938463444927863358058659840
+ 8000:DEAD:BEEF:4:CAFE:BAD:2:FACE/60 170145699920964442595609400891477785294 340282366920938463168226702252415385600
+ 8000:DEAD:BEEF:4:CAFE:BAD:2:FACE/56 170145699920964442595609400891477785294 340282366920938458741008124562122997760
+ 8000:DEAD:BEEF:4:CAFE:BAD:2:FACE/52 170145699920964442595609400891477785294 340282366920938387905510881517444792320
+ 8000:DEAD:BEEF:4:CAFE:BAD:2:FACE/48 170145699920964442595609400891477785294 340282366920937254537554992802593505280
+ 8000:DEAD:BEEF:4:CAFE:BAD:2:FACE/44 170145699920964442595609400891477785294 340282366920919120650260773364972912640
+ 8000:DEAD:BEEF:4:CAFE:BAD:2:FACE/40 170145699920964442595609400891477785294 340282366920628978453553262363043430400
+ 8000:DEAD:BEEF:4:CAFE:BAD:2:FACE/36 170145699920964442595609400891477785294 340282366915986703306233086332171714560
+ 8000:DEAD:BEEF:4:CAFE:BAD:2:FACE/32 170145699920964442595609400891477785294 340282366841710300949110269838224261120
+ 8000:DEAD:BEEF:4:CAFE:BAD:2:FACE/28 170145699920964442595609400891477785294 340282365653287863235145205935065006080
+ 8000:DEAD:BEEF:4:CAFE:BAD:2:FACE/24 170145699920964442595609400891477785294 340282346638528859811704183484516925440
+ 8000:DEAD:BEEF:4:CAFE:BAD:2:FACE/20 170145699920964442595609400891477785294 340282042402384805036647824275747635200
+ 8000:DEAD:BEEF:4:CAFE:BAD:2:FACE/16 170145699920964442595609400891477785294 340277174624079928635746076935438991360
+ 8000:DEAD:BEEF:4:CAFE:BAD:2:FACE/12 170145699920964442595609400891477785294 340199290171201906221318119490500689920
+ 8000:DEAD:BEEF:4:CAFE:BAD:2:FACE/8 170145699920964442595609400891477785294 338953138925153547590470800371487866880
+ 8000:DEAD:BEEF:4:CAFE:BAD:2:FACE/4 170145699920964442595609400891477785294 319014718988379809496913694467282698240
+ 8000:DEAD:BEEF:4:CAFE:BAD:2:FACE/0 170145699920964442595609400891477785294 0
+));
my $ptr = 0;
-my $max = @exp;
+my $max = @exp -11;
plan tests => $max || 1;
-my $ip = new NetAddr::IP::Lite('255.255.255.253');
-
sub run {
foreach(1..5) {
+ my $ip = new NetAddr::IP::Lite($exp[$ptr]);
my $mbi = $ip->bigint();
- $mbi++;
- is($mbi, $exp[$ptr++]);
+ $mbi = $mbi + 1;
+#print $ip,"\n";
+#print Dumper $mbi;
+#print $exp[$ptr+1],"\n";
+ like($mbi, qr/(?:0|$exp[$ptr+4])/);
$ip = new NetAddr::IP::Lite($mbi);
- is($ip, $exp[$ptr++]);
+ is($ip, $exp[$ptr+3]);
+ pass(); # ignore mask for these tests
+ $ptr += 3;
}
}
run();
-$ip = new NetAddr::IP::Lite('FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFD');
+$ptr += 3;
run();
-sub mrun {
- my ($jump) = @_;
- my($mbia,$mbim) = $ip->bigint();
+$ptr += 3;
-#print $ip,"\n";
+sub mrun {
+ my $n = shift;
+ foreach(1..$n) {
+ my $ip = new NetAddr::IP::Lite($exp[$ptr]);
+ my ($mbia,$mbim) = $ip->bigint();
+ my($ary,$msk,$eip) = @exp[$ptr+1,$ptr+2,$ptr+3];
+ $ptr += 3;
+#print $msk,"\n";
#print Dumper $mbia;
#print Dumper $mbim;
-
- $ip = new NetAddr::IP::Lite($mbia,$mbim);
-
- while(1) {
- ($mbia,$mbim) = $ip->bigint();
- my($ary,$msk,$eip) = @exp[$ptr,$ptr+1,$ptr+2];
- $ptr += 3;
- is($mbia, $ary);
- is($mbim, $msk);
- is($ip, $eip);
+ like($mbia, qr/$ary/);
+ like($mbim, qr/$msk/);
my $len = $ip->masklen();
last unless $len;
last if $ptr > $max + 200; # loop stop, just in case
- $mbim *= $jump;
+#print Dumper $mbim;
+ $mbim = new Math::BigInt($exp[$ptr+2]);
+#print Dumper $mbim;
+#print Dumper $mbia;
$ip = new NetAddr::IP::Lite($mbia,$mbim);
+ is($ip, $eip);
+#print '|',$ip,"|\n";
}
}
-$ip = new NetAddr::IP::Lite('123.45.67.89');
-mrun(16);
+mrun(9);
-$ip = new NetAddr::IP::Lite('8000:dead:beef:4:cafe:bad:2:face');
+$ptr += 3;
-mrun(16);
+mrun(32);
diff --git a/MANIFEST b/MANIFEST
index 6f5c5c0..6a369ec 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -37,7 +37,6 @@
t/v6-splitplan.t
t/wildcard.t
Lite/Changes
-Lite/Calc.pm
Lite/Lite.pm
Lite/MANIFEST
Lite/MANIFEST.SKIP
diff --git a/META.yml b/META.yml
index a03c3c6..8457fdd 100644
--- a/META.yml
+++ b/META.yml
@@ -1,6 +1,6 @@
--- #YAML:1.0
name: NetAddr-IP
-version: 4.052
+version: 4.054
abstract: Manages IPv4 and IPv6 addresses and subnets
license: ~
author: