I have some questions regarding scalar values and how to populate them.

I generated the following two code files using "mib2c" with the 
"mib2c.scalar.conf" configuration file.

  ocStbHostHWIdentifiers.h
  ocStbHostHWIdentifiers.c


There are three data fields (ie: scalar values) defined in the 
"ocStbHostHWIdentifiers" object so there are three "Get" routines which were 
created and defined in the "ocStbHostHWIdentifiers.c" file.

  int handle_ocStbHostSerialNumber()
  int handle_ocStbHostHostID()
  int handle_ocStbHostCapabilities()


Lets use the "handle_ocStbHostSerialNumber()" routine as an example (see below):
Note: I added the structure definition for my testing of course.


typedef struct MIB_OCTET_STRING_s {

   u_long  length;              
   u_char  textStr[50];

} MIB_OCTET_STRING;



int
handle_ocStbHostSerialNumber(netsnmp_mib_handler *handler,
                             netsnmp_handler_registration *reginfo,
                             netsnmp_agent_request_info *reqinfo,
                             netsnmp_request_info *requests)
{

  switch (reqinfo->mode) {

   case MODE_GET:
   {

      MIB_OCTET_STRING  serialNumber;
      strcpy(serialNumber.textStr ,"MY_SERIAL_NUMBER_TEXT");
      serialNumber.length = strlen(serialNumber.textStr);


      snmp_set_var_typed_value(requests->requestvb, 
                               ASN_OCTET_STR,
                               (u_char *)&serialNumber.textStr,
                               serialNumber.length);
  }
  break;


  default:
      /*
       * we should never get here, so this is a really bad error 
       */
      snmp_log(LOG_ERR,
               "unknown mode (%d) in handle_ocStbHostSerialNumber\n",
               reqinfo->mode);
      return SNMP_ERR_GENERR;
  }

  return SNMP_ERR_NOERROR;
}



All I needed to do was to apply a "pointer to the scalar's data" as well as the 
"length of the data in bytes" when calling the "snmp_set_var_typed_value" 
routine.  Based on my test code (shown above), is this how most people would 
supply the pointer (third parameter) to the routine, by simply taking the 
address of the storage location and then casting it to a (u_char*)?   The 
"snmpget" works but for some reason the code looks a bit weird to me so I 
wanted to make sure I was not doing something goofy.

Now, in the "handle_ocStbHostCapabilities()" routine (not shown), I noticed I 
need to supply the scalar value via the same exact "snmp_set_var_typed_value" 
routine interface using a pointer/length combination.   Since the 
"HostCapabilities" value is defined as an "Integer" value in the MIB file, I 
was expecting to call a new routine which had an interface allowing me to 
provide "u_int" value instead of a pointer/length combination.  I guess I 
mainly use the pointer/length stuff when dealing with text strings, but have 
not seen them being used for "Integer" values, etc..   Are all scalar values 
treated the same in that I will need to provide a pointer and byte length for 
each?  If so, then I guess NetSNMP figures out the byte is really not a 
character, but is in fact an Integer ... correct?

Also, what is the "maximum length" of a scalar value which can be passed into 
the "snmp_set_var_typed_value" routine?


       
---------------------------------
Boardwalk for $500? In 2007? Ha! 
Play Monopoly Here and Now (it's updated for today's economy) at Yahoo! Games.
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Net-snmp-coders mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/net-snmp-coders

Reply via email to