[SNMP4J] handling IP address formats

Chris Richmond crichmond at referentia.com
Fri Jan 20 09:33:16 CET 2012


I am performing polling and one particular field  for EIGRP neighbors in 
cisco routers (.  returns ip addresses in 
a hex string format delimited by ":"...such as c0:A8:01:23. This was 
what I always got for devices I tested and I handled it like this in my 
code using the SNMP4j classes :

            /// neighborAddressStat.getValue().toString()  = "c0:A8:01:23"

                 OctetString os = 
                 org.snmp4j.smi.Address snmp4jIpAddress = new 
                 neighborAddress = snmp4jIpAddress.toString();

where neighborAddress gives me a string ""

Worked fine until some devices are now returning a string like 
"" instead of the hex string, which  of course breaks this code.

There doesn't seem to be a comprehensive method or API in SNMP4j for 
handling both situtions.  In other words,   org.snmp4j.smi.Address can 
be constructed from a "" string or a byte array.  Octet 
string breaks on "" but can provide a byte array from a 
"c0:A8:01:23" format.

It seems as though I am possibly missing the ideal way to handle this 
within the Snmp4j library.

Any ideas?


More information about the SNMP4J mailing list