Hi
I am learning to coding MIBs. My problem is that my module is not answering
to MODE_GET message. Here is code
/*
* Note: this file originally auto-generated by mib2c using
* : mib2c.int_watch.conf,v 5.0 2002/04/20 07:30:13 hardaker 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 "nstAgentPluginObject.h"
/*
* the variable we want to tie an OID to. The agent will handle all
* * GET and SET requests to this variable changing it's value as needed.
*/
static int nstAgentPluginObject = 3;
static int nstAgentPluginObject1 = 42;
static int nstAgentPluginObject2 = 69;
#define DELAYED_INSTANCE_SET_NAME "nstAgentPluginObject2_delayed"
int
nstAgentPluginObject2_handler(netsnmp_mib_handler *handler,
netsnmp_handler_registration *reginfo,
netsnmp_agent_request_info *reqinfo,
netsnmp_request_info *requests)
{
u_long *nstAgentPluginObject2_cache = NULL;
int ret;
DEBUGMSGTL(("nstAgentPluginObject2", "Got request, mode = %d:\n",
reqinfo->mode));
//requests->delegated = 0;
switch (reqinfo->mode) {
case MODE_GET:
case MODE_GETNEXT:
/*
* return the currend delay time
*/
DEBUGMSGTL(("nstAgentPluginObject2", "Got get, value = %d:\n",
nstAgentPluginObject2));
ret = snmp_set_var_typed_value(requests->requestvb,
ASN_INTEGER,
(u_char *) & nstAgentPluginObject2,
sizeof(nstAgentPluginObject2));
DEBUGMSGTL(("nstAgentPluginObject2", "snmp_set_var_typed_value returned
%d\n",
ret));
break;
case MODE_SET_RESERVE1:
/*
* check type
*/
if (requests->requestvb->type != ASN_INTEGER) {
/*
* not an integer. Bad dog, no bone.
*/
netsnmp_set_request_error(reqinfo, requests,
SNMP_ERR_WRONGTYPE);
/*
* we don't need the cache any longer
*/
//netsnmp_free_delegated_cache(cache);
return SNMP_ERR_WRONGTYPE;
}
break;
case MODE_SET_RESERVE2:
/*
* store old value for UNDO support in the future.
*/
memdup((u_char **) & nstAgentPluginObject2_cache,
(u_char *) & nstAgentPluginObject2,
sizeof(nstAgentPluginObject2));
/*
* malloc failed
*/
if (nstAgentPluginObject2_cache == NULL) {
netsnmp_set_request_error(reqinfo, requests,
SNMP_ERR_RESOURCEUNAVAILABLE);
//netsnmp_free_delegated_cache(cache);
return SNMP_ERR_RESOURCEUNAVAILABLE;
}
/*
* Add our temporary information to the request itself.
* This is then retrivable later. The free function
* passed auto-frees it when the request is later
* deleted.
*/
netsnmp_request_add_list_data(requests,
netsnmp_create_data_list
(DELAYED_INSTANCE_SET_NAME,
nstAgentPluginObject2_cache, free));
break;
case MODE_SET_ACTION:
/*
* update current value
*/
nstAgentPluginObject2 = *(requests->requestvb->val.integer);
DEBUGMSGTL(("nstAgentPluginObject2_handler", "updated
nstAgentPluginObject2 -> %d\n",
nstAgentPluginObject2));
break;
case MODE_SET_UNDO:
/*
* ack, something somewhere failed. We reset back to the
* previously old value by extracting the previosuly
* stored information back out of the request
*/
nstAgentPluginObject2 =
*((u_long *) netsnmp_request_get_list_data(requests,
DELAYED_INSTANCE_SET_NAME));
break;
case MODE_SET_COMMIT:
case MODE_SET_FREE:
/*
* the only thing to do here is free the old memdup'ed
* value, but it's auto-freed by the datalist recovery, so
* we don't have anything to actually do here
*/
break;
}
return SNMP_ERR_NOERROR;
}
/*
* our initialization routine, automatically called by the agent
* (to get called, the function name must match init_FILENAME())
*/
void
init_nstAgentPluginObject(void)
{
static oid nstAgentPluginObject_oid[] =
{ 1, 3, 6, 1, 4, 1, 8072, 2, 4, 1, 1, 3, 0 };
static oid nstAgentPluginObject1_oid[] =
{ 1, 3, 6, 1, 4, 1, 8072, 2, 4, 1, 1, 4, 0 };
static oid nstAgentPluginObject2_oid[] =
{ 1, 3, 6, 1, 4, 1, 8072, 2, 4, 1, 1, 5, 0 };
netsnmp_handler_registration *my_test;
/*
* a debugging statement. Run the agent with -DnstAgentPluginObject to
see
* the output of this debugging statement.
*/
DEBUGMSGTL(("nstAgentPluginObject",
"Initializing the nstAgentPluginObject module\n"));
/*
* the line below registers our variables defined above as
* accessible and makes it writable. A read only version of any
* of these registration would merely call
* register_read_only_int_instance() instead. The functions
* called below should be consistent with your MIB, however.
*
* If we wanted a callback when the value was retrieved or set
* (even though the details of doing this are handled for you),
* you could change the NULL pointer below to a valid handler
* function.
*/
DEBUGMSGTL(("nstAgentPluginObject",
"Initalizing nstAgentPluginObject scalar integer. Default
value = %d\n",
nstAgentPluginObject));
DEBUGMSGTL(("nstAgentPluginObject1",
"Initalizing nstAgentPluginObject scalar integer. Default
value = %d\n",
nstAgentPluginObject1));
netsnmp_register_int_instance("nstAgentPluginObject",
nstAgentPluginObject_oid,
OID_LENGTH(nstAgentPluginObject_oid),
&nstAgentPluginObject, NULL);
netsnmp_register_int_instance("nstAgentPluginObject1",
nstAgentPluginObject1_oid,
OID_LENGTH(nstAgentPluginObject1_oid),
&nstAgentPluginObject1, NULL);
my_test =
netsnmp_create_handler_registration("nstAgentPluginObject2",
nstAgentPluginObject2_handler,
nstAgentPluginObject2_oid,
OID_LENGTH(nstAgentPluginObject2_oid),
HANDLER_CAN_RWRITE);
netsnmp_register_instance(my_test);
//netsnmp_register_int_instance("nstAgentPluginObject2",
// nstAgentPluginObject2_oid,
// OID_LENGTH(nstAgentPluginObject2_oid),
// &nstAgentPluginObject2, NULL);
DEBUGMSGTL(("nstAgentPluginObject",
"Done initalizing nstAgentPluginObject module\n"));
}
Here is snmp agent output
-bash-3.00# /usr/sfw/sbin/snmpd -f -L -DnstAgentPluginObject,dlmod
dlmod: register mib
dlmod: dlmod_path: /usr/sfw/lib/amd64/snmp/dlmod
dlmod: dlmod_create_module
dlmod: dlmod_load_module nstAgentPluginObject:
/usr/sfw/lib/amd64/nstAgentPluginObject.so
nstAgentPluginObject: Initializing the nstAgentPluginObject module
nstAgentPluginObject: Initalizing nstAgentPluginObject scalar integer.
Default value = 3
nstAgentPluginObject1: Initalizing nstAgentPluginObject scalar integer.
Default value = 42
nstAgentPluginObject: Done initalizing nstAgentPluginObject module
NET-SNMP version 5.0.9
nstAgentPluginObject2: Got request, mode = 160:
nstAgentPluginObject2: Got get, value = 69:
nstAgentPluginObject2: snmp_set_var_typed_value returned 0
nstAgentPluginObject2: Got request, mode = 160:
nstAgentPluginObject2: Got get, value = 69:
nstAgentPluginObject2: snmp_set_var_typed_value returned 0
nstAgentPluginObject2: Got request, mode = 160:
nstAgentPluginObject2: Got get, value = 69:
nstAgentPluginObject2: snmp_set_var_typed_value returned 0
nstAgentPluginObject2: Got request, mode = 160:
nstAgentPluginObject2: Got get, value = 69:
nstAgentPluginObject2: snmp_set_var_typed_value returned 0
nstAgentPluginObject2: Got request, mode = 160:
nstAgentPluginObject2: Got get, value = 69:
nstAgentPluginObject2: snmp_set_var_typed_value returned 0
nstAgentPluginObject2: Got request, mode = 160:
nstAgentPluginObject2: Got get, value = 69:
nstAgentPluginObject2: snmp_set_var_typed_value returned 0
^CReceived TERM or STOP signal... shutting down...
dlmod: Module nstAgentPluginObject unloaded
Here is snmpget output
-bash-3.00# snmpget -c private localhost
NET-SNMP-TUTORIAL-MIB::nstAgentPluginObject2.0
Timeout: No Response from localhost.
-bash-3.00#
I build module using command
$(CC) $(CFLAGS) -xarch=amd64 -G -o nstAgentPluginObject.so -Kpic
nstAgentPluginObject.c
snmpset is working correctly
-bash-3.00# snmpset -c private localhost
NET-SNMP-TUTORIAL-MIB::nstAgentPluginObject2.0 = 234
NET-SNMP-TUTORIAL-MIB::nstAgentPluginObject2.0 = INTEGER: 234
-bash-3.00#
Also nstAgentPluginObject and nstAgentPluginObject1 are working correctly
I am using version 5.0.9 because I want to create module for x86 Solaris 10.
I installed headerfiles ( <net-snmp/net-snmp-config.h> ... )
from net-snmp-5.0.11
Christer Ekholm
-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
_______________________________________________
Net-snmp-coders mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/net-snmp-coders