diff --git a/Changes b/Changes index 929ccae..bcd128f 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,13 @@ Revision history for Perl extension NetAddr::IP +4.029 Thu Jul 8 18:17:38 PDT 2010 + In NetAddr::IP::Lite, + added support for the sub "new" to resolve host6 names + if the OPTIONAL perl Socket6 module is available + + Thanks to "Mabe, Dusty" for spotting + this and suggesting a fix. + 4.028 Wed May 12 14:18:20 PDT 2010 In /Lite/Util/Util.xs v1.32, changed netswap() to postincrement diff --git a/IP.pm b/IP.pm index 9d459f1..c14df5f 100644 --- a/IP.pm +++ b/IP.pm @@ -4,7 +4,7 @@ use strict; #use diagnostics; -use NetAddr::IP::Lite 1.13 qw(Zero Zeros Ones V4mask V4net); +use NetAddr::IP::Lite 1.14 qw(Zero Zeros Ones V4mask V4net); use NetAddr::IP::Util 1.32 qw( sub128 inet_aton @@ -34,7 +34,7 @@ @ISA = qw(Exporter NetAddr::IP::Lite); -$VERSION = do { sprintf " %d.%03d", (q$Revision: 4.28 $ =~ /\d+/g) }; +$VERSION = do { sprintf " %d.%03d", (q$Revision: 4.29 $ =~ /\d+/g) }; =pod @@ -1405,116 +1405,7 @@ =over 4 -=item 4.00 - -Dependence on Math::BigInt in earlier version is removed in this release -4.00. NetAddr::IP now works with earlier versions of Perl. -The module was partitioned into three logical pieces as follows: - -Util.pm Math and logic operation on bit strings and number - that represent IP addresses and masks. Conversions - between various number formats. Implemented in - C_XS for speed and PURE PERL of transportability. - -Lite.pm Operations, simple conversions and comparisons of - IP addresses, notations and formats. - -IP.pm Complex operations and conversions of IP address - notation, nets, subnets, and ranges. - -The internal representation of addresses was changed to 128 bit binary -strings as returned by inet_pton (ipv6_aton in this module). Both -ipV4 and ipV6 notations can be freely mixed and matched. - -Additional methods added to force operations into ipV6 space even when -ipV4 notation is used. - -=item 4.05 - - NetAddr::IP :aton DEPRECATED ! - new method "new_from_aton" - -THE FOLLOWING CHANGES MAY BREAK SOME CODE ! - - Inherited methods from Lite.pm updated as follows: - - comparisons of the form <, >, <=, >= - - 10.0.0.0/24 {operator} 10.0.0.0/16 - - return now return the comparison of the cidr value - when the address portion is equal. - Thanks to Peter DeVries for spotting this bug. - - ... and leading us to discover that this next fix is required - - comparisons of the form <=>, cmp - now return the correct value 1, or -1 - when the address portion is equal and the CIDR value is not - i.e. where /16 is > /24, etc... - - This is the OPPOSITE of the previous return values for - comparison of the CIDR portion of the address object - -=item 4.08 - - added method ->new_from_aton to supplement broken - :aton functionality which is now DEPRECATED and - will eventually go away. - -=item 4.13 - - added 'no octal' method ->new_no - -=item 4.17 - - add support for PTHREADS in the event that perl is - built with . This must be invoked at build - time with the switch --with-threads - - WARNING: --with-threads is not tested in a threads - environment. Reports welcome and solicited. - - update _compV6 which runs faster and produces more - compact ipV6 addresses. - ....and - added minus (-) overloading to allow the subtraction - of two NetAddr::IP objects to get the difference between - the object->{addr}'s as a numeric value - - Thanks to Rob Riepel for - the _compV6 code and the inspiration for (-) overloading. - - Extended the capability of 'splitref' to allow splitting of - objects into multiple pieces with differing CIDR masks. - Returned object list can be split from bottom to top - or from top to bottom depending on which routine is called - - split, rsplit, splitref, rsplitref - - Thanks to kashmish for the idea on - improving functionality of 'split'. - -=item 4.018 - - removed --with-threads, PTHREADS support, and all - the mutex locking - unlocking - - updated Util.xs to be fully re-entrant and thus - fully thread safe. - -=item 4.020 - - Fixed core dump due to bug in perl 5.8.4 handling of - @_ in goto &sub operations. Unfortunately this version - of perl is standard on Solaris, 5.85 on RedHat and I'm - sure other distributions. -- all should be upgraded! - Similar behavior exists in perl versions 5.80 - 5.85 - See perl bug [ 23429]. - - Included missing code to parse BCD numbers as argument - to sub new(bcdnum). Thanks to Carlos Vicente cvicente@cpan.org - for reporting this bug. +See the Changes file =back diff --git a/Lite/Changes b/Lite/Changes index 766d28e..5598a48 100644 --- a/Lite/Changes +++ b/Lite/Changes @@ -1,5 +1,9 @@ Revision history for Perl extension NetAddr::IP::Lite +1.14 Thu Jul 8 18:17:38 PDT 2010 + added support for the sub "new" to resolve host6 names + if the OPTIONAL perl Socket6 module is available + 1.13 Tue Dec 9 16:00:35 PST 2008 added missing regexp to classify arguments as BCD numbers, apparently this has been missing from NetAddr::IP::Lite diff --git a/Lite/Lite.pm b/Lite/Lite.pm index 943d555..edcf483 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 *Zero); -$VERSION = do { my @r = (q$Revision: 1.13 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r }; +$VERSION = do { my @r = (q$Revision: 1.14 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r }; require Exporter; @@ -180,6 +180,48 @@ return $_v4net; } +# invoke replacement subroutine for Perl's "gethostbyname" +# if Socket6 is available. +# +# used only in 'sub _xnew' below +# +sub _end_gethostbyname { + my $tip = $_[0]; + return 0 unless $tip && $tip ne $_v4zero && $tip ne $_zero; + my $len = length($tip); + if ($len == 4) { + return ipv4to6($tip); + } + elsif ($len == 16) { + return $tip; + } + return 0; +} + +my $_gethostbyname; +unless (eval { require Socket6 }) { + $_gethostbyname = sub { + my $tip = gethostbyname($_[0]); + return &_end_gethostbyname($tip); + }; +} else { + require Socket; + my $_AF_INET6 = (defined eval { &Socket::AF_INET6 }) + ? \&Socket::AF_INET6 + : \&Socket6::AF_INET6; + $_AF_INET6 = $_AF_INET6->(); + + import Socket6 qw( gethostbyname2 ); + my $tip; + $_gethostbyname = sub { + unless ($tip = gethostbyname2($_[0],$_AF_INET6)) { + $tip = gethostbyname($_[0]); + } + return &_end_gethostbyname($tip); + }; +} + + ############################################# # These are the overload methods, placed here # for convenience. @@ -498,7 +540,9 @@ C<$addr> can be almost anything that can be resolved to an IP address in all the notations I have seen over time. It can optionally contain -the mask in CIDR notation. +the mask in CIDR notation. If the OPTIONAL perl module Socket6 is +available in the local library it will autoload and ipV6 host6 +names will be resolved as well as ipV4 hostnames. B notation is understood, with the limitation that the range specified by the prefix must match with a valid subnet. @@ -809,8 +853,10 @@ return undef if hasbits($ip & $tmp); last; } - elsif ($ip !~ /[^a-zA-Z0-9\.-]/ && ($tmp = gethostbyname($ip)) && $tmp ne $_v4zero && $tmp ne $_zero ) { - $ip = ipv4to6($tmp); + elsif ($ip !~ /[^a-zA-Z0-9\.-]/ && ($tmp = $_gethostbyname->($ip))) { + $ip = $tmp; +# elsif ($ip !~ /[^a-zA-Z0-9\.-]/ && ($tmp = gethostbyname($ip)) && $tmp ne $_v4zero && $tmp ne $_zero ) { +# $ip = ipv4to6($tmp); last; } elsif ($Accept_Binary_IP && ! $hasmask) { diff --git a/Lite/README b/Lite/README index cb348b4..5b42987 100644 --- a/Lite/README +++ b/Lite/README @@ -195,7 +195,9 @@ "$addr" can be almost anything that can be resolved to an IP address in all the notations I have seen over time. It can optionally - contain the mask in CIDR notation. + contain the mask in CIDR notation. If the OPTIONAL perl module + Socket6 is available in the local library it will autoload and ipV6 + host6 names will be resolved as well as ipV4 hostnames. prefix notation is understood, with the limitation that the range specified by the prefix must match with a valid subnet. diff --git a/META.yml b/META.yml index 126dabd..4c46f61 100644 --- a/META.yml +++ b/META.yml @@ -1,6 +1,6 @@ --- #YAML:1.0 name: NetAddr-IP -version: 4.028 +version: 4.029 abstract: Manages IPv4 and IPv6 addresses and subnets license: ~ author: