From 690bc6bfa0ab02a0bbb55709c908edb04e5b827d Mon Sep 17 00:00:00 2001 From: Carlos Vicente <> Date: Tue, 10 Mar 2009 16:57:37 +0000 Subject: [PATCH] Add support for other CDP/LLDP binary formatted values (ID 1909147) --- Info/LLDP.pm | 8 +++++++- Info/Layer2/HP.pm | 30 +++++++++++++++++++++--------- 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/Info/LLDP.pm b/Info/LLDP.pm index e907e22e..41bbe5f4 100644 --- a/Info/LLDP.pm +++ b/Info/LLDP.pm @@ -191,7 +191,13 @@ sub lldp_id { # May need to format other types in the future if ( $type =~ /mac/ ) { $id = join( ':', map { sprintf "%02x", $_ } unpack( 'C*', $id ) ); - } + }elsif ($type eq 'networkAddress'){ + if ( length(unpack('H*', $id)) == 10 ){ + # IP address (first octet is sign, I guess) + my @octets = (map { sprintf "%02x",$_ } unpack('C*', $id))[1..4]; + $id = join '.', map { hex($_) } @octets; + } + } $lldp_id{$key} = $id; } return \%lldp_id; diff --git a/Info/Layer2/HP.pm b/Info/Layer2/HP.pm index 6cb13a43..a10918cf 100644 --- a/Info/Layer2/HP.pm +++ b/Info/Layer2/HP.pm @@ -112,12 +112,12 @@ $VERSION = '2.00'; ); %MUNGE = ( - # Inherit all the built in munging %SNMP::Info::Layer3::MUNGE, %SNMP::Info::MAU::MUNGE, %SNMP::Info::LLDP::MUNGE, - %SNMP::Info::CDP::MUNGE + %SNMP::Info::CDP::MUNGE, + 'c_id' => \&munge_hp_c_id, ); %MODEL_MAP = ( @@ -553,7 +553,6 @@ sub c_port { foreach my $iid ( keys %$lldp ) { my $port = $lldp->{$iid}; next unless defined $port; - $c_port{$iid} = $port; } return \%c_port; @@ -570,19 +569,32 @@ sub c_id { foreach my $iid ( keys %$cdp ) { my $id = $cdp->{$iid}; next unless defined $id; - + $c_id{$iid} = $id; } - + foreach my $iid ( keys %$lldp ) { - my $id = $lldp->{$iid}; - next unless defined $id; - - $c_id{$iid} = $id; + my $id = $lldp->{$iid}; + next unless defined $id; + + $c_id{$iid} = $id; } return \%c_id; } +sub munge_hp_c_id { + my ($v) = @_; + if ( length(unpack('H*', $v)) == 12 ){ + return join(':',map { sprintf "%02x", $_ } unpack('C*', $v)); + }if ( length(unpack('H*', $v)) == 10 ){ + # IP address (first octet is sign, I guess) + my @octets = (map { sprintf "%02x",$_ } unpack('C*', $v))[1..4]; + return join '.', map { hex($_) } @octets; + }else{ + return $v; + } +} + sub c_platform { my $hp = shift; my $partial = shift;