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