/*
*
* U.S. Government Rights - Commercial software. Government users are subject
* to the Sun Microsystems, Inc. standard license agreement and applicable
* provisions of the FAR and its supplements.
*
*
* This distribution may include materials developed by third parties. Sun,
* Sun Microsystems, the Sun logo and Solaris are trademarks or registered
* trademarks of Sun Microsystems, Inc. in the U.S. and other countries.
*
*/
/*
* Note: this file originally auto-generated by mib2c using :
* mib2c.scalar.conf,v 1.5 2002/07/18 14:18:52 dts12 Exp $
*/
#include <net-snmp/net-snmp-config.h>
#include <net-snmp/net-snmp-includes.h>
#include "demo_module_6.h"
//Hardcoded size of fileX context name string
//Hardcoded size of fileY context name string
/*
The following code example shows how to write a module that registers
an object in two different contexts. It also shows how to check for
the contextName in a request and return a different value depending
on the value of the contextName.
The code example registers one object, filesize, in two different
contexts, fileX, and fileY. This example registers the OIDs using a
read-only instance handler helper. The OIDs do not need to be read-only.
You could also register the OIDs using any of the SMA instance handler
helper APIs.
The function get_filesize is registered to handle get requests for
instances of the filesize object. This function checks the contextName
in the reginfo structure that is passed to the function by the SMA
agent. If the value of contextName is fileX, the function returns
fileX_data, which has been set to the integer 111. If the value of
contextName is fileY, the function returns fileY_data, which has been
set to the integer 999. */
/* Initialialization routine, which is automatically called by the agent.
The function name must match init_FILENAME() */
void
init_demo_module_6(void)
{
/*
* the OID at which to register the demo_module_6 integer.
*/
{1, 3, 6, 1, 4, 1, 42, 2, 2, 4, 4, 6, 1, 1, 0};
//Registration handler
//Name of fileX context
//Name of fileY context
/*
* A debugging statement. Run the agent with -Ddemo_module_6 to see
* default. Use the -L option to write debugging output to the
* screen.
*/
/*
* Creates a read-only registration handler named demo_module_6,
* which calls the get_demo_module_6 function to service snmp
* requests for the demo_module_6_oid object. The OID_LENGTH
* argument calculates the length of the demo_module_6_oid.
*/
("filesize",
/*
* Assigns new filename as a context string in the contextName member
* of the netsnmp_registration_handler struct for the filesize_oid.
*/
/*
* Registers the OID and contextName.
*
*/
/*
* Creates a read-only registration handler named filesize, which
* calls the get_filesize function to service snmp requests for the
* filesize_oid object. The OID_LENGTH argument calculates the
* length of the filesize_oid.
*/
("filesize",
/*
* Assigns new filename as a context string in the contextName member
* of the netsnmp_registration_handler struct for the filesize_oid.
*/
/*
* Creates a read-only registration handler named filesize, which
* calls the get_filesize function to service snmp requests for the
* filesize_oid object. The OID_LENGTH argument calculates the
* length of the filesize_oid.
*/
}
int
{
/*
* This handler is never called for a getnext if it is registered as
* an instance. An instance handler only delivers one request at a
* time, so we do not need to loop over a list of requests.
*/
reginfo->contextName));
case MODE_GET:
sizeof (fileX_data) /* length in bytes */);
ASN_INTEGER, (u_char *)
& fileY_data,
sizeof (fileY_data));
break;
default:
/*
* We should never get here, so this is a really bad error.
*/
return (SNMP_ERR_GENERR);
}
return (SNMP_ERR_NOERROR);
}