Subject: | sub ip_bintoint returns undef instead of 0 for low IP addr on default routes |
Date: | Thu, 22 Oct 2015 12:11:28 -0500 |
To: | bug-net-ip [...] rt.cpan.org |
From: | Elle Plato <techgrrl [...] gmail.com> |
Greetings, we call ip_bintoint to get the low address of a range, and
pass it to sort. When we call it with the default route, or 0::0/2
etc, we get undef. It looks like $dec on default, $_ is never true,
so $dec += $n is never called, so $dec is undef. It seems like we
should do something along the lines of if (defined($dec) {return $dec}
else {return 0}
sub ip_bintoint {
my $binip = shift;
# $n is the increment, $dec is the returned value
my ($n, $dec) = (Math::BigInt->new(1), Math::BigInt->new(0));
# Reverse the bit string
foreach (reverse(split '', $binip)) {
# If the nth bit is 1, add 2**n to $dec
$_ and $dec += $n;
$n *= 2;
}
# Strip leading + sign
$dec =~ s/^\+//;
return $dec;
}