Skip Menu |

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

Report information
The Basics
Id: 129964
Status: open
Priority: 0/
Queue: Net-IP

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

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



Subject: Incorrect calculation of reverse string
Date: Tue, 2 Jul 2019 17:33:52 -0400
To: bug-Net-IP [...] rt.cpan.org
From: Matt Richard <gmattrichard [...] gmail.com>
Hello, We appear to be incorrectly calculating the reverse (PTR-style) string for an IP address when the IP address ends in a zero. Consider: use Net::IP; my $addr1 = '10.100.128.114'; my $addr2 = '10.100.128.0'; my $ip1 = new Net::IP ($addr1 . "/32"); my $ip2 = new Net::IP ($addr2 . "/32"); printf "IP1 = %s / object = %s / reverse = %s\n", $addr1, $ip1->print(), $ip1->reverse_ip(); printf "IP2 = %s / object = %s / reverse = %s\n", $addr2, $ip2->print(), $ip2->reverse_ip(); the output is: IP1 = 10.100.128.114 / object = 10.100.128.114/32 / reverse = 114.128.100.10.in-addr.arpa. IP2 = 10.100.128.0 / object = 10.100.128.0/32 / reverse = 128.100.10.in-addr.arpa. The reverese for $addr2 should be *0.**128.100.10.in-addr.arpa.* Can you please confim? Best, Matt
I also have seen this issue and agree it is a bug. It doesn't just affect the last octet either, it'll trim any leading 0's. #!/usr/bin/perl use strict; use warnings; use Net::IP; my @ips = ("10.1.1.0","10.1.0.0","10.0.0.0"); foreach my $ip (@ips) { my $obj = new Net::IP($ip) or die ("module error - ".Net::IP::Error()); my $rev = $obj->reverse_ip(); print "IP addr ".$ip." reverse address is $rev\n"; } Results are: IP addr 10.1.1.0 reverse address is 1.1.10.in-addr.arpa. IP addr 10.1.0.0 reverse address is 1.10.in-addr.arpa. IP addr 10.0.0.0 reverse address is 10.in-addr.arpa.
Updating line 1850, in sub ip_reverse from: while (@reverse_quads and $reverse_quads[0] == 0) { to while (@reverse_quads and $reverse_quads[0] == 0 and scalar(@reverse_quads) > $no_quads) { Seems to resolve this issue. My testing of IPv6 seems to not show this issue so that should be the only adjustment required.