[SNMP4J] handling IP address formats

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


Hello,

I am performing polling and one particular field  for EIGRP neighbors in 
cisco routers (.1.3.6.1.4.1.9.9.449.1.4.1.1.3)  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 = 
OctetString.fromHexString(neighborAddressStat.getValue().toString());
                 org.snmp4j.smi.Address snmp4jIpAddress = new 
org.snmp4j.smi.IpAddress(os.getValue());
                 neighborAddress = snmp4jIpAddress.toString();


where neighborAddress gives me a string "192.168.1.34"

Worked fine until some devices are now returning a string like 
"192.168.1.34" 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 "192.168.1.34" string or a byte array.  Octet 
string breaks on "192.168.1.34" 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?

Thanks,
Chris








More information about the SNMP4J mailing list