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

Jochen Katz katz at agentpp.com
Fri Oct 7 22:10:34 CEST 2016


Hi,

> 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.
> 
> (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

the data given by the vb.get_printable_value() should be the following
(everything between the "):
"  12 34 56 78 90 12                                  .4Vx..
"
This is the default behaviour of OctetStr::get_printable(). As the
string contains non-printable characters (0x12), it prints a HEX block
followed by the printable characters where everything that is not
printable is replaced by a dot.

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

snmp++ does not know the MIB information that specifies that the value
of this Oid is PhysAddress, so it is up to your application code to
handle this Oid as a MAC address. This can be done with the following
code (you have to enable the MacAddress class):

  MacAddress mac;
  vb.get_value(mac);
  cout << mac.get_printable() << endl;

Regards,
  Jochen



More information about the AGENTPP mailing list