C - Parse string from SNMP SET (weird) -


i working on own snmp agent , having trouble processing strings. pretty new snmp well.

i've referred following links of implementing own agent :

http://www.net-snmp.org/dev/agent/ucddemopublic_8c_source.html

http://www.net-snmp.org/dev/agent/example_8h_source.html

the second link shows how handle when user attempts set integer type mib object :

line 657 shows :

intval = *((long *) var_val); 

my question : how go string? i've tried casting it, strncpy, snprintf, etc.

my work :

i know, or @ least think, following legal :

int setstring(int action,                  u_char * var_val,                  u_char var_val_type,                  size_t var_val_len,                  u_char * statp, oid * name, size_t name_len) {     unsigned char publicstring[10];     static long intval;     char *cmd_string = null;      /*      * define arbitrary maximum permissible value      */     switch (action) {     case reserve1:          //intval = *((long *) var_val);          /*          *  check value being set acceptable          */         if (var_val_type != asn_octet_str) {             debugmsgtl(("setstring", "%x not string type", var_val_type));             return snmp_err_wrongtype;         }          if (var_val_len > 1 ) {             debugmsgtl(("setstring", "wrong length %" netsnmp_priz "u",                         var_val_len));             return snmp_err_wronglength;         }          if ( !(var_val[0] == '1' || var_val[0] == '0') )         {             debugmsgtl(("setstring", "wrong value %s", var_val));             return snmp_err_wrongvalue;         } 

i know working because when invoke

# snmpset -v 2c -c xxx 10.20.30.40 1.3.6.1.4.1.54321.3.0 s 3 error in packet. reason: wrongvalue (the set value illegal or unsupported in way) failed object: my-test-mib::testsnmp.3.0 

and

snmpset -v 2c -c xxx 10.20.30.40 1.3.6.1.4.1.54321.3.0 s 1 my-test-mib::testsnmp.3.0 = string: "1" 

this proves me @ least last collection of code working.

here action part :

   case action:         /*          *  set variable requested.          *   note may need reversed,          *   save information needed this.          */          if ( var_val[0] == '1' )         {             //do stuff - there realy script call here         }          if ( var_val[0] == '0' )         {             //do stuff - there realy script call here         }         break; 

the above section cannot work.

i've been able want making object integer (asn.1) type can't because when reading object returns string (asn.1).


Comments

Popular posts from this blog

methods - python can't use function in submodule -

Java 3D LWJGL collision -

c# - ErrorThe type or namespace name 'AxWMPLib' could not be found (are you missing a using directive or an assembly reference?) -