[AGENT++] Parse ASCII and bit string value from response

Zhenyu Zhou zzy.cs.sxfs at gmail.com
Fri Oct 7 01:32:04 CEST 2016


Hello,

I'm using SNMP++ to do queries and it works well for most cases. However,
when querying the OID with suffix "1.3.6.1.2.1.2.2.1.6.", the result is
broken.

Basically, such OIDs are the MAC address of interface and it is not an
ASCII string in the return packet. I used wireshark to catch the packet,
the result is below:

(Assume the MAC address is 12:34:56:78:90:12)
1. Data in packet: 12 34 56 78 90 12 (by byte)
2. Data given by SNMP++: ____12_34_56_78_90_12_____s. ("_" denotes
unprintable character here. And the ASCII value of the raw byte array is
"_____s.")
3. What I expected: 12:34:56:78:90:12

Currently, I'm using the similar code as snmpWalk.cpp in the sample tar
ball.
Important code lines:

snmp.get_bulk( pdu,*target,0,BULK_MAX)

...

pdu.get_vb(vb, z); // z is an index in the for loop to retrieve all
variables

cout << vb.get_printable_value() << "\n";


Furthermore, there are also other OIDs that represent interface name, which
is an ASCII string (eg. "eth0"). SNMP++ parses such string correctly.
Therefore I suspect it somehow always assume the string is an ASCII one(at
least in my way of using it).

Also, I've also tested net-snmp, another c++ library and it doesn't have
such issue. Its variable type contains a field called type, which could be
"ASN_BIT_STR" or "ASN_OCTET_STR" to solve this case. But I currently didn't
find the corresponding mechanism for SNMP++.

Any ideas to fix this problem so that the string of ASCII and non-ASCII
format can be distinguished?

Many thanks!


Best Regards!

Zhou, Zhenyu


More information about the AGENTPP mailing list