Skip Menu |

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

Report information
The Basics
Id: 36344
Status: resolved
Worked: 2 hours (120 min)
Priority: 0/
Queue: NetAddr-IP

People
Owner: Nobody in particular
Requestors: peter [...] devries.tv
Cc:
AdminCc:

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



Subject: Comparisons Don't take CIDR Notations into account
Date: Sun, 1 Jun 2008 23:22:20 -0400
To: bug-NetAddr-IP [...] rt.cpan.org
From: "Peter DeVries" <peter [...] devries.tv>
When doing comparisons on two networks the CIDR notation is not taken into consideration as documented: "Internally, all network objects are represented in 128 bit format. The numeric representation of the network is compared through the corresponding operation. Comparisons are tried first on the address portion of the object and if that is equal then the cidr portion of the masks are compared.' For example 10.10.10.0/24 and 10.10.10.0/16 are considered equal. Using < > also fail to work. Here is the small test I've written. ##### Code ####### #!/usr/bin/perl use NetAddr::IP; $IP1 = '10.10.10.0'; # Can also be defined in CIDR notation - 10.10.10.0/24 $IP2 = '10.10.10.0'; $NETADDRIP1 = new NetAddr::IP "$IP1", '255.255.255.0'; $NETADDRIP2 = new NetAddr::IP "$IP2", '255.255.0.0'; if ($NETADDRIP1 = $NETADDRIP2) { print "equal\n";}; if ($NETADDRIP1 < $NETADDRIP2) { print "Less Than\n";}; if ($NETADDRIP1 > $NETADDRIP2) { print "Greater Than\n";}; ################# I would expect the answer to be "Less Than" but it is in fact "equal" (BTW I've tested with the variables defined as CIDR notation as well ie. $IP1 = ' 10.10.10.0/24';) NetAddr::IP version is 4.007 Perl Version 5.8.4 OS - Solaris 10 Thanks for any help, Peter
Subject: Re: [rt.cpan.org #36344] AutoReply: Comparisons Don't take CIDR Notations into account
Date: Mon, 2 Jun 2008 00:04:25 -0400
To: bug-NetAddr-IP [...] rt.cpan.org
From: "Peter DeVries" <peter [...] devries.tv>
Quick Followup. it looks like the documentation on: http://search.cpan.org/~luismunoz/NetAddr-IP-4.007/IP.pm
Subject: Re: [rt.cpan.org #36344] AutoReply: Comparisons Don't take CIDR Notations into account
Date: Mon, 2 Jun 2008 00:09:17 -0400
To: bug-NetAddr-IP [...] rt.cpan.org
From: "Peter DeVries" <peter [...] devries.tv>
Sorry for the multiple messages. I fat fingered the last one. My first issue of > < not working seems to be a documentation issue. On this page: http://search.cpan.org/~luismunoz/NetAddr-IP-4.007/IP.pm it says: "Comparison via >, <, >=, <=, <=> and cmp Internally, all network objects are represented in 128 bit format. The numeric representation of the network is compared through the corresponding operation. Comparisons are tried first on the address portion of the object and if that is equal then the cidr portion of the masks are compared." However in the module it says: "Comparison via E<gt>, E<lt>, E<gt>=, E<lt>=, E<lt>=E<gt> and C<cmp>> Internally, all network objects are represented in 128 bit format. The numeric representation of the network is compared through the corresponding operation. Comparisons are tried first on the address portion of the object and if that is equal then the cidr portion of the masks are compared." The documentation in the module is correct. However that is only half the issue. When comparing 10.10.0.0/16 to 10.10.0.0/24, 10.10.0.0/24 is considered the greater value. The logic in the module should change to account for the fact that the smaller the CIDR notation the larger the network. Thanks again. Peter
On Sun Jun 01 23:22:44 2008, peter@devries.tv wrote: Show quoted text
> When doing comparisons on two networks the CIDR notation is not taken into > consideration as documented: > > "Internally, all network objects are represented in 128 bit format. The > numeric representation of the network is compared through the
corresponding Show quoted text
> operation. Comparisons are tried first on the address portion of the
object Show quoted text
> and if that is equal then the cidr portion of the masks are compared.' > > For example 10.10.10.0/24 and 10.10.10.0/16 are considered equal.
Using < > Show quoted text
> also fail to work. > > Here is the small test I've written. > > ##### Code ####### > #!/usr/bin/perl > > use NetAddr::IP; > > $IP1 = '10.10.10.0'; # Can also be defined in CIDR notation - > 10.10.10.0/24 > $IP2 = '10.10.10.0'; > > $NETADDRIP1 = new NetAddr::IP "$IP1", '255.255.255.0'; > $NETADDRIP2 = new NetAddr::IP "$IP2", '255.255.0.0'; > > if ($NETADDRIP1 = $NETADDRIP2) { print "equal\n";}; > if ($NETADDRIP1 < $NETADDRIP2) { print "Less Than\n";}; > if ($NETADDRIP1 > $NETADDRIP2) { print "Greater Than\n";}; > ################# > > I would expect the answer to be "Less Than" but it is in fact "equal" (BTW > I've tested with the variables defined as CIDR notation as well ie.
$IP1 = ' Show quoted text
> 10.10.10.0/24';) > > NetAddr::IP version is 4.007 > Perl Version 5.8.4 > OS - Solaris 10 > > Thanks for any help, > Peter
Version 4.008 now takes CIDR comparisons into account. The result is probably not what you expect. i.e. CIDR /24 > /16 This may seem counterintuitive, however it is consistent with the intent of sorting network ranges from less specific to more specific. It is also necessary for the proper operation of Coalesce and Compact. In general, network comparisons should be done using 'masklen' since the comparison of netaddr objects with differing CIDR's will result in inconsistent results dependent on the IP portion of the object. Those results are not logical in any sense of the word when IP's of differing (with some 'equal') are compared as a group in a 'sort'; The NetAddr documentation has been updated to clarify both of these points.