Skip Menu |

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

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

People
Owner: dtown [...] cpan.org
Requestors: bug [...] davidprantl.de
Cc:
AdminCc:

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



Subject: octet_string translate bug
when fetching mac addresses from a cisco-router, which are octet_strings, some of them are returned untranslated, even though translation is enabled. here are two examples, the first one is a mac for which the translation didnt work, using sprintf('0x%s', unpack('H*', $variable)) directly did the job, so i "guess(although i have no real understanding of the Message.pm module)" that the octet_string is perhaps recognized incorrectly? (in the following expamle, left of the => means with translate => ['-octetstring' => 0] e.g. turnded of, right of => is whats returned with it turned on.) first example, doesnt translate correctly: ^L>Z? => ^L>Z? sprintf yields: 0x00000c3e5a3f second expamle, here everything worked fine: 0:ยข@ => 0x0030193aa240 The versions of my underlying os and perl: Net::SNMP: $Id: SNMP.pm,v 4.5 2002/09/09 12:46:09 dtown Exp $ Perl: This is perl, v5.6.1 built for i586-linux# OS: SuSE Linux 8.0 (i386) Please contact me for any additional info you might need. Best Regards, David Prantl
What you are seeing is the expected behavior of the module. The Net::SNMP module has translation enabled by default. When an OCTET STRING is received, the contents of the string are checked to make sure that all octets are printable. If any octet is not printable, the string is translated into the hexadecimal representation. The key factor here is "What is printable?". 0x00000c3e5a3f 00 - NUL <considered printable by the module> 00 - NUL <considered printable by the module> 0c - FF <considered printable by the module> 3e - > 5a - Z 3f - ? The OCTET STRING in question contains all printable characters (as defined by the module), so no translation takes place. From the documentation: When the object decodes the GetResponse-PDU that is returned in response to a SNMP message, certain values are translated into a more ``human readable'' form. By default the following translations occur: * OCTET STRINGs and Opaques containing non-printable ASCII characters are converted into a hexadecimal representation prefixed with ``0x''. NOTE: The following ASCII control characters are considered to be printable by the module: NUL(0x00), HT(0x09), LF(0x0A), FF(0x0C), and CR(0x0D). If you know the "type" of the value to you will be querying, I usually recommend to users that they disable translation and do their own. ==== ($session, $error) = Net::SNMP->session( ... -translate => [-octetstring => 0x0], ... ); ... $oid = "<your OID>"; $response = $session->get_request($oid); printf("%s: %s\n", $oid, _format_mac($response->{$oid})); ... sub _format_mac { sprintf("%s:%s:%s:%s:%s:%s", unpack('H2' x 6, $_[0])); } ==== -David