Skip Menu |
 

This queue is for tickets about the Net-IP CPAN distribution.

Report information
The Basics
Id: 71042
Status: resolved
Priority: 0/
Queue: Net-IP

People
Owner: Nobody in particular
Requestors: dmitry.kurochkin [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: 1.26



Subject: ip_reverse incorrect result for many IPv6 addresses
Date: Sun, 18 Sep 2011 04:14:06 +0400
To: bug-Net-IP [...] rt.cpan.org
From: Dmitry Kurochkin <dmitry.kurochkin [...] gmail.com>
Download (untitled) / with headers
text/plain 459b
Hello. Net::IP::ip_reverse() produces incorrect results for many IPv6 addresses, e.g. ip_reverse("2001:4f8:3:36:0:0:0:235", 128, 6) returns: 5.3.2.0.0.0.6.3.3.8.f.4.1.0.0.2.ip6.arpa. While expected result is: 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. Attached patch for Net::IP v1.25 fixes the problem. Note: I am not very good at Perl so there may be a more elegant/efficient way to fix this. Regards, Dmitry
Download ipv6-reverse.patch
text/x-diff 1.4k
--- a/IP.pm 2006-05-24 22:35:23.000000000 +0400 +++ b/IP.pm 2011-09-18 04:09:19.338849625 +0400 @@ -1766,42 +1766,43 @@ $ERRNO = 101; return; } if ($ip_version == 4) { my @quads = split /\./, $ip; my $no_quads = ($len / 8); my @reverse_quads = reverse @quads; while (@reverse_quads and $reverse_quads[0] == 0) { shift(@reverse_quads); } return join '.', @reverse_quads, 'in-addr', 'arpa.'; } elsif ($ip_version == 6) { my @rev_groups = reverse split /:/, $ip; my @result; - foreach (@rev_groups) { - my @revhex = reverse split //; + foreach my $a (@rev_groups) { + $a = sprintf "%04s", $a; + my @revhex = reverse split //, $a; push @result, @revhex; } # This takes the zone above if it's not exactly on a nibble my $first_nibble_index = $len ? 32 - (int($len / 4)) : 0; return join '.', @result[ $first_nibble_index .. $#result ], 'ip6', 'arpa.'; } } #------------------------------------------------------------------------------ # Subroutine ip_normalize # Purpose : Normalize data to a range of IP addresses # Params : IP or prefix or range # Returns : ip1, ip2 (if range) or undef (error) sub ip_normalize { my ($data) = shift; my $ipversion;


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.