Hello community, here is the log from the commit of package perl-Net-IP for openSUSE:Factory checked in at 2013-06-13 18:18:33 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/perl-Net-IP (Old) and /work/SRC/openSUSE:Factory/.perl-Net-IP.new (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "perl-Net-IP" Changes: -------- --- /work/SRC/openSUSE:Factory/perl-Net-IP/perl-Net-IP.changes 2011-11-18 16:39:58.000000000 +0100 +++ /work/SRC/openSUSE:Factory/.perl-Net-IP.new/perl-Net-IP.changes 2013-06-13 18:18:34.000000000 +0200 @@ -1,0 +2,14 @@ +Sat Jun 8 07:11:10 UTC 2013 - [email protected] + +- updated to 1.26 + - 81138 ip types + - 80164 hexip does not change when ip changes (fix: hexformat needs to be cleared by set) + - 4898 double compression + - 73232 invalid ipv6 1:2:3:4:5:6:7 + - 73105 invalid ip 1:2 + - 73104 expand 1::2::3 + - 71042 ip_reverse 2001:4f8:3:36:0:0:0:235 + - 45165 ip_range_to_prefix updated documentation + - 32232 excepts 61-217-102-8.hinet-ip.hinet.net as range + +------------------------------------------------------------------- Old: ---- Net-IP-1.25.tar.gz New: ---- Net-IP-1.26.tar.gz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ perl-Net-IP.spec ++++++ --- /var/tmp/diff_new_pack.V3y2PB/_old 2013-06-13 18:18:35.000000000 +0200 +++ /var/tmp/diff_new_pack.V3y2PB/_new 2013-06-13 18:18:35.000000000 +0200 @@ -1,7 +1,7 @@ # # spec file for package perl-Net-IP # -# Copyright (c) 2011 SUSE LINUX Products GmbH, Nuernberg, Germany. +# Copyright (c) 2013 SUSE LINUX Products GmbH, Nuernberg, Germany. # # All modifications and additions to the file contributed by third parties # remain the property of their copyright owners, unless otherwise agreed @@ -15,21 +15,18 @@ # Please submit bugfixes or comments via http://bugs.opensuse.org/ # -# norootforbuild - Name: perl-Net-IP Url: http://cpan.org/modules/by-module/Net/ -License: Artistic-1.0 -Group: Development/Libraries/Perl Provides: perl_Net-IP Obsoletes: perl_Net-IP -AutoReqProv: on Summary: allow easy manipulation of IPv4 and IPv6 addresses -Version: 1.25 -Release: 61 +License: Artistic-1.0 +Group: Development/Libraries/Perl +Version: 1.26 +Release: 0 Source: Net-IP-%{version}.tar.gz -Patch: %{name}-%{version}-zero_address.diff +Patch: %{name}-1.25-zero_address.diff BuildRoot: %{_tmppath}/%{name}-%{version}-build %{perl_requires} BuildRequires: perl ++++++ Net-IP-1.25.tar.gz -> Net-IP-1.26.tar.gz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Net-IP-1.25/Changes new/Net-IP-1.26/Changes --- old/Net-IP-1.25/Changes 2006-05-24 18:34:39.000000000 +0200 +++ new/Net-IP-1.26/Changes 2012-11-28 16:20:32.000000000 +0100 @@ -1,5 +1,18 @@ Revision history for Perl extension Net::IP. +1.26 Wed Nov 28 12:00:00 2012 + - This version is authored by Ulrich Wisser + - 81138 ip types + - 80164 hexip does not change when ip changes (fix: hexformat needs to be cleared by set) + - 4898 double compression + - 73232 invalid ipv6 1:2:3:4:5:6:7 + - 73105 invalid ip 1:2 + - 73104 expand 1::2::3 + - 71042 ip_reverse 2001:4f8:3:36:0:0:0:235 + - 45165 ip_range_to_prefix updated documentation + - 32232 excepts 61-217-102-8.hinet-ip.hinet.net as range + + 1.25 Wed May 24 12:00:00 2006 - Math::BigInt is now mandatory - Several bugfixes done diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Net-IP-1.25/IP.pm new/Net-IP-1.26/IP.pm --- old/Net-IP-1.25/IP.pm 2006-05-22 18:46:40.000000000 +0200 +++ new/Net-IP-1.26/IP.pm 2012-11-28 16:23:38.000000000 +0100 @@ -47,7 +47,7 @@ %IPv4ranges %IPv6ranges $useBigInt $IP_NO_OVERLAP $IP_PARTIAL_OVERLAP $IP_A_IN_B_OVERLAP $IP_B_IN_A_OVERLAP $IP_IDENTICAL); -$VERSION = '1.25'; +$VERSION = '1.26'; require Exporter; @@ -73,49 +73,55 @@ # Definition of the Ranges for IPv4 IPs %IPv4ranges = ( - '00000000' => 'PRIVATE', # 0/8 - '00001010' => 'PRIVATE', # 10/8 - '01111111' => 'PRIVATE', # 127.0/8 - '101011000001' => 'PRIVATE', # 172.16/12 - '1100000010101000' => 'PRIVATE', # 192.168/16 - '1010100111111110' => 'RESERVED', # 169.254/16 - '110000000000000000000010' => 'RESERVED', # 192.0.2/24 - '1110' => 'RESERVED', # 224/4 - '11110' => 'RESERVED', # 240/5 - '11111' => 'RESERVED', # 248/5 + '00000000' => 'PRIVATE', # 0/8 + '00001010' => 'PRIVATE', # 10/8 + '0110010001' => 'SHARED', # 100.64/10 + '01111111' => 'LOOPBACK', # 127.0/8 + '1010100111111110' => 'LINK-LOCAL', # 169.254/16 + '101011000001' => 'PRIVATE', # 172.16/12 + '110000000000000000000000' => 'RESERVED', # 192.0.0/24 + '110000000000000000000010' => 'TEST-NET', # 192.0.2/24 + '110000000101100001100011' => '6TO4-RELAY', # 192.88.99.0/24 + '1100000010101000' => 'PRIVATE', # 192.168/16 + '110001100001001' => 'RESERVED', # 198.18/15 + '110001100011001101100100' => 'TEST-NET', # 198.51.100/24 + '110010110000000001110001' => 'TEST-NET', # 203.0.113/24 + '1110' => 'MULTICAST', # 224/4 + '1111' => 'RESERVED', # 240/4 + '11111111111111111111111111111111' => 'BROADCAST', # 255.255.255.255/32 ); # Definition of the Ranges for Ipv6 IPs %IPv6ranges = ( - '00000000' => 'RESERVED', # ::/8 - '00000001' => 'RESERVED', # 0100::/8 - '0000001' => 'RESERVED', # 0200::/7 - '000001' => 'RESERVED', # 0400::/6 - '00001' => 'RESERVED', # 0800::/5 - '0001' => 'RESERVED', # 1000::/4 - '001' => 'GLOBAL-UNICAST', # 2000::/3 - '010' => 'RESERVED', # 4000::/3 - '011' => 'RESERVED', # 6000::/3 - '100' => 'RESERVED', # 8000::/3 - '101' => 'RESERVED', # A000::/3 - '110' => 'RESERVED', # C000::/3 - '1110' => 'RESERVED', # E000::/4 - '11110' => 'RESERVED', # F000::/5 - '111110' => 'RESERVED', # F800::/6 - '1111101' => 'RESERVED', # FA00::/7 - '1111110' => 'UNIQUE-LOCAL-UNICAST', # FC00::/7 - '111111100' => 'RESERVED', # FE00::/9 - '1111111010' => 'LINK-LOCAL-UNICAST', # FE80::/10 - '1111111011' => 'RESERVED', # FEC0::/10 - '11111111' => 'MULTICAST', # FF00::/8 - '00100000000000010000110110111000' => 'RESERVED', # 2001:DB8::/32 - - '0' x 96 => 'IPV4COMP', # ::/96 - ('0' x 80) . ('1' x 16) => 'IPV4MAP', # ::FFFF:0:0/96 - - '0' x 128 => 'UNSPECIFIED', # ::/128 - ('0' x 127) . '1' => 'LOOPBACK' # ::1/128 - + '00000000' => 'RESERVED', # ::/8 + ('0' x 128) => 'UNSPECIFIED', # ::/128 + ('0' x 127) . '1' => 'LOOPBACK', # ::1/128 + ('0' x 80) . ('1' x 16) => 'IPV4MAP', # ::FFFF:0:0/96 + '00000001' => 'RESERVED', # 0100::/8 + '0000000100000000' . ('0' x 48) => 'DISCARD', # 0100::/64 + '0000001' => 'RESERVED', # 0200::/7 + '000001' => 'RESERVED', # 0400::/6 + '00001' => 'RESERVED', # 0800::/5 + '0001' => 'RESERVED', # 1000::/4 + '001' => 'GLOBAL-UNICAST', # 2000::/3 + '0010000000000001' . ('0' x 16) => 'TEREDO', # 2001::/32 + '00100000000000010000000000000010' . ('0' x 16) => 'BMWG', # 2001:0002::/48 + '00100000000000010000110110111000' => 'DOCUMENTATION', # 2001:DB8::/32 + '0010000000000001000000000001' => 'ORCHID', # 2001:10::/28 + '0010000000000010' => '6TO4', # 2002::/16 + '010' => 'RESERVED', # 4000::/3 + '011' => 'RESERVED', # 6000::/3 + '100' => 'RESERVED', # 8000::/3 + '101' => 'RESERVED', # A000::/3 + '110' => 'RESERVED', # C000::/3 + '1110' => 'RESERVED', # E000::/4 + '11110' => 'RESERVED', # F000::/5 + '111110' => 'RESERVED', # F800::/6 + '1111110' => 'UNIQUE-LOCAL-UNICAST', # FC00::/7 + '111111100' => 'RESERVED', # FE00::/9 + '1111111010' => 'LINK-LOCAL-UNICAST', # FE80::/10 + '1111111011' => 'RESERVED', # FEC0::/10 + '11111111' => 'MULTICAST', # FF00::/8 ); # Overlap constants @@ -211,7 +217,7 @@ # We need to reset everything for ( qw(ipversion errno prefixlen binmask reverse_ip last_ip iptype - binip error ip intformat mask last_bin last_int prefix is_prefix) + binip error ip intformat hexformat mask last_bin last_int prefix is_prefix) ) { delete($self->{$_}); @@ -1024,7 +1030,7 @@ # Count octets my $n = ($ip =~ tr/:/:/); - return (0) unless ($n > 0 and $n < 8); + return 0 unless ($n > 0 and $n < 8); # $k is a counter my $k; @@ -1039,8 +1045,9 @@ next if (/^[a-f\d]{1,4}$/i); # Last octet - is it IPv4 ? - if ($k == $n + 1) { - next if (ip_is_ipv4($_)); + if ( ($k == $n + 1) && ip_is_ipv4($_) ) { + $n++; # ipv4 is two octets + next; } $ERROR = "Invalid IP address $ip"; @@ -1063,12 +1070,20 @@ } # Does the IP address have more than one '::' pattern ? - if ($ip =~ s/:(?=:)//g > 1) { + if ($ip =~ s/:(?=:)/:/g > 1) { $ERROR = "Invalid address $ip (More than one :: pattern)"; $ERRNO = 111; return 0; } + # number of octets + if ($n != 7 && $ip !~ /::/) { + $ERROR = "Invalid number of octets $ip"; + $ERRNO = 112; + return 0; + } + + # valid IPv6 address return 1; } @@ -1090,9 +1105,24 @@ if ($ip_version == 4) { my @quads = split /\./, $ip; + # check number of quads + if (scalar(@quads) > 4) { + $ERROR = "Not a valid IPv address $ip"; + $ERRNO = 102; + return; + } my @clean_quads = (0, 0, 0, 0); foreach my $q (reverse @quads) { + + #check quad data + if ($q !~ m/^\d{1,3}$/) { + $ERROR = "Not a valid IPv4 address $ip"; + $ERRNO = 102; + return; + } + + # build clean ipv4 unshift(@clean_quads, $q + 1 - 1); } @@ -1100,7 +1130,12 @@ } # Keep track of :: - $ip =~ s/::/:!:/; + my $num_of_double_colon = ($ip =~ s/::/:!:/g); + if ($num_of_double_colon > 1) { + $ERROR = "Too many :: in ip"; + $ERRNO = 102; + return; + } # IP as an array my @ip = split /:/, $ip; @@ -1118,10 +1153,7 @@ # Convert into hex # Keep the last two octets - $ip[$_] = - substr( - ip_bintoip(ip_iptobin(ip_expand_address($ip[$_], 4), 4), 6), - -9); + $ip[$_] = substr( ip_bintoip( ip_iptobin( ip_expand_address($ip[$_], 4), 4), 6), -9); # Has an error occured here ? return unless (defined($ip[$_])); @@ -1506,6 +1538,9 @@ # Just return if IP is IPv4 return ($ip) if ($ip_version == 4); + # already compressed addresses must be expanded first + $ip = ip_expand_address( $ip, $ip_version); + # Remove leading 0s: 0034 -> 34; 0000 -> 0 $ip =~ s/ (^|:) # Find beginning or ':' -> $1 @@ -1695,21 +1730,60 @@ sub ip_iptype { my ($ip, $ip_version) = @_; - # Find IP version + # handle known ip versions + return ip_iptypev4($ip) if $ip_version == 4; + return ip_iptypev6($ip) if $ip_version == 6; - if ($ip_version == 4) { - foreach (sort { length($b) <=> length($a) } keys %IPv4ranges) { - return ($IPv4ranges{$_}) if ($ip =~ m/^$_/); - } + # unsupported ip version + $ERROR = "IP version $ip not supported"; + $ERRNO = 180; + return; +} - # IP is public - return 'PUBLIC'; +#------------------------------------------------------------------------------ +# Subroutine ip_iptypev4 +# Purpose : Return the type of an IP (Public, Private, Reserved) +# Params : IP to test, IP version +# Returns : type or undef (invalid) +sub ip_iptypev4 { + my ($ip) = @_; + + # check ip + if ($ip !~ m/^[01]{1,32}$/) { + $ERROR = "$ip is not a binary IPv4 address $ip"; + $ERRNO = 180; + return; } + + # see if IP is listed + foreach (sort { length($b) <=> length($a) } keys %IPv4ranges) { + return ($IPv4ranges{$_}) if ($ip =~ m/^$_/); + } + + # not listed means IP is public + return 'PUBLIC'; +} + +#------------------------------------------------------------------------------ +# Subroutine ip_iptypev6 +# Purpose : Return the type of an IP (Public, Private, Reserved) +# Params : IP to test, IP version +# Returns : type or undef (invalid) +sub ip_iptypev6 { + my ($ip) = @_; + # check ip + if ($ip !~ m/^[01]{1,128}$/) { + $ERROR = "$ip is not a binary IPv6 address"; + $ERRNO = 180; + return; + } + foreach (sort { length($b) <=> length($a) } keys %IPv6ranges) { return ($IPv6ranges{$_}) if ($ip =~ m/^$_/); } + # How did we get here? All IPv6 addresses should match $ERROR = "Cannot determine type for $ip"; $ERRNO = 180; return; @@ -1780,7 +1854,7 @@ return join '.', @reverse_quads, 'in-addr', 'arpa.'; } elsif ($ip_version == 6) { - my @rev_groups = reverse split /:/, $ip; + my @rev_groups = reverse split /:/, ip_expand_address($ip, 6); my @result; foreach (@rev_groups) { @@ -1930,7 +2004,7 @@ 1; __END__ - +=encoding utf8 =head1 NAME Net::IP - Perl extension for manipulating IPv4/IPv6 addresses @@ -2110,7 +2184,7 @@ =head2 iptype Return the IP Type - this describes the type of an IP (Public, Private, -Reserved, etc.) +Reserved, etc.) See procedural interface ip_iptype for more details. C<print ($ip-E<gt>iptype());> @@ -2380,7 +2454,7 @@ Return all prefixes between two IPs. - Params : First IP, Last IP, IP version + Params : First IP (binary format), Last IP (binary format), IP version Returns : List of Prefixes or undef (problem) The prefixes returned have the form q.q.q.q/nn. @@ -2450,12 +2524,92 @@ C<$prefix = ip_aggregate ($bip1,$eip1,$bip2,$eip2) || die ...> +=head2 ip_iptypev4 + +Return the type of an IPv4 address. + + Params: binary IP + Returns: type as of the following table or undef (invalid ip) + +See RFC 5735 and RFC 6598 + +S<Address Block Present Use Reference> +S<-------------------------------------------------------------------> +S<0.0.0.0/8 "This" Network RFC 1122 PRIVATE> +S<10.0.0.0/8 Private-Use Networks RFC 1918 PRIVATE> +S<100.64.0.0/10 CGN Shared Address Space RFC 6598 SHARED> +S<127.0.0.0/8 Loopback RFC 1122 LOOPBACK> +S<169.254.0.0/16 Link Local RFC 3927 LINK-LOCAL> +S<172.16.0.0/12 Private-Use Networks RFC 1918 PRIVATE> +S<192.0.0.0/24 IETF Protocol Assignments RFC 5736 RESERVED> +S<192.0.2.0/24 TEST-NET-1 RFC 5737 TEST-NET> +S<192.88.99.0/24 6to4 Relay Anycast RFC 3068 6TO4-RELAY> +S<192.168.0.0/16 Private-Use Networks RFC 1918 PRIVATE> +S<198.18.0.0/15 Network Interconnect> +S< Device Benchmark Testing RFC 2544 RESERVED> +S<198.51.100.0/24 TEST-NET-2 RFC 5737 TEST-NET> +S<203.0.113.0/24 TEST-NET-3 RFC 5737 TEST-NET> +S<224.0.0.0/4 Multicast RFC 3171 MULTICAST> +S<240.0.0.0/4 Reserved for Future Use RFC 1112 RESERVED> +S<255.255.255.255/32 Limited Broadcast RFC 919 BROADCAST> +S< RFC 922> + +=head2 ip_iptypev6 + +Return the type of an IPv6 address. + + Params: binary ip + Returns: type as of the following table or undef (invalid) + +See L<IANA Internet Protocol Version 6 Address Space|http://www.iana.org/assignments/ipv6-address-space/ipv6-address-space.txt> and L<IANA IPv6 Special Purpose Address Registry|http://www.iana.org/assignments/iana-ipv6-special-registry/iana-ipv6-special-registry.txt> + + +S<Prefix Allocation Reference> +S<-------------------------------------------------------------> +S<0000::/8 Reserved by IETF [RFC4291] RESERVED> +S<0100::/8 Reserved by IETF [RFC4291] RESERVED> +S<0200::/7 Reserved by IETF [RFC4048] RESERVED> +S<0400::/6 Reserved by IETF [RFC4291] RESERVED> +S<0800::/5 Reserved by IETF [RFC4291] RESERVED> +S<1000::/4 Reserved by IETF [RFC4291] RESERVED> +S<2000::/3 Global Unicast [RFC4291] GLOBAL-UNICAST> +S<4000::/3 Reserved by IETF [RFC4291] RESERVED> +S<6000::/3 Reserved by IETF [RFC4291] RESERVED> +S<8000::/3 Reserved by IETF [RFC4291] RESERVED> +S<A000::/3 Reserved by IETF [RFC4291] RESERVED> +S<C000::/3 Reserved by IETF [RFC4291] RESERVED> +S<E000::/4 Reserved by IETF [RFC4291] RESERVED> +S<F000::/5 Reserved by IETF [RFC4291] RESERVED> +S<F800::/6 Reserved by IETF [RFC4291] RESERVED> +S<FC00::/7 Unique Local Unicast [RFC4193] UNIQUE-LOCAL-UNICAST> +S<FE00::/9 Reserved by IETF [RFC4291] RESERVED> +S<FE80::/10 Link Local Unicast [RFC4291] LINK-LOCAL-UNICAST> +S<FEC0::/10 Reserved by IETF [RFC3879] RESERVED> +S<FF00::/8 Multicast [RFC4291] MULTICAST> + + +S<Prefix Assignment Reference> +S<---------------------------------------------------------------------> +S<::1/128 Loopback Address [RFC4291] UNSPECIFIED> +S<::/128 Unspecified Address [RFC4291] LOOPBACK> +S<::FFFF:0:0/96 IPv4-mapped Address [RFC4291] IPV4MAP> +S<0100::/64 Discard-Only Prefix [RFC6666] DISCARD> +S<2001:0000::/32 TEREDO [RFC4380] TEREDO> +S<2001:0002::/48 BMWG [RFC5180] BMWG> +S<2001:db8::/32 Documentation Prefix [RFC3849] DOCUMENTATION> +S<2001:10::/28 ORCHID [RFC4843] ORCHID> +S<2002::/16 6to4 [RFC3056] 6TO4> +S<FC00::/7 Unique-Local [RFC4193] UNIQUE-LOCAL-UNICAST> +S<FE80::/10 Linked-Scoped Unicast [RFC4291] LINK-LOCAL-UNICAST> +S<FF00::/8 Multicast [RFC4291] MULTICAST> + + =head2 ip_iptype Return the type of an IP (Public, Private, Reserved) - Params : IP to test, IP version - Returns : type or undef (invalid) + Params : Binary IP to test, IP version (defaults to 6) + Returns : type (see ip_iptypev4 and ip_iptypev6 for details) or undef (invalid) C<$type = ip_iptype ($ip);> diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Net-IP-1.25/META.yml new/Net-IP-1.26/META.yml --- old/Net-IP-1.25/META.yml 2006-05-24 18:35:08.000000000 +0200 +++ new/Net-IP-1.26/META.yml 2012-11-28 16:33:03.000000000 +0100 @@ -1,10 +1,21 @@ -# http://module-build.sourceforge.net/META-spec.html -#XXXXXXX This is a prototype!!! It will change in the future!!! XXXXX# -name: Net-IP -version: 1.25 -version_from: IP.pm -installdirs: site -requires: - -distribution_type: module -generated_by: ExtUtils::MakeMaker version 6.30 +--- #YAML:1.0 +name: Net-IP +version: 1.26 +abstract: Perl extension for manipulating IPv4/IPv6 addresses +author: + - Manuel Valente <[email protected]> +license: unknown +distribution_type: module +configure_requires: + ExtUtils::MakeMaker: 0 +build_requires: + ExtUtils::MakeMaker: 0 +requires: {} +no_index: + directory: + - t + - inc +generated_by: ExtUtils::MakeMaker version 6.57_05 +meta-spec: + url: http://module-build.sourceforge.net/META-spec-v1.4.html + version: 1.4 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Net-IP-1.25/README new/Net-IP-1.26/README --- old/Net-IP-1.25/README 2005-10-18 11:59:25.000000000 +0200 +++ new/Net-IP-1.26/README 2012-11-28 16:18:43.000000000 +0100 @@ -17,8 +17,7 @@ All bug reports and suggestions for improvemenets should be sent to Manuel Valente <[email protected]>. -All files contained in this installation are Copyright (c) 1999-2000 -RIPE-NCC unless otherwise specified. All rights reserved. +Many thanks to Ulrich Wisser for the version 1.26. This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Net-IP-1.25/t/ipv4.t new/Net-IP-1.26/t/ipv4.t --- old/Net-IP-1.25/t/ipv4.t 2006-04-26 10:35:42.000000000 +0200 +++ new/Net-IP-1.26/t/ipv4.t 2012-11-28 15:51:38.000000000 +0100 @@ -12,10 +12,11 @@ }; }; -my $numtests = 26; +my $numtests = 8031; # Create checker: my $T = typical ExtUtils::TBone; +#my $T = new ExUtils::TBone "log.txt"; $numtests++ if $math_bigint; @@ -77,6 +78,189 @@ $ip->set('192.168.0.3/32'); $T->ok_eqnum ($ip->size,1,$ip->error()); +# test if hexip changes when ip is set (bug 80164 RT) +$ip = new Net::IP('195.114.80/24',4); +$hex1 = $ip->hexip; +$ip->set('192.168.0.3/32'); +$hex2 = $ip->hexip; +$T->ok($hex1 ne $hex2, "Hex IP should not match (hexip1:$hex1 hexip2:$hex2"); + +# regression test bug 32232 RT +$ip->set('61-217-102-8.hinet-ip.hinet.net'); +$T->ok_eq ($ip->error(),'Not a valid IPv4 address 217-102-8.hinet-ip.hinet.net',$ip->error()); +$T->ok_eqnum ($ip->errno(),102,$ip->error()); + + +#------------------------------------------------------------------------------ +# test for network types + +sub rbin { return int(2*rand); } +sub ip2bin { return unpack('B32', pack('C4C4C4C4', split(/\./, shift))); } +sub bin2ip { return join('.', unpack('C4C4C4C4', pack('B32', shift))); } +sub v4_first { + my $network = shift; + while (length $network < 32) { + $network .= '0'; + } + return bin2ip($network); +} +sub v4_last { + my $network = shift; + while (length $network < 32) { + $network .= '1'; + } + return bin2ip($network); +} +sub v4_rand { + my $network = shift; + while (length $network < 32) { + $network .= rbin(); + } + return bin2ip($network); +} +sub v4_okeq { + my $ip = Net::IP->new(shift); + $T->msg('IPv4: '.$ip->print ); + $T->ok_eq ($ip->iptype(), shift, $ip->error()); + return; +} +sub v4_nettest { + my $ip = shift; + my $prefix = shift; + my $iptype = shift; + my $numoftests = shift; + my $network = substr( ip2bin($ip), 0, $prefix); + + die "ERROR! At least 3 tests must be run." if $numoftests < 3; + + v4_okeq( v4_first( $network ), $iptype ); + v4_okeq( v4_last( $network ), $iptype ); + $numoftests -= 2; + + while ($numoftests--) { + v4_okeq( v4_rand( $network ), $iptype ); + } + + # done + return; +} + + +# Address Block Present Use Reference +# ------------------------------------------------------------------ +# 0.0.0.0/8 "This" Network RFC 1122, Section 3.2.1.3 PRIVATE +# 10.0.0.0/8 Private-Use Networks RFC 1918 PRIVATE +# 100.64.0.0/10 CGN Shared Address Space RFC 6598 SHARED +# 127.0.0.0/8 Loopback RFC 1122, Section 3.2.1.3 LOOPBACK +# 169.254.0.0/16 Link Local RFC 3927 LINK-LOCAL +# 172.16.0.0/12 Private-Use Networks RFC 1918 PRIVATE +# 192.0.0.0/24 IETF Protocol Assignments RFC 5736 RESERVED +# 192.0.2.0/24 TEST-NET-1 RFC 5737 TEST-NET +# 192.88.99.0/24 6to4 Relay Anycast RFC 3068 6TO4-RELAY +# 192.168.0.0/16 Private-Use Networks RFC 1918 PRIVATE +# 198.18.0.0/15 Network Interconnect +# Device Benchmark Testing RFC 2544 RESERVED +# 198.51.100.0/24 TEST-NET-2 RFC 5737 TEST-NET +# 203.0.113.0/24 TEST-NET-3 RFC 5737 TEST-NET +# 224.0.0.0/4 Multicast RFC 3171 MULTICAST +# 240.0.0.0/4 Reserved for Future Use RFC 1112, Section 4 RESERVED +# 255.255.255.255/32 Limited Broadcast RFC 919, Section 7 BROADCAST +# RFC 922, Section 7 + + +v4_nettest( '0.0.0.0', 8, 'PRIVATE', 100); # 1 +v4_nettest( '10.0.0.0', 8, 'PRIVATE', 100); # 2 +v4_nettest( '100.64.0.0', 10, 'SHARED', 100); # 3 +v4_nettest( '127.0.0.0', 8, 'LOOPBACK', 100); # 4 +v4_nettest( '169.254.0.0', 16, 'LINK-LOCAL', 100); # 5 +v4_nettest( '172.16.0.0', 12, 'PRIVATE', 100); # 6 +v4_nettest( '192.0.0.0', 24, 'RESERVED', 100); # 7 +v4_nettest( '192.0.2.0', 24, 'TEST-NET', 100); # 8 +v4_nettest( '192.88.99.0', 24, '6TO4-RELAY', 100); # 9 +v4_nettest( '192.168.0.0', 16, 'PRIVATE', 100); # 10 +v4_nettest( '198.18.0.0', 15, 'RESERVED', 100); # 11 +v4_nettest( '198.51.100.0', 24, 'TEST-NET', 100); # 12 +v4_nettest( '203.0.113.0', 24, 'TEST-NET', 100); # 13 +v4_nettest( '224.0.0.0', 4, 'MULTICAST', 100); # 14 +# the 240/4 net can not be tested directly because the last ip in the block 255.255.255.255/32 has another type +v4_nettest( '240.0.0.0', 5, 'RESERVED', 100); # 15 +v4_nettest( '248.0.0.0', 6, 'RESERVED', 100); # 16 +v4_nettest( '252.0.0.0', 7, 'RESERVED', 100); # 17 +v4_nettest( '254.0.0.0', 8, 'RESERVED', 100); # 18 +v4_nettest( '255.0.0.0', 9, 'RESERVED', 100); # 19 +v4_nettest( '255.128.0.0', 10, 'RESERVED', 100); # 20 +v4_nettest( '255.192.0.0', 11, 'RESERVED', 100); # 21 +v4_nettest( '255.224.0.0', 12, 'RESERVED', 100); # 22 +v4_nettest( '255.240.0.0', 13, 'RESERVED', 100); # 23 +v4_nettest( '255.248.0.0', 14, 'RESERVED', 100); # 24 +v4_nettest( '255.252.0.0', 15, 'RESERVED', 100); # 25 +v4_nettest( '255.254.0.0', 16, 'RESERVED', 100); # 26 +v4_nettest( '255.255.0.0', 17, 'RESERVED', 100); # 27 +v4_nettest( '255.255.128.0', 18, 'RESERVED', 100); # 28 +v4_nettest( '255.255.192.0', 19, 'RESERVED', 100); # 29 +v4_nettest( '255.255.224.0', 20, 'RESERVED', 100); # 30 +v4_nettest( '255.255.240.0', 21, 'RESERVED', 100); # 31 +v4_nettest( '255.255.248.0', 22, 'RESERVED', 100); # 32 +v4_nettest( '255.255.252.0', 23, 'RESERVED', 100); # 33 +v4_nettest( '255.255.254.0', 24, 'RESERVED', 100); # 34 +v4_nettest( '255.255.255.0', 25, 'RESERVED', 100); # 35 +v4_nettest( '255.255.255.128', 26, 'RESERVED', 100); # 36 +v4_nettest( '255.255.255.192', 27, 'RESERVED', 100); # 37 +v4_nettest( '255.255.255.224', 28, 'RESERVED', 100); # 38 +v4_nettest( '255.255.255.240', 29, 'RESERVED', 100); # 39 +v4_nettest( '255.255.255.248', 30, 'RESERVED', 100); # 40 +v4_nettest( '255.255.255.252', 31, 'RESERVED', 100); # 41 +v4_okeq( '255.255.255.254', 'RESERVED'); +v4_okeq( '255.255.255.255', 'BROADCAST'); + +# check boundary networks to be public +v4_nettest( '1.0.0.0', 8, 'PUBLIC', 100); # 42 +v4_nettest( '8.0.0.0', 8, 'PUBLIC', 100); # 43 +v4_nettest( '9.0.0.0', 8, 'PUBLIC', 100); # 44 +v4_nettest( '11.0.0.0', 8, 'PUBLIC', 100); # 45 +v4_nettest( '100.63.0.0', 10, 'PUBLIC', 100); # 46 +v4_nettest( '100.128.0.0', 10, 'PUBLIC', 100); # 47 +v4_nettest( '100.192.0.0', 10, 'PUBLIC', 100); # 48 +v4_nettest( '126.0.0.0', 8, 'PUBLIC', 100); # 49 +v4_nettest( '128.0.0.0', 8, 'PUBLIC', 100); # 50 +v4_nettest( '169.253.0.0', 16, 'PUBLIC', 100); # 51 +v4_nettest( '169.255.0.0', 16, 'PUBLIC', 100); # 52 +v4_nettest( '172.15.0.0', 12, 'PUBLIC', 100); # 53 +v4_nettest( '172.32.0.0', 12, 'PUBLIC', 100); # 54 +v4_nettest( '172.48.0.0', 12, 'PUBLIC', 100); # 55 + +v4_nettest( '191.255.255.0',24, 'PUBLIC', 100); # 56 +v4_nettest( '192.0.1.0', 24, 'PUBLIC', 100); # 57 + +v4_nettest( '192.0.1.0', 24, 'PUBLIC', 100); # 58 +v4_nettest( '192.0.3.0', 24, 'PUBLIC', 100); # 59 + +v4_nettest( '192.88.96.0', 24, 'PUBLIC', 100); # 60 +v4_nettest( '192.88.97.0', 24, 'PUBLIC', 100); # 61 +v4_nettest( '192.88.98.0', 24, 'PUBLIC', 100); # 62 +v4_nettest( '192.88.100.0', 24, 'PUBLIC', 100); # 63 +v4_nettest( '192.88.103.0', 24, 'PUBLIC', 100); # 64 + +v4_nettest( '192.160.0.0', 16, 'PUBLIC', 100); # 65 +v4_nettest( '192.187.0.0', 16, 'PUBLIC', 100); # 66 +v4_nettest( '192.175.0.0', 16, 'PUBLIC', 100); # 67 +v4_nettest( '192.176.0.0', 16, 'PUBLIC', 100); # 68 + +v4_nettest( '198.16.0.0', 15, 'PUBLIC', 100); # 69 +v4_nettest( '198.17.0.0', 15, 'PUBLIC', 100); # 70 +v4_nettest( '198.20.0.0', 15, 'PUBLIC', 100); # 71 +v4_nettest( '198.22.0.0', 15, 'PUBLIC', 100); # 72 + +v4_nettest( '198.48.100.0', 24, 'PUBLIC', 100); # 73 +v4_nettest( '198.49.100.0', 24, 'PUBLIC', 100); # 74 +v4_nettest( '198.50.100.0', 24, 'PUBLIC', 100); # 75 +v4_nettest( '198.52.100.0', 24, 'PUBLIC', 100); # 76 +v4_nettest( '198.55.100.0', 24, 'PUBLIC', 100); # 77 + +v4_nettest( '203.0.112.0', 24, 'PUBLIC', 100); # 78 +v4_nettest( '203.0.114.0', 24, 'PUBLIC', 100); # 79 +v4_nettest( '203.0.115.0', 24, 'PUBLIC', 100); # 80 + #------------------------------------------------------------------------------ $T->end; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Net-IP-1.25/t/ipv6.t new/Net-IP-1.26/t/ipv6.t --- old/Net-IP-1.25/t/ipv6.t 2006-04-21 15:23:27.000000000 +0200 +++ new/Net-IP-1.26/t/ipv6.t 2012-11-28 16:32:22.000000000 +0100 @@ -8,13 +8,15 @@ $math_bigint = 1; }; }; -my $numtests = 20; +my $numtests = 28; # Create checker: my $T = typical ExtUtils::TBone; $numtests++ if $math_bigint; +$numtests += 28 * 1000 + 8; # IPv6 network type tests + $T->begin($numtests); #------------------------------------------------------------------------------ @@ -69,6 +71,149 @@ $T->ok_eqnum ($ip->overlaps($ip2),$IP_NO_OVERLAP,$ip->error()); +# regression test bug 74898 RT +$T->ok_eq( ip_compress_address ("2221:0:0:f800::1", 6), '2221:0:0:f800::1'); + +# regression test bug 73232 RT +$T->ok( !ip_is_ipv6('1:2:3:4:5:6:7'), 'Invalid IPv6 1:2:3:4:5:6:7'); +$T->ok( ip_is_ipv6('::1'), 'Valid ip ::1'); +$T->ok( ip_is_ipv6('2001::'), 'Valid ip 2001::'); +$T->ok( !ip_is_ipv6("1:2") , 'Invalid ip 1:2'); # bug 73105 RT + +# regression test bug 73104 RT +$T->ok( !defined ip_expand_address("1::2::3",6), 'Expand invalid 1::2::3'); +$T->ok_eq(Error(), 'Too many :: in ip'); +$T->ok_eqnum(Errno(), 102); + +# regression test bug 71042 RT +$T->ok_eq( ip_reverse("2001:4f8:3:36:0:0:0:235", 128, 6), '5.3.2.0.0.0.0.0.0.0.0.0.0.0.0.0.6.3.0.0.3.0.0.0.8.f.4.0.1.0.0.2.ip6.arpa.'); +$T->ok_eq( ip_reverse("2001:4f8:3:36::235", 128, 6), '5.3.2.0.0.0.0.0.0.0.0.0.0.0.0.0.6.3.0.0.3.0.0.0.8.f.4.0.1.0.0.2.ip6.arpa.'); + +#------------------------------------------------------------------------------ +# test for network types +sub v6_expand { + my ($ip) = @_; + + # Keep track of :: + $ip =~ s/::/:!:/; + + # IP as an array + my @ip = split /:/, $ip; + + + # prepare result string + $ip = ''; + + # go through all octets + foreach (@ip) { + + # insert octet divider + $ip .= ':' if length($ip); + + # replace ! with 0 octets + if ($_ eq '!') { + my $num_of_zero_octets = 9 - scalar(@ip); + $ip .= ('0000:' x ($num_of_zero_octets - 1)) . '0000'; + next; + } + + # Add missing trailing 0s + $ip .= ('0' x (4 - length($_))) . $_; + } + + return lc($ip); +} +sub rbin { return int(2*rand); } +sub ip2bin { my $ip = v6_expand(shift); $ip =~ s/://g; return unpack('B128', pack('H32', $ip)); } +sub bin2ip { return join(':', unpack('H4H4H4H4H4H4H4H4', pack('B128', shift))); } +sub v6_first { + my $network = shift; + while (length $network < 128) { + $network .= '0'; + } + return bin2ip($network); +} +sub v6_last { + my $network = shift; + while (length $network < 128) { + $network .= '1'; + } + return bin2ip($network); +} +sub v6_rand { + my $network = shift; + while (length $network < 128) { + $network .= rbin(); + } + return bin2ip($network); +} +sub v6_okeq { + my $ip = Net::IP->new(shift); + $T->msg('IPv6: '.$ip->print ); + $T->ok_eq ($ip->iptype(), shift, $ip->error()); + return; +} +sub v6_nettest { + my $ip = shift; + my $prefix = shift; + my $iptype = shift; + my $numoftests = shift; + my $network = substr( ip2bin($ip), 0, $prefix); + + die "ERROR! At least 3 tests must be run." if $numoftests < 3; + + v6_okeq( v6_first( $network ), $iptype ); + v6_okeq( v6_last( $network ), $iptype ); + $numoftests -= 2; + + while ($numoftests--) { + v6_okeq( v6_rand( $network ), $iptype ); + } + + # done + return; +} + +# this net is not complete of type RESERVED, test only parts +#v6_nettest('::', 8, 'RESERVED', 1000); +v6_nettest('::', 128, 'UNSPECIFIED', 3); +v6_nettest('::1', 128, 'LOOPBACK', 3); +v6_nettest('::FFFF:0:0', 96, 'IPV4MAP', 1000); +v6_nettest('80::', 9, 'RESERVED', 1000); + +# this net is not complete of type RESERVED, test oly parts +#v6_nettest('0100::', 8, 'RESERVED', 1000); +v6_nettest('0100::', 64, 'DISCARD', 1000); +v6_nettest('0180::', 9, 'RESERVED', 1000); + +v6_nettest('0200::', 7, 'RESERVED', 1000); +v6_nettest('0400::', 6, 'RESERVED', 1000); +v6_nettest('0800::', 5, 'RESERVED', 1000); +v6_nettest('1000::', 4, 'RESERVED', 1000); + +# this net is not complete of type GLOBAL-UNICAST, test only parts +#v6_nettest('2000::', 3, 'GLOBAL-UNICAST', 1000); +v6_nettest('2001::', 32, 'TEREDO', 1000); +v6_nettest('2001:2::', 48, 'BMWG', 1000); +v6_nettest('2001:DB8::', 32, 'DOCUMENTATION', 1000); +v6_nettest('2001:10::', 28, 'ORCHID', 1000); +v6_nettest('2002::', 16, '6TO4', 1000); +v6_nettest('3000::', 4, 'GLOBAL-UNICAST', 1000); + +v6_nettest('4000::', 3, 'RESERVED', 1000); +v6_nettest('6000::', 3, 'RESERVED', 1000); +v6_nettest('8000::', 3, 'RESERVED', 1000); +v6_nettest('A000::', 3, 'RESERVED', 1000); +v6_nettest('C000::', 3, 'RESERVED', 1000); +v6_nettest('E000::', 4, 'RESERVED', 1000); +v6_nettest('F000::', 5, 'RESERVED', 1000); +v6_nettest('F800::', 6, 'RESERVED', 1000); +v6_nettest('FA00::', 7, 'RESERVED', 1000); +v6_nettest('FC00::', 8, 'UNIQUE-LOCAL-UNICAST', 1000); +v6_nettest('FE00::', 9, 'RESERVED', 1000); +v6_nettest('FE80::', 10, 'LINK-LOCAL-UNICAST', 1000); +v6_nettest('FEC0::', 10, 'RESERVED', 1000); +v6_nettest('FF00::', 8, 'MULTICAST', 1000); + $T->end; 1; - -- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
