Skip Menu |

This queue is for tickets about the Net-SNMP CPAN distribution.

Report information
The Basics
Id: 25381
Status: resolved
Worked: 6 min
Priority: 0/
Queue: Net-SNMP

People
Owner: dtown [...] cpan.org
Requestors: netsnmp [...] agk.nnov.ru
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: It is a bug rather then translate feature.
Date: Mon, 12 Mar 2007 10:16:21 +0300
To: bug-Net-SNMP [...] rt.cpan.org
From: Andrei Koulik <netsnmp [...] agk.nnov.ru>
Hello, I use perl Net-SNMP to manage my devices. In particular it used to retrieve mac addresses. Most of mac addresses are returned in hex-string format e.g. 0x001195287e87 but some in string format e.g. PpdOf of course it is very hard to parse data in different formats, so i tried to play with translate function, but was failed. When I looked over code then found: if (($this->{_translate} & $mask) && ($s =~ /[\x01-\x08\x0b\x0e-\x1f\x7f-\xff]/g)) { DEBUG_INFO("translating %s to printable hex string", asn1_itoa($type)); sprintf('0x%s', unpack('H*', $s)); It means the translate never occurs if no "non-printable" chars in a string. other words I always will receive 00:50:70:64:4f:66 as PpdOf but 00:11:95:28:7e:87 as 0x001195287e87 I think it is wrong logic and should be used OR operator instead of AND: If mask sets to use translate function, then it will used always. Else it will be used only then string contains "non-printable" chars. -- Best regards, Koulik Andrei
The "translate" functionality of Net::SNMP was designed as a presentation aid, not as a format converter. To quote the documentation, by default data is "translated into a more 'human readable' form." Since Net::SNMP works at the protocol level, it has no knowledge of proper syntax of the data as defined in the MIBs. The translation code makes a best guess at how things are to be translated. Without translation enabled, the raw byte stream is returned. You state that your program works primarily with MAC addresses, but you did not specifically state what it does. When working with MAC addresses most people I am familiar with turn off translation and use the raw values. When it comes time to display anything they then format the output themselves such as: sub format_mac { sprintf("%02x:%02x:%02x:%02x:%02x:%02x", unpack('C*', $_[0])); }
Subject: Re: [rt.cpan.org #25381] It is a bug rather then translate feature.
Date: Mon, 12 Mar 2007 18:41:38 +0300
To: via RT <bug-Net-SNMP [...] rt.cpan.org>
From: netsnmp [...] agk.nnov.ru <netsnmp [...] agk.nnov.ru>
Thank you. I have gone by wrong way! I assumed translated values as main form, really I must use 'original', not translated value, and do unpack where need. So now my scripts will become little more graceful. I revoke this ticked, please close it. Monday, March 12, 2007, 4:40:52 PM, via RT wrote: Show quoted text
Show quoted text
> The "translate" functionality of Net::SNMP was designed as a > presentation aid, not as a format converter. To quote the > documentation, by default data is "translated into a more 'human > readable' form." Since Net::SNMP works at the protocol level, it has no > knowledge of proper syntax of the data as defined in the MIBs. The > translation code makes a best guess at how things are to be translated. > Without translation enabled, the raw byte stream is returned.
Show quoted text
> You state that your program works primarily with MAC addresses, but you > did not specifically state what it does. When working with MAC > addresses most people I am familiar with turn off translation and use > the raw values. When it comes time to display anything they then format > the output themselves such as:
Show quoted text
> sub format_mac > { > sprintf("%02x:%02x:%02x:%02x:%02x:%02x", unpack('C*', $_[0])); > }
-- Andrei Koulik.
Net::SNMP module is working was documented.