Agent display Hex-STRING

Hi Frank
How does agent determine data type “Hex-STRING” vs “STRING”? I am curious if I missed something in handling the data type.

with snmp4j-agent
SNMPv2-SMI::enterprises.4491. = STRING: “07E4011E12140E00”

previous non-snmp4j agent displays
SNMPv2-SMI::enterprises.4491. = Hex-STRING: 07 E4 01 15 0E 3A 2B 00


In SNMP (SMI) there is no data type string nor there is any hex-string. Instead there is OCTET-STRING, which is a plain 8bit/element Byte string.

Said that. I guess you have put a hexadecimal string as string into the SNMP4J OctetString type. That’s why the resulting value does not match your expectations.
Instead, simply put the bytes represented by the original hex-string into the OctetString using the setValue method for example.

Thanks Frank. I have resolve my issue.
I have another issue that relates to this. I have some byte arrays, each represent string “09”, “0a”, “0b”, “0c”, “0d”. I did new OctetString(byte[]), but I found something quite interesting. Whenever I have “09”, the agent displays as followed. It seems like they are replaced by numbers of spaces. I checked ascii table 9 is a TAB, A is LF, etc. Is there a way to escape them and display the correct value?

SNMPv2-SMI::enterprises.4491. = STRING: " "
SNMPv2-SMI::enterprises.4491. = STRING: "
SNMPv2-SMI::enterprises.4491. = STRING: "
SNMPv2-SMI::enterprises.4491. = STRING: "
"NMPv2-SMI::enterprises.4491. = STRING: "

There is no “escaping” in the agent, as I wrote before, in the agent and on the wire there is plain OCTET-STRING only. That means, you have two options:

  1. Create a MIB specification for your OBJECT-TYPE that defines how your OCTET-STRING should be displayed using a DISPLAY-HINT clause.
  2. Configure your client to print the OCTET-STRING as a hex-string,

Of course, the first option is the preferred one because others could benefit from that too :slightly_smiling_face: