Skip Menu |

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

Report information
The Basics
Id: 76297
Status: resolved
Worked: 3 hours (180 min)
Priority: 0/
Queue: NetAddr-IP

People
Owner: Nobody in particular
Requestors: fh [...] open.ch
Cc:
AdminCc:

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



Subject: IPv6 Address Creation Broken for Low Address Values
Date: Wed, 04 Apr 2012 08:33:29 +0200
To: bug-NetAddr-IP [...] rt.cpan.org
From: Fabian Hugelshofer <fh [...] open.ch>
When creating IPv6 addresses with new6() and an integer as address value, the address is not created as expected: $ perl -e 'use NetAddr::IP::Lite; my $addr = NetAddr::IP::Lite->new6(0, 0); print $addr."\n";' 0:0:0:0:0:0:0:0/96 => Expected would be ::/0 $ perl -e 'use NetAddr::IP::Lite; my $addr = NetAddr::IP::Lite->new6(1 ,0); print $addr."\n";' 0:0:0:0:0:0:100:0/96 => Expected would be ::1/0 $ perl -e 'use NetAddr::IP::Lite; my $addr = NetAddr::IP::Lite->new6(1 ,1); print $addr."\n";' 0:0:0:0:0:0:100:0/97 => Expected would be ::1/1 It looks like integers 0-255 are interpreted as the highest byte of an IPv4 address which is then represented as an IPv4-compatible IPv6 addresses. This has been tested with NetAddr-IP-0.059 and Perl v5.14.0. Kind regards, Fabian
After staring at this and digging through the code for a couple of hours it occurred to me that the response you are seeing is correct. 0/0 or new(0,0) is 0.0.0.0/0.0.0.0 translated to ipV6 using new6 0:0:0:0:0:0:0:0/FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:0:0 which is 0:0:0:0:0:0:0:0/96 new6 converts the values it sees as ipV4 to their ipV6 counterparts if you say new('::'/0) you get 0:0:0:0:0:0:0:0/0:0:0:0:0:0:0:0 or 0:0:0:0:0:0:0:0/0 On Wed Apr 04 02:33:39 2012, fh@open.ch wrote: Show quoted text
> When creating IPv6 addresses with new6() and an integer as address > value, the address is not created as expected: > > $ perl -e 'use NetAddr::IP::Lite; my $addr = NetAddr::IP::Lite->new6(0, > 0); print $addr."\n";' > 0:0:0:0:0:0:0:0/96 > > => Expected would be ::/0 > > $ perl -e 'use NetAddr::IP::Lite; my $addr = NetAddr::IP::Lite->new6(1 > ,0); print $addr."\n";' > 0:0:0:0:0:0:100:0/96 > > => Expected would be ::1/0 > > $ perl -e 'use NetAddr::IP::Lite; my $addr = NetAddr::IP::Lite->new6(1 > ,1); print $addr."\n";' > 0:0:0:0:0:0:100:0/97 > > => Expected would be ::1/1 > > It looks like integers 0-255 are interpreted as the highest byte of an > IPv4 address which is then represented as an IPv4-compatible IPv6
addresses. Show quoted text
> > This has been tested with NetAddr-IP-0.059 and Perl v5.14.0. > > Kind regards, > > Fabian
Subject: Re: [rt.cpan.org #76297] IPv6 Address Creation Broken for Low Address Values
Date: Tue, 10 Apr 2012 10:13:18 +0200
To: bug-NetAddr-IP [...] rt.cpan.org
From: Fabian Hugelshofer <fh [...] open.ch>
Thank you for looking into this. This kind of does make sense, but it means that one has to be very careful when using integers or Math::BigInt as address values: 0 is IPv4 0.0.0.0 255 is IPv4 255.0.0.0 (0:0:0:0:0:0:ff00:0 converted to IPv6) 256 is IPv6 0:0:0:0:0:0:0:100
On Tue Apr 10 04:13:31 2012, fh@open.ch wrote: Show quoted text
> Thank you for looking into this. This kind of does make sense, but it > means that one has to be very careful when using integers or > Math::BigInt as address values: > > 0 is IPv4 0.0.0.0 > 255 is IPv4 255.0.0.0 (0:0:0:0:0:0:ff00:0 converted to IPv6) > 256 is IPv6 0:0:0:0:0:0:0:100
I agree, IPv4 and IPv6 notation are easily confused when it comes to the CIDR component. Probably not a good idea to mix them. We've given it our best shot in NetAddr::IP, and hope the community can work with it. We are always open to improvements and frequently make additions submitted by users. Best regards, Michael