diff --git a/Changes b/Changes index ac47d81..8d425a3 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,18 @@ Revision history for Perl extension NetAddr::IP +4.057 Fri Nov 11 15:04:20 PST 2011 + Lite.pm v1.40 + add call to InetBase::fillIPv4 to all uses of gethostbyname + + break out the code in InetBase v0.05 that expands short IPv4 + addresses into dotquad format to account for broken BSD + implementations of inet_aton and gethostbyname that do + not recognize the short format. EXPORT this as sub 'fillIPv4' + + in Util.pm v1.45, add 'fillIPv4' to calls to gethostbyname to + work around broken inet_aton and gethostbyname implementations + in certain BSD implementations + 4.056 Wed Nov 2 19:15:31 PDT 2011 bump rev to incorporate improved inet_aton in InetBase v0.04 to overcome broken diff --git a/IP.pm b/IP.pm index da9f96b..b5a08d9 100644 --- a/IP.pm +++ b/IP.pm @@ -35,7 +35,7 @@ @ISA = qw(Exporter NetAddr::IP::Lite); -$VERSION = do { sprintf " %d.%03d", (q$Revision: 4.56 $ =~ /\d+/g) }; +$VERSION = do { sprintf " %d.%03d", (q$Revision: 4.57 $ =~ /\d+/g) }; =pod diff --git a/Lite/Changes b/Lite/Changes index ebef138..143e77e 100644 --- a/Lite/Changes +++ b/Lite/Changes @@ -1,9 +1,21 @@ Revision history for Perl extension NetAddr::IP::Lite +1.40 Fri Nov 11 13:20:32 PST 2011 + add call to InetBase::fillIPv4 to all uses of gethostbyname + + break out the code in InetBase v0.05 that expands short IPv4 + addresses into dotquad format to account for broken BSD + implementations of inet_aton and gethostbyname that do + not recognize the short format. EXPORT this as sub 'fillIPv4' + + in Util.pm v1.45, add 'fillIPv4' to calls to gethostbyname to + work around broken inet_aton and gethostbyname implementations + in certain BSD implementations + 1.39 Wed Nov 2 19:15:31 PDT 2011 bump rev to incorporate - improved inet_aton in InetBase v0.04 to overcome broken - gethostbyname found in NetBSD and OpenBSD + improved inet_aton in InetBase v0.04 to overcome broken + gethostbyname found in NetBSD and OpenBSD 1.38 Fri Oct 28 11:41:22 PDT 2011 patch for bug 71869, issues with Math::BigInt varients @@ -31,13 +43,13 @@ back to NetAddr::IP::Calc if Math::BigInt is not present. Thanks to Paul Howarth for spotting that bug. - remove reference to Config{osname} in InetBase.pm v0.03 + remove reference to Config{osname} in InetBase.pm v0.03 (Util 1.43) 1.33 Sat Oct 22 01:47:42 PDT 2011 In Lite/Util/lib/NetAddr/IP/Lite/Util/InetBase.pm v0.02 - Socket6 prior to version 0.23 does not have AF_INET6 in the - EXPORT_OK array, modify InetBase.pm v0.2 to work around this. + Socket6 prior to version 0.23 does not have AF_INET6 in the + EXPORT_OK array, modify InetBase.pm v0.2 to work around this. Add support for Math::BigInt objects @@ -47,32 +59,32 @@ missing. Thanks to Andrei Benea for spotting this. In Util v1.41 - add inet_pton, inet_ntop, AF_INET, AF_INET6 + add inet_pton, inet_ntop, AF_INET, AF_INET6 - modify inet_n2dx and inet_n2ad to - recognize the new 128 bit IPv4 format - ::FFFF:FFFF:0:0 + modify inet_n2dx and inet_n2ad to + recognize the new 128 bit IPv4 format + ::FFFF:FFFF:0:0 - replace isIPv4 with a pure perl version for portablity + replace isIPv4 with a pure perl version for portablity split the following into NetAddr::IP::InetBase v0.01 to provide better long term support for IPv6 - inet_aton - inet_ntoa - ipv6_aton - ipv6_n2x - ipv6_n2d - inet_any2n - inet_n2dx - inet_n2ad - inet_ntop - inet_pton - packzeros - isIPv4 - isNewIPv4 - isAnyIPv4 - AF_INET - AF_INET6 + inet_aton + inet_ntoa + ipv6_aton + ipv6_n2x + ipv6_n2d + inet_any2n + inet_n2dx + inet_n2ad + inet_ntop + inet_pton + packzeros + isIPv4 + isNewIPv4 + isAnyIPv4 + AF_INET + AF_INET6 1.31 Sat Oct 8 01:33:44 PDT 2011 remove debug print statement from Util.pm v1.40 diff --git a/Lite/Lite.pm b/Lite/Lite.pm index 37b179f..1c66072 100644 --- a/Lite/Lite.pm +++ b/Lite/Lite.pm @@ -13,6 +13,7 @@ inet_aton ipv6_aton ipv6_n2x + fillIPv4 ); use NetAddr::IP::Util qw( addconst @@ -31,7 +32,7 @@ use vars qw(@ISA @EXPORT_OK $VERSION $Accept_Binary_IP $Old_nth $AUTOLOAD *Zero); -$VERSION = do { my @r = (q$Revision: 1.39 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r }; +$VERSION = do { my @r = (q$Revision: 1.40 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r }; require Exporter; @@ -975,7 +976,7 @@ last; } # check for resolvable IPv4 hosts - elsif ($ip !~ /[^a-zA-Z0-9\.-]/ && ($tmp = gethostbyname($ip)) && $tmp ne $_v4zero && $tmp ne $_zero ) { + elsif ($ip !~ /[^a-zA-Z0-9\.-]/ && ($tmp = gethostbyname(fillIPv4($ip))) && $tmp ne $_v4zero && $tmp ne $_zero ) { $ip = ipv4to6($tmp); last; } diff --git a/Lite/Util/Changes b/Lite/Util/Changes index 79bd979..f3f2bff 100644 --- a/Lite/Util/Changes +++ b/Lite/Util/Changes @@ -1,3 +1,13 @@ +1.45 Fri Nov 11 13:20:32 PST 2011 + break out the code in InetBase v0.05 that expands short IPv4 + addresses into dotquad format to account for broken BSD + implementations of inet_aton and gethostbyname that do + not recognize the short format. EXPORT this as sub 'fillIPv4' + + in Util.pm, add 'fillIPv4' to calls to gethostbyname to + work around broken inet_aton and gethostbyname implementations + in certain BSD implementations + 1.44 Wed Nov 2 19:15:31 PDT 2011 improve inet_aton in InetBase v0.04 to overcome broken gethostbyname found in NetBSD and OpenBSD diff --git a/Lite/Util/Util.pm b/Lite/Util/Util.pm index 09d1c30..ee4ea5c 100644 --- a/Lite/Util/Util.pm +++ b/Lite/Util/Util.pm @@ -21,7 +21,7 @@ @ISA = qw(Exporter DynaLoader); -$VERSION = do { my @r = (q$Revision: 1.44 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r }; +$VERSION = do { my @r = (q$Revision: 1.45 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r }; @EXPORT_OK = qw( inet_aton @@ -146,7 +146,7 @@ # if Socket lib is broken in some way, check for overange values # #my $overange = yinet_aton('256.1') ? 1:0; -my $overange = gethostbyname('256.1') ? 1:0; +#my $overange = gethostbyname('256.1') ? 1:0; sub mode() { $Mode }; @@ -203,6 +203,9 @@ # invoke replacement subroutine for Perl's "gethostbyname" # if Socket6 is available. # +# NOTE: in certain BSD implementations, Perl's gethostbyname is broken +# we will use our own InetBase::inet_aton instead + sub _end_gethostbyname { # my ($name,$aliases,$addrtype,$length,@addrs) = @_; my @rv = @_; @@ -228,7 +231,8 @@ unless ( eval { require Socket6 }) { $mygethostbyname = sub { - my @tip = gethostbyname($_[0]); +# SEE NOTE above about broken BSD + my @tip = gethostbyname(NetAddr::IP::InetBase::fillIPv4($_[0])); return &_end_gethostbyname(@tip); }; } else { @@ -244,7 +248,8 @@ $mygethostbyname = sub { my @tip; unless ($_Sock6ok && (@tip = _ghbn2($_[0],NetAddr::IP::Util::AF_INET6())) && @tip > 1) { - @tip = gethostbyname($_[0]); +# SEE NOTE above about broken BSD + @tip = gethostbyname(NetAddr::IP::InetBase::fillIPv4($_[0])); } return &_end_gethostbyname(@tip); }; diff --git a/Lite/Util/lib/NetAddr/IP/InetBase.pm b/Lite/Util/lib/NetAddr/IP/InetBase.pm index e3b3647..3e4a1f2 100644 --- a/Lite/Util/lib/NetAddr/IP/InetBase.pm +++ b/Lite/Util/lib/NetAddr/IP/InetBase.pm @@ -11,7 +11,7 @@ @ISA = qw(Exporter); -$VERSION = do { my @r = (q$Revision: 0.04 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r }; +$VERSION = do { my @r = (q$Revision: 0.05 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r }; @EXPORT_OK = qw( inet_aton @@ -32,6 +32,7 @@ AF_INET AF_INET6 fake_AF_INET6 + fillIPv4 ); %EXPORT_TAGS = ( @@ -39,6 +40,7 @@ ipv4 => [qw( inet_aton inet_ntoa + fillIPv4 )], ipv6 => [qw( ipv6_aton @@ -162,7 +164,7 @@ # scalar gethostbyname($_[0]); #} -sub inet_aton { +sub fillIPv4 { my $host = $_[0]; return undef unless defined $host; if ($host =~ /^(\d+)(?:|\.(\d+)(?:|\.(\d+)(?:|\.(\d+))))$/) { @@ -172,30 +174,73 @@ $2 >= 0 && $2 < 256 && $3 >= 0 && $3 < 256 && $4 >= 0 && $4 < 256; - return pack('C4',$1,$2,$3,$4); + $host = $1.'.'.$2.'.'.$3.'.'.$4; +# return pack('C4',$1,$2,$3,$4); # $host = ($1 << 24) + ($2 << 16) + ($3 << 8) + $4; } elsif (defined $3) { return undef unless $1 >= 0 && $1 < 256 && $2 >= 0 && $2 < 256 && $3 >= 0 && $3 < 256; - return pack('C4',$1,$2,0,$3); + $host = $1.'.'.$2.'.0.'.$3 +# return pack('C4',$1,$2,0,$3); # $host = ($1 << 24) + ($2 << 16) + $3; } elsif (defined $2) { return undef unless $1 >= 0 && $1 < 256 && $2 >= 0 && $2 < 256; - return pack('C4',$1,0,0,$2); + $host = $1.'.0.0.'.$2; +# return pack('C4',$1,0,0,$2); # $host = ($1 << 24) + $2; } else { - return pack('C4',0,0,0,$1); + $host = '0.0.0.'.$1; +# return pack('C4',0,0,0,$1); # $host = $1; } # return pack('N',$host); } - scalar gethostbyname($host); + $host; } +sub inet_aton { + my $host = fillIPv4($_[0]); + return $host ? scalar gethostbyname($host) : undef; +} + +#sub inet_aton { +# my $host = $_[0]; +# return undef unless defined $host; +# if ($host =~ /^(\d+)(?:|\.(\d+)(?:|\.(\d+)(?:|\.(\d+))))$/) { +# if (defined $4) { +# return undef unless +# $1 >= 0 && $1 < 256 && +# $2 >= 0 && $2 < 256 && +# $3 >= 0 && $3 < 256 && +# $4 >= 0 && $4 < 256; +# return pack('C4',$1,$2,$3,$4); +## $host = ($1 << 24) + ($2 << 16) + ($3 << 8) + $4; +# } elsif (defined $3) { +# return undef unless +# $1 >= 0 && $1 < 256 && +# $2 >= 0 && $2 < 256 && +# $3 >= 0 && $3 < 256; +# return pack('C4',$1,$2,0,$3); +## $host = ($1 << 24) + ($2 << 16) + $3; +# } elsif (defined $2) { +# return undef unless +# $1 >= 0 && $1 < 256 && +# $2 >= 0 && $2 < 256; +# return pack('C4',$1,0,0,$2); +## $host = ($1 << 24) + $2; +# } else { +# return pack('C4',0,0,0,$1); +## $host = $1; +# } +## return pack('N',$host); +# } +# scalar gethostbyname($host); +#} + my $_zero = pack('L4',0,0,0,0); my $_ipv4mask = pack('L4',0xffffffff,0xffffffff,0xffffffff,0); @@ -651,6 +696,15 @@ This function return FALSE if AF_INET6 is provided by Socket or Socket6. Otherwise, it returns the best guess value based on name of the host operating system. +=item * $ip_filled = fillIPv4($shortIP); + +This function converts IPv4 addresses of the form 127.1 to the long form +127.0.0.1 + +If the function is passed an argument that does not match the form of an IP +address, the original argument is returned. i.e. pass it a hostname or a +short IP and it will return a hostname or a filled IP. + =back =head1 EXPORT_OK @@ -674,6 +728,7 @@ AF_INET AF_INET6 fake_AF_INET6 + fillIPv4 =head1 %EXPORT_TAGS diff --git a/META.yml b/META.yml index 04a9727..5624083 100644 --- a/META.yml +++ b/META.yml @@ -1,6 +1,6 @@ --- #YAML:1.0 name: NetAddr-IP -version: 4.056 +version: 4.057 abstract: Manages IPv4 and IPv6 addresses and subnets license: ~ author: