[SNMP4J] Octet strings returned for sysDesc with whitespace

Frank Fock fock at agentpp.com
Wed May 3 23:42:19 CEST 2006


Hi Ron,

Good point. I have changed OctetString.isPrintable for the
next release as follows:

   /**
    * Determines whether this octet string contains non ISO control 
characters
    * only.
    * @return
    *    <code>false</code> if this octet string contains any ISO control
    *    characters as defined by <code>Character.isISOControl(char)</code>
    *    except if these ISO control characters are all whitespace 
characters
    *    as defined by <code>Character.isWhitespace(char)</code>.
    */
   public boolean isPrintable() {
     for (int i=0; i<value.length; i++) {
       char c = (char)value[i];
       if ((Character.isISOControl(c) ||
           ((value[i] & 0xFF) >= 0x80)) && (!Character.isWhitespace(c))) {
         return false;
       }
     }
     return true;
   }

Best regards,
Frank

Rozensky, Ronald S (Ronald) wrote:
> I'm using SNMP4J 1.7.1 to query a variety of devices, but the Cisco's
> are returning a hex sysDesc:
> 
>  
> 
> 1.3.6.1.2.1.1.1.0 =
> 43:69:73:63:6f:20:49:6e:74:65:72:6e:65:74:77:6f:72:6b:20:4f:70:65:72:61:
> 74:69:6e:67:20:53:79:73:74:65:6d:20:53:6f:66:74:77:61:72:65:20:0d:0a:49:
> 4f:53:20:28:74:6d:29:20:34:35:30:30:20:53:6f:66:74:77:61:72:65:20:28:43:
> 34:35:30:30:2d:4a:53:2d:4d:29:2c:20:56:65:72:73:69:6f:6e:20:31:32:2e:30:
> 28:35:29:2c:20:52:45:4c:45:41:53:45:20:53:4f:46:54:57:41:52:45:20:28:66:
> 63:31:29:0d:0a:43:6f:70:79:72:69:67:68:74:20:28:63:29:20:31:39:38:36:2d:
> 31:39:39:39:20:62:79:20:63:69:73:63:6f:20:53:79:73:74:65:6d:73:2c:20:49:
> 6e:63:2e:0d:0a:43:6f:6d:70:69:6c:65:64:20:57:65:64:20:31:36:2d:4a:75:6e:
> 2d:39:39:20:30:33:3a:33:39:20:62:79:20:70:68:61:6e:67:75:79:65
> 
>  
> 
> Cisco includes whitespace in the description. The toString in
> OctetString is checking if the characters are printable in isPrintable.
> isPrintable is using Character.isISOControl-but is not ignoring
> whitespace (linefeeds, tabs, space, etc.).  If isPrintable is changed to
> be as follows:
> 
>  
> 
>   public boolean isPrintable() {
> 
>     for (int i=0; i<value.length; i++) {
> 
>       if (!Character.isWhitespace((char)value[i]) &&
> 
>           (Character.isISOControl((char)value[i]) ||
> 
>           ((value[i] & 0xFF) >= 0x80))) {
> 
>         return false;
> 
>       }
> 
>     }
> 
>     return true;
> 
>   }
> 
>  
> 
> The result is:
> 
> Cisco Internetwork Operating System Software   IOS (tm) C3550 Software
> (C3550-I5Q3L2-M), Version 12.1(19)EA1a, RELEASE SOFTWARE (fc1)
> Copyright (c) 1986-2003 by cisco Systems, Inc.  Compiled Tue 09-Dec-03
> 03:21 by yenanh
> 
>  
> 
> Can the above change be made to isPrintable?  This would save a lot of
> processing downstream having to check the description and converting
> when necessary.
> 
>  
> 
> Ron Rozensky
> 
>  
> 
> _______________________________________________
> SNMP4J mailing list
> SNMP4J at agentpp.org
> http://lists.agentpp.org/mailman/listinfo/snmp4j

-- 
AGENT++
http://www.agentpp.com
http://www.mibexplorer.com
http://www.mibdesigner.com




More information about the SNMP4J mailing list