Use NetAddr::IP::Lite to determine if EIGRP peer is a valid IP

This commit is contained in:
Eric A. Miller
2018-05-09 22:42:59 -04:00
parent f531c9d9a7
commit 4f8534169a
2 changed files with 6 additions and 6 deletions

View File

@@ -160,10 +160,10 @@ sub eigrp_peers {
my $peer = $peers->{$idx};
next unless $peer;
if ( ( $type eq 'ipv4' or $type eq 'ipv6' )
and $peer =~ /^(?:\w|\.|\:)+$/x )
{
$eigrp_peers{$idx} = $peer;
my $ip = NetAddr::IP::Lite->new($peer);
if ($ip) {
$eigrp_peers{$idx} = $ip->addr;
}
elsif ( $type eq 'ipv4' ) {
$eigrp_peers{$idx} = SNMP::Info::munge_ip($peer);

View File

@@ -122,8 +122,8 @@ sub eigrp_peers : Tests(3) {
my $expected = {
'0.5.0' => '1.2.3.4',
'0.5.1' => '10.20.30.40',
'65536.10.2' => '::1.2.3.4',
'65536.10.3' => 'fe80::2d0:b7ff:fe21:c6c0'
'65536.10.2' => '0:0:0:0:0:0:102:304',
'65536.10.3' => 'fe80:0:0:0:2d0:b7ff:fe21:c6c0'
};
cmp_deeply($test->{info}->eigrp_peers(),