I wrote my own simple MIB module, used mib2c.scalar.conf. So, I made my
example like delayed_instance.c.
You can see source code here
/*
* Note: this file originally auto-generated by mib2c using
* : mib2c.scalar.conf 11805 2005-01-07 09:37:18Z dts12 $
*/
#include <net-snmp/net-snmp-config.h>
#include <net-snmp/net-snmp-includes.h>
#include <net-snmp/agent/net-snmp-agent-includes.h>
#include "simpleMib.h"
/** Initializes the simpleMib module */
void
init_simpleMib(void)
{
static oid simpleMibInt_oid[] = { 1,3,6,1,4,1,6,1 };
DEBUGMSGTL(("simpleMib", "Initializing\n"));
netsnmp_register_scalar(
netsnmp_create_handler_registration("simpleMibInt",
handle_simpleMibInt,
simpleMibInt_oid,
OID_LENGTH(simpleMibInt_oid),
HANDLER_CAN_RWRITE
));
}
static int var = 100;
static int* varcache = NULL;
int
handle_simpleMibInt(netsnmp_mib_handler *handler,
netsnmp_handler_registration *reginfo,
netsnmp_agent_request_info *reqinfo,
netsnmp_request_info *requests)
{
int ret;
/* We are never called for a GETNEXT if it's registered as a
"instance", as it's "magically" handled for us. */
DEBUGMSGTL(("simpleMib", "startdispatch\n"));
/* a instance handler also only hands us one request at a time, so
we don't need to loop over a list of requests; we'll only get one. */
switch(reqinfo->mode) {
case MODE_GET:
DEBUGMSGTL(("simpleMib", "mod_get\n"));
snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER,
(u_char *) &var/* XXX: a pointer to the
scalar's data */,
sizeof(var)/* XXX: the length of the
data in bytes */);
DEBUGMSGTL(("simpleMib", "mod_get_ok\n"));
break;
/*
* SET REQUEST
*
* multiple states in the transaction. See:
*
http://www.net-snmp.org/tutorial-5/toolkit/mib_module/set-actions.jpg
*/
case MODE_SET_RESERVE1:
/* or you could use netsnmp_check_vb_type_and_size instead
*/
ret = netsnmp_check_vb_type(requests->requestvb, ASN_INTEGER);
if ( ret != SNMP_ERR_NOERROR ) {
netsnmp_set_request_error(reqinfo, requests, ret );
}
break;
case MODE_SET_RESERVE2:
DEBUGMSGTL(("simpleMib", "mode_set_reserve_2\n"));
memdup((u_char**) &varcache,(u_char*) &var,sizeof(var));
/* XXX malloc "undo" storage buffer */
if (varcache == NULL/* XXX if malloc, or whatever, failed: */) {
DEBUGMSGTL(("simpleMib", "mode_set_reserve_2_varcachenull\n"));
netsnmp_set_request_error(reqinfo, requests,
SNMP_ERR_RESOURCEUNAVAILABLE);
}
/* when i include this function, i receive a error below. Note,
that this function like in delayed_instance.c. example
netsnmp_request_add_list_data(requests,
netsnmp_create_data_list("test",varcache,free));
DEBUGMSGTL(("simpleMib", "mode_set_reserve_2_ok\n"));
break;
case MODE_SET_FREE:
/* XXX: free resources allocated in RESERVE1 and/or
RESERVE2. Something failed somewhere, and the states
below won't be called. */
break;
case MODE_SET_ACTION:
/* XXX: perform the value change here */
DEBUGMSGTL(("simpleMib", "mode_set_action\n"));
var = *(requests->requestvb->val.integer);
DEBUGMSGTL(("simpleMib", "mode_set_action_updated_to-%d\n",var));
if (FALSE/* XXX: error? */) {
netsnmp_set_request_error(reqinfo, requests, 1/* some error
*/);
}
DEBUGMSGTL(("simpleMib", "mode_set_action_ok\n"));
break;
case MODE_SET_COMMIT:
DEBUGMSGTL(("simpleMib", "mode_set_commit\n"));
if (varcache != NULL) {
free(varcache);
varcache = NULL;
}
DEBUGMSGTL(("simpleMib", "mode_set_commit_ok\n"));
/* XXX: delete temporary storage */
if (FALSE/* XXX: error? */) {
/* try _really_really_ hard to never get to this point */
netsnmp_set_request_error(reqinfo, requests,
SNMP_ERR_COMMITFAILED);
}
break;
case MODE_SET_UNDO:
DEBUGMSGTL(("simpleMib", "mode_set_undo\n"));
var = * ((int *) netsnmp_request_get_list_data(requests,"test"));
DEBUGMSGTL(("simpleMib", "mode_set_undo_returned_to-%d\n",var));
/* XXX: UNDO and return to previous value for the object */
if (FALSE/* XXX: error? */) {
/* try _really_really_ hard to never get to this point */
netsnmp_set_request_error(reqinfo, requests,
SNMP_ERR_UNDOFAILED);
}
DEBUGMSGTL(("simpleMib", "mode_set_undo_ok\n"));
break;
default:
/* we should never get here, so this is a really bad error */
snmp_log(LOG_ERR, "unknown mode (%d) in handle_simpleMibInt\n",
reqinfo->mode );
return SNMP_ERR_GENERR;
}
DEBUGMSGTL(("simpleMib", "dispatch_ok\n"));
return SNMP_ERR_NOERROR;
}
this is received by gdb:
Program received signal SIGSEGV, Segmentation fault.
_int_malloc (av=<value optimized out>, bytes=<value optimized out>) at
malloc.c:4339
4339 malloc.c: no such file.
in malloc.c
(gdb) bt
#0 _int_malloc (av=<value optimized out>, bytes=<value optimized out>) at
malloc.c:4339
#1 0x0042a682 in __libc_calloc (n=10, elem_size=4) at malloc.c:4065
#2 0x0059d86f in netsnmp_binary_array_insert (container=0x9444710,
data=0x9444338) at container_binary_array.c:426
#3 _ba_insert (container=0x9444710, data=0x9444338) at
container_binary_array.c:561
#4 0x001fd26a in CONTAINER_INSERT_HELPER (container=0x9444710,
load_flags=<value optimized out>)
at ../../include/net-snmp/library/container.h:421
#5 CONTAINER_INSERT (container=0x9444710, load_flags=<value optimized out>)
at ../../include/net-snmp/library/container.h:445
#6 netsnmp_arch_interface_container_load (container=0x9444710,
load_flags=<value optimized out>) at
if-mib/data_access/interface_linux.c:768
#7 0x001c7742 in netsnmp_access_interface_container_load
(container=0x9444710, load_flags=0) at if-mib/data_access/interface.c:159
#8 0x001cc3b8 in ifTable_container_load (container=0x93a72d0) at
if-mib/ifTable/ifTable_data_access.c:546
#9 0x001cb208 in _cache_load (cache=0x93a7270, vmagic=0x93a72d0) at
if-mib/ifTable/ifTable_interface.c:1838
#10 0x00397858 in _cache_load (cache=0x93a7270) at
helpers/cache_handler.c:624
#11 0x0058131a in run_alarms () at snmp_alarm.c:246
#12 0x0804b6ef in receive (argc=6, argv=0xbfa00ae4) at snmpd.c:1297
#13 main (argc=6, argv=0xbfa00ae4) at snmpd.c:1062
all my DEBUGMSGTL is shown and it's everything OK. I see all "dispatch_ok"
messages.
What it could be?
------------------------------------------------------------------------------
Special Offer-- Download ArcSight Logger for FREE (a $49 USD value)!
Finally, a world-class log management solution at an even better price-free!
Download using promo code Free_Logger_4_Dev2Dev. Offer expires
February 28th, so secure your free ArcSight Logger TODAY!
http://p.sf.net/sfu/arcsight-sfd2d
_______________________________________________
Net-snmp-coders mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/net-snmp-coders