1

I'm using SNMP4J to read info of devices with SNMP. Now I found some devices which represent the system name (OID iso.3.6.1.2.1.1.5.0) as a Hex-STRING instead of a STRING.

To show the system name I use the following code:

Variable var = response.getVariable(new OID(".1.3.6.1.2.1.1.5.0"));
System.out.println(var.toString());

Where response is a PDU object.

If the system name is represented as a STRING value, this goes as I expected. When it is represented as a Hex-STRING, it just prints the Hex value.

Example:
Take the name of the system as "SYSTEM NAME".
With STRING it prints "SYSTEM NAME".
With Hex-STRING it prints "53:59:53:54:45:4d:20:4e:41:4d:45"

Now with snmpwalk in command line I can just use the -Oa flag. This makes all Hex-STRING values show as STRING. Is it possible to use this flag in SNMP4J or is there a similar option?

Daantie
  • 951
  • 10
  • 13

1 Answers1

0

I'm not sure where you're getting the term "Hex-STRING" from. SNMP does not define such a data type. I suggest you read through the relevant RFC documents, they are publicly available from IETF. The wikipedia article for SNMP (http://en.wikipedia.org/wiki/Simple_Network_Management_Protocol#References) has an excellent reference list, you can start with browsing the ones marked as "STD".

In SNMP, all strings are subtypes (or in a different word, "restrictions") of OCTET-STRING, a byte string of indeterminate length. It may contain any data, even non-printable stuff, representing a jpeg image or whatever.

Some textual-conventions have been defined, which restrict the data to some specific byte range, or length. A DisplayString is defined to only contain bytes from the NVT ASCII character set, so the user may trust it to be printable.

In fact, sysName is defined to be a DisplayString with a max length of 255 characters.

sysName OBJECT-TYPE
              SYNTAX  DisplayString (SIZE (0..255))

Since a good SNMP manager is aware of RFC1213-MIB, which defines both sysName and DisplayString, the manager should assume that the data received is printable ASCII characters.

When you say "When it is represented as a Hex-STRING", what do you mean? "Represented" where, on the agent or in your Java code or when using the net-snmp "snmpwalk" command?

The var.toString() call should convert the contents of the variable into something that could be safely printed in a terminal, so it's possible that SNMP4j is converting any binary string to a hex string.

Jolta
  • 2,620
  • 1
  • 29
  • 42
  • Thanks for your reply. I see Hex-STRING when using the net-snmp "snmpwalk" command. I'm sure the sysName of the device only contains printable ASCII characters, so I don't understand why this device returns the sysName as hexadecimal. When using the -Oa option with the "snmpwalk" command it does return a readable string, so I was wondering if there is such an option in SNMP4J. – Daantie Mar 24 '14 at 11:32
  • The -O flags to "snmpwalk" will only affect the way "snmpwalk" formats its printouts. The data transferred on the network still has the same, binary, format. "snmpwalk" is very helpful that way. So, in your SNMP4j code, if you want to handle the string as ASCII, you can do that. Just call "toString()", it should work by default, as long as the contents are actually printable. If you want to print it as a hex-string, you'll have to do some conversion, probably iterate over the bytes of the string and convert each byte to a pair of hex digits. – Jolta Mar 25 '14 at 13:31