/*
* Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
*
* 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 <net-snmp/agent/net-snmp-agent-includes.h>
#include "demo_module_6.h"
//Hardcoded size of fileX context name string
static long fileX_data = 111;
//Hardcoded size of fileY context name string
static long fileY_data = 999;
/*
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.
*/
static oid filesize_oid[] =
{1, 3, 6, 1, 4, 1, 42, 2, 2, 4, 4, 6, 1, 1, 0};
netsnmp_handler_registration *myreg1;
//Registration handler
char *filexcon = "fileX";
//Name of fileX context
char *fileycon = "fileY";
//Name of fileY context
/*
* A debugging statement. Run the agent with -Ddemo_module_6 to see
* the output of this debugging statement in /var/log/snmpd.log, by
* default. Use the -L option to write debugging output to the
* screen.
*/
DEBUGMSGTL(("demo_module_6", "Initializing\n"));
/*
* 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.
*/
myreg1 = netsnmp_create_handler_registration
("filesize",
get_filesize,
filesize_oid,
OID_LENGTH(filesize_oid),
HANDLER_CAN_RONLY);
/*
* Assigns new filename as a context string in the contextName member
* of the netsnmp_registration_handler struct for the filesize_oid.
*/
myreg1->contextName = filexcon;
/*
* Registers the OID and contextName.
*
*/
netsnmp_register_read_only_instance(myreg1);
/*
* 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.
*/
myreg1 = netsnmp_create_handler_registration
("filesize",
get_filesize,
filesize_oid,
OID_LENGTH(filesize_oid),
HANDLER_CAN_RONLY);
/*
* Assigns new filename as a context string in the contextName member
* of the netsnmp_registration_handler struct for the filesize_oid.
*/
myreg1->contextName = fileycon;
/*
* 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.
*/
netsnmp_register_read_only_instance(myreg1);
}
int
get_filesize(netsnmp_mib_handler * handler,
netsnmp_handler_registration * reginfo,
netsnmp_agent_request_info * reqinfo,
netsnmp_request_info * requests)
{
/*
* 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.
*/
DEBUGMSGTL(("demo_module_6", "get_filesize CALLED\n"));
DEBUGMSGTL(("demo_module_6", "INCOMING CONTEXT NAME = %s:\n",
reginfo->contextName));
switch (reqinfo->mode) {
case MODE_GET:
if (strcmp(reginfo->contextName, "fileX") == 0)
snmp_set_var_typed_value(requests->requestvb,
ASN_INTEGER, (u_char *) & fileX_data,
sizeof (fileX_data) /* length in bytes */);
else if (strcmp(reginfo->contextName, "fileY") == 0)
snmp_set_var_typed_value(requests->requestvb,
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);
}