Subject: | Incorrect Range Expansion of Abbreviated CIDRs |
LACNIC uses an unusual abbreviated CIDR notation. Net::CIDR doesn't consider this notation valid, but still tries to expand it into a range. The range it comes up with is busted.
Here's a script and output showing the problem and one (hackish) way of rewriting the screwy CIDRs into the normal format:
------------------------------------------------
Script:
use Net::CIDR;
use Net::Whois::IANA;
my $iana = Net::Whois::IANA->new;
$iana->whois_query(-ip => '191.96.58.222');
print "CIDR: ", $iana->cidr->[0], "\n";
print "Range: ", $iana->inetnum, "\n";
print "Net::CIDR considers invalid\n" unless Net::CIDR::cidrvalidate($iana->cidr);
my $cidr = $iana->cidr()->[0];
my $num_dots = $cidr =~ tr/\.//;
$cidr =~ s/(?:\d+\.)*\d+/$& . '.0' x (3 - $num_dots)/e;
print "Fixed CIDR: $cidr\n";
print "Fixed Range: ", Net::CIDR::cidr2range($cidr), "\n";
print "Net::CIDR considers valid\n" if Net::CIDR::cidrvalidate($cidr);
-------------------------------------------------
Output:
CIDR: 191.96/16
Range: 191.96-191.96
Net::CIDR considers invalid
Fixed CIDR: 191.96.0.0/16
Fixed Range: 191.96.0.0-191.96.255.255
Net::CIDR considers valid