From f27d76fa9d78e2779d7f4178709bc5a2ea12408e Mon Sep 17 00:00:00 2001 From: "Eric A. Miller" Date: Wed, 9 May 2018 22:44:24 -0400 Subject: [PATCH] Use munge_mac() to unpack MACs --- lib/SNMP/Info/LLDP.pm | 5 ++--- xt/lib/Test/SNMP/Info/LLDP.pm | 8 ++++---- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/lib/SNMP/Info/LLDP.pm b/lib/SNMP/Info/LLDP.pm index 7c6faa8f..183c6725 100644 --- a/lib/SNMP/Info/LLDP.pm +++ b/lib/SNMP/Info/LLDP.pm @@ -255,8 +255,7 @@ sub lldp_port { # May need to format other types in the future, i.e. Network address if ( $type =~ /mac/ ) { - $port = join( ':', - map { sprintf "%02x", $_ } unpack( 'C*', $port ) ); + $port = SNMP::Info::munge_mac($port) } } @@ -291,7 +290,7 @@ sub lldp_id { # May need to format other types in the future if ( $type =~ /mac/ ) { - $id = join( ':', map { sprintf "%02x", $_ } unpack( 'C*', $id ) ); + $id = SNMP::Info::munge_mac($id) } elsif ( $type eq 'networkAddress' ) { if ( length( unpack( 'H*', $id ) ) == 10 ) { diff --git a/xt/lib/Test/SNMP/Info/LLDP.pm b/xt/lib/Test/SNMP/Info/LLDP.pm index 5e5709c8..36000f95 100644 --- a/xt/lib/Test/SNMP/Info/LLDP.pm +++ b/xt/lib/Test/SNMP/Info/LLDP.pm @@ -64,7 +64,7 @@ sub setup : Tests(setup) { {'0.6.1' => 'C2960 Software (C2960-LANBASEK9-M), Version 12.2(37)SE'}, 'lldp_rem_sysname' => {'0.6.1' => 'My C2960'}, 'lldp_rem_id_type' => {'0.6.1' => 'macAddress'}, - 'lldp_rem_id' => {'0.6.1' => pack("H*", 'ABCD123456')}, + 'lldp_rem_id' => {'0.6.1' => pack("H*", 'ABCD12345678')}, 'lldp_rem_cap_spt' => {'0.6.1' => pack("H*", '2800')}, 'lldp_rem_media_cap_spt' => {'0.6.1' => pack("H*", '4C')}, } @@ -286,10 +286,10 @@ sub lldp_port : Tests(10) { $test->{info}{store} = { lldp_rem_pid_type => {'0.16.1' => 'macAddress'}, lldp_rem_desc => {'0.16.1' => ''}, - lldp_rem_pid => {'0.16.1' => pack("H*", '2345678ABC')}, + lldp_rem_pid => {'0.16.1' => pack("H*", '2345678ABCDE')}, }; - $expected = {'0.16.1' => '23:45:67:8a:bc'}; + $expected = {'0.16.1' => '23:45:67:8a:bc:de'}; cmp_deeply($test->{info}->lldp_port(), $expected, q(Remote port type 'macAddress' no 'lldpRemPortDesc' uses 'lldpRemPortId')); @@ -330,7 +330,7 @@ sub lldp_id : Tests(4) { can_ok($test->{info}, 'lldp_id'); - my $expected = {'0.6.1' => 'ab:cd:12:34:56'}; + my $expected = {'0.6.1' => 'ab:cd:12:34:56:78'}; cmp_deeply($test->{info}->lldp_id(), $expected, q(Remote LLDP ID type 'macAddress' has expected value));