Skip Menu |
 

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

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

People
Owner: cpan [...] bat.ru
Requestors: andreas.papst [...] univie.ac.at
Cc:
AdminCc:

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



Subject: reverse_ip Bug
Date: Mon, 26 Jan 2009 10:26:06 +0100
To: bug-Net-IP [...] rt.cpan.org
From: Andreas Papst <andreas.papst [...] univie.ac.at>
Download (untitled) / with headers
text/plain 288b
Hi, Net::IP has a function reverse_ip that should return the reverse IP in in-addr.arpa notation. In case of 1.2.3.0 it does not and returns 3.2.1.in-addr.arpa instead of 0.3.2.1.in-addr.arpa. If you edit ip_reverse to not omit leading 0s, other functions fail. Kind Regards Andreas
RT-Send-CC: manuel.valente [...] gmail.com
Download (untitled) / with headers
text/plain 101b
I've just discovered the same problem. Please find my suggestion for a patch attached. Regards, fany
diff -ur Net-IP-1.25/IP.pm Net-IP-1.26/IP.pm --- Net-IP-1.25/IP.pm 2006-05-22 18:46:40.000000000 +0200 +++ Net-IP-1.26/IP.pm 2009-09-03 18:59:52.994133875 +0200 @@ -40,6 +40,7 @@ package Net::IP; use strict; +use Carp qw(croak); use Math::BigInt; # Global Variables definition @@ -47,7 +48,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; @@ -1770,12 +1771,12 @@ if ($ip_version == 4) { my @quads = split /\./, $ip; my $no_quads = ($len / 8); + croak("A /$len object does not have a defined reverse name") + if $no_quads != int $no_quads; my @reverse_quads = reverse @quads; - while (@reverse_quads and $reverse_quads[0] == 0) { - shift(@reverse_quads); - } + splice @reverse_quads, 0, 4 - $no_quads; return join '.', @reverse_quads, 'in-addr', 'arpa.'; } diff -ur Net-IP-1.25/t/ipv4.t Net-IP-1.26/t/ipv4.t --- Net-IP-1.25/t/ipv4.t 2006-04-26 10:35:42.000000000 +0200 +++ Net-IP-1.26/t/ipv4.t 2009-09-03 18:55:30.410538089 +0200 @@ -12,7 +12,7 @@ }; }; -my $numtests = 26; +my $numtests = 27; # Create checker: my $T = typical ExtUtils::TBone; @@ -43,6 +43,11 @@ $T->ok_eq ($ip->last_bin(),'11000011011100100101000011111111',$ip->error()); $T->ok_eq ($ip->last_ip(),'195.114.80.255',$ip->error()); +{ # for #42793: reverse_ip Bug + my $ip = Net::IP->new('195.114.80.0'); + $T->ok_eq( $ip->reverse_ip, '0.80.114.195.in-addr.arpa.', $ip->error ); +} + $ip->set('202.31.4/24'); $T->ok_eq ($ip->ip(),'202.31.4.0',$ip->error()); Only in Net-IP-1.26: testout
Also see bug #25169 (and maybe merge them, if the system lets you.)
Download (untitled) / with headers
text/plain 226b
On Fri Sep 04 04:21:52 2009, FANY wrote: Show quoted text
> Also see bug #25169 (and maybe merge them, if the system lets you.)
This bug is being fixed in Debian using the following patch. So now whoever owns this module can take their pick.
Subject: ip_reverse.patch
Download ip_reverse.patch
text/x-diff 1.6k
Author: Nicholas Bamber <nicholas@periapt.co.uk> Bug: http://rt.cpan.org/Public/Bug/Display.html?d=42793 Bug-Debian: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=623681 Subject: ip_reverse() for IPv4 ignores prefixlen parameter The problem particularly occurs where there are a lot of zeros in the less significant quads. You can use a /number to force retention of those quads in the reversed address but the code was ignoring that instruction. There is some ambiguity over what should happen when the number of bits specified does not fall on a boundary. I have tested with Net::IP::XS and tried to follow what they do. Last-Update: 2011-05-11 --- /dev/null +++ b/t/reverse_ip.t @@ -0,0 +1,13 @@ +use Test::More tests=>4; +use Net::IP; + +my $obj = Net::IP->new('10.10.0.0/31'); +is($obj->reverse_ip, '0.10.10.in-addr.arpa.', 'reverse_ip'); +$obj->set('192.168.0.0/24'); +is($obj->reverse_ip, '0.168.192.in-addr.arpa.', 'reverse_ip'); +$obj->set('192.0.0.0/24'); +is($obj->reverse_ip, '0.0.192.in-addr.arpa.', 'reverse_ip'); +$obj->set('192.0.0.0/32'); +is($obj->reverse_ip, '0.0.0.192.in-addr.arpa.', 'reverse_ip'); + + --- a/IP.pm +++ b/IP.pm @@ -1769,12 +1769,13 @@ if ($ip_version == 4) { my @quads = split /\./, $ip; - my $no_quads = ($len / 8); + my $no_quads = 4 - int($len / 8); my @reverse_quads = reverse @quads; - while (@reverse_quads and $reverse_quads[0] == 0) { + while (@reverse_quads and $reverse_quads[0] == 0 and $no_quads > 0) { shift(@reverse_quads); + --$no_quads; } return join '.', @reverse_quads, 'in-addr', 'arpa.';
Fix committed into 1.27 release. Thanks for the patch and report!


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.