diff --git a/Changes b/Changes index 68d6583..685cae6 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,12 @@ Revision history for Perl extension NetAddr::IP +4.014 Sat Nov 1 15:13:48 PST 2008 + in Lite.pm v1.11, add test for characters not allowed by + rfc952 before the call to gethostbyname in sub new() for those + people that insist on using deprecated functionality :aton + and OS's that fail to notice calls to gethostbyname with + binary arguments. + 4.013 Wed Oct 22 15:04:49 PDT 2008 In Lite.pm v1.10, add new no octal method for improperly formatted ipV4 addresses diff --git a/IP.pm b/IP.pm index 52b368a..29114d4 100644 --- a/IP.pm +++ b/IP.pm @@ -4,8 +4,8 @@ use strict; #use diagnostics; -use NetAddr::IP::Lite 1.07 qw(Zero Ones V4mask V4net); -use NetAddr::IP::Util 1.20 qw( +use NetAddr::IP::Lite 1.11 qw(Zero Ones V4mask V4net); +use NetAddr::IP::Util 1.22 qw( sub128 inet_aton inet_any2n @@ -31,7 +31,7 @@ @ISA = qw(Exporter NetAddr::IP::Lite); -$VERSION = do { sprintf " %d.%03d", (q$Revision: 4.13 $ =~ /\d+/g) }; +$VERSION = do { sprintf " %d.%03d", (q$Revision: 4.14 $ =~ /\d+/g) }; =pod diff --git a/Lite/Changes b/Lite/Changes index 515c0bf..195b2f3 100644 --- a/Lite/Changes +++ b/Lite/Changes @@ -1,5 +1,12 @@ Revision history for Perl extension NetAddr::IP::Lite +1.11 Sat Nov 1 15:13:48 PST 2008 + add test for characters not allowed by rfc952before + the call to gethostbyname in sub new() for those people + that insist on using deprecated functionality :aton + and OS's that fail to notice calls to gethostbyname + with binary arguments + 1.10 Wed Oct 22 14:54:12 PDT 2008 add new no octal method for improperly formatted ipV4 addresses diff --git a/Lite/Lite.pm b/Lite/Lite.pm index 0ba29e3..321de37 100644 --- a/Lite/Lite.pm +++ b/Lite/Lite.pm @@ -27,7 +27,7 @@ ); use vars qw(@ISA @EXPORT_OK $VERSION $Accept_Binary_IP $Old_nth $AUTOLOAD); -$VERSION = do { my @r = (q$Revision: 1.10 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r }; +$VERSION = do { my @r = (q$Revision: 1.11 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r }; require Exporter; @@ -157,6 +157,10 @@ =cut +# these really should be packed in Network Long order but since they are +# symetrical, that extra internal processing can be skipped + +my $_v4zero = pack('L',0); my $_zero = pack('L4',0,0,0,0); my $_ones = ~$_zero; my $_v4mask = pack('L4',0xffffffff,0xffffffff,0xffffffff,0); @@ -778,7 +782,7 @@ return undef if hasbits($ip & $tmp); last; } - elsif (($tmp = gethostbyname($ip)) && $tmp ne pack('L',0) ) { + elsif ($ip !~ /[^a-zA-Z0-9\.-]/ && ($tmp = gethostbyname($ip)) && $tmp ne $_v4zero && $tmp ne $_zero ) { $ip = ipv4to6($tmp); last; } diff --git a/Lite/t/v4-aton.t b/Lite/t/v4-aton.t index adc49cd..6673399 100644 --- a/Lite/t/v4-aton.t +++ b/Lite/t/v4-aton.t @@ -1,5 +1,4 @@ -use Test::More tests => 18; -use Socket; +use Test::More tests => 19; my @addr = ( [ 'localhost', '127.0.0.1' ], @@ -9,30 +8,52 @@ [ '10.0.0.1', '10.0.0.1' ], ); +my %addr = ( + localhost => pack('N',0x7f000001), + broadcast => pack('N',0xffffffff), + '254.254.0.1' => pack('N',0xfefe0001), + default => pack('N',0), + '10.0.0.1' => pack('N',0x0a000001), + '127.0.0.1' => pack('N',0x7f000001), + '255.255.255.255' => pack('N',0xffffffff), + '0.0.0.0' => pack('N',0), +); + +# local inet_aton, don't use perl's Socket + +sub l_inet_aton { + my $rv = (exists $addr{$_[0]}) ? $addr{$_[0]} : undef; +} + # Verify that Accept_Binary_IP works... +my $x; + SKIP: { skip "Failed to load NetAddr::IP::Lite", 17 unless use_ok('NetAddr::IP::Lite'); ok(! defined NetAddr::IP::Lite->new("\1\1\1\1"), - "binary unrecognized by default..."); + "binary unrecognized by default ". ($x ? $x->addr :'')); # This mimicks the actual use with :aton NetAddr::IP::Lite::import(':aton'); - ok(defined NetAddr::IP::Lite->new("\1\1\1\1"), - "...but can be recognized"); + ok(defined ($x = NetAddr::IP::Lite->new("\1\1\1\1")), + "...but can be recognized ". $x->addr); - is(NetAddr::IP::Lite->new($_->[0])->aton, inet_aton($_->[1]), "->aton($_->[0])") + ok(!defined ($x = NetAddr::IP::Lite->new('bad rfc-952 characters')), + "bad rfc-952 characters ". ($x ? $x->addr :'')); + + is(NetAddr::IP::Lite->new($_->[0])->aton, l_inet_aton($_->[1]), "->aton($_->[0])") for @addr; - ok(defined NetAddr::IP::Lite->new(inet_aton($_->[1])), "->new aton($_->[1])") + ok(defined NetAddr::IP::Lite->new(l_inet_aton($_->[1])), "->new aton($_->[1])") for @addr; - is(NetAddr::IP::Lite->new(inet_aton($_->[1]))->addr, $_->[1], + is(NetAddr::IP::Lite->new(l_inet_aton($_->[1]))->addr, $_->[1], "->new aton($_->[1])") for @addr; }; diff --git a/Lite/t/v4-new_from_aton.t b/Lite/t/v4-new_from_aton.t index 39801b6..2a26c36 100644 --- a/Lite/t/v4-new_from_aton.t +++ b/Lite/t/v4-new_from_aton.t @@ -4,7 +4,7 @@ ); use NetAddr::IP::Lite; use Test::More; -use diagnostics; +#use diagnostics; plan tests => 12 + 3; diff --git a/META.yml b/META.yml index ae03dff..9d0f586 100644 --- a/META.yml +++ b/META.yml @@ -1,6 +1,6 @@ --- #YAML:1.0 name: NetAddr-IP -version: 4.013 +version: 4.014 abstract: Manages IPv4 and IPv6 addresses and subnets license: ~ author: