It does not work by putting & in front of datapointer. It is already a void
pointer. Trying with & in front of datapointer outputs wrong. For scalar
testCounter it gives 1780230716 instead of 1234.
I have modified my code which now works. This version I have registered all 3
scalars.
#include <net-snmp/net-snmp-config.h>
#include <net-snmp/net-snmp-includes.h>
#include <net-snmp/agent/net-snmp-agent-includes.h>
#include "test.h"
const oid test_oid[] = { 1,3,6,1,4,1,40463,1 };
const oid testInfo_oid[] = { 1,3,6,1,4,1,40463,1,1 };
const oid testPlacementCountry_oid[] = { 1,3,6,1,4,1,40463,1,2 };
const oid testCounter_oid[] = { 1,3,6,1,4,1,40463,1,3 };
/** Initializes the test module */
void init_test(void) {
DEBUGMSGTL(("test", "Initializing\n"));
netsnmp_register_scalar(
netsnmp_create_handler_registration("testInfo",
handle_test,
testInfo_oid,
OID_LENGTH(testInfo_oid),
HANDLER_CAN_RONLY
));
netsnmp_register_scalar(
netsnmp_create_handler_registration("testPlacementCountry",
handle_test,
testPlacementCountry_oid,
OID_LENGTH(testPlacementCountry_oid),
HANDLER_CAN_RONLY
));
netsnmp_register_scalar(
netsnmp_create_handler_registration("testCounter",
handle_test,
testCounter_oid,
OID_LENGTH(testCounter_oid),
HANDLER_CAN_RONLY
));
}
int handle_test(netsnmp_mib_handler *handler,
netsnmp_handler_registration *reginfo,
netsnmp_agent_request_info *reqinfo,
netsnmp_request_info *requests) {
void* datapointer;
char buffer[200];
int dataint;
int length = 0;
u_char type;
const oid* request_rootoid = (*reginfo).rootoid;
if (netsnmp_oid_equals(request_ rootoid , 9, testInfo_oid, 9) == 0) { //Why not
OID_LENGTH(testInfo_oid)
strcpy(buffer, "test");
datapointer = buffer;
length = strlen(buffer);
type = ASN_OCTET_STR;
} else if (netsnmp_oid_equals(request_ rootoid , 9, testPlacementCountry_oid,
9) == 0) {
strcpy(buffer, "test2");
datapointer = buffer;
length = strlen(buffer);
type = ASN_OCTET_STR;
} else if (netsnmp_oid_equals(request_ rootoid , 9, testCounter_oid, 9) == 0) {
dataint = 1234;
datapointer = &dataint;
length = sizeof(dataint);
type = ASN_INTEGER;
} else {
strcpy(buffer, "UNKNOWN_OID");
datapointer = buffer;
length = strlen(buffer);
type = ASN_OCTET_STR;
}
switch(reqinfo->mode) {
case MODE_GET:
snmp_set_var_typed_value(requests->requestvb,
type,
datapointer,
length);
break;
default:
/* we should never get here, so this is a really bad error */
snmp_log(LOG_ERR, "unknown mode (%d) in handle_test\n", reqinfo->mode );
return SNMP_ERR_GENERR;
}
return SNMP_ERR_NOERROR;
}
----- Original Message -----
Fra: "Jatin Bodarya" <[email protected]>
Til: "Sverre Moe" <[email protected]>
Kopi: [email protected]
Sendt: 5. september 2012 11:12:01
Emne: RE: A primary OID handler for a whole subtree
Could anyone point me in the right direction concerning my MIB module? Do I
need to implement it in a different way and/or am I missing something?
It does not seem like request for any child elements of test are directed to
its handler. Though if I register all 3 scalars with same handler method (put
aside that my OID comparison does not work). Is there any other way to do this
or do I really need to register all scalars this way?
...................................................................................................
Wrong:
snmp_set_var_typed_value(requests->requestvb,
ASN_OCTET_STR,
datapointer,
sizeof(datapointer));
right
snmp_set_var_typed_value(requests->requestvb,
ASN_OCTET_STR,
&datapointer,
sizeof(datapointer));
CONFIDENTIALITY This e-mail and any attachment contain KONGSBERG information
which may be proprietary, confidential or subject to export regulations, and is
only meant for the intended recipient(s). Any disclosure, copying, distribution
or use is prohibited, if not otherwise explicitly agreed with KONGSBERG. If
received in error, please delete it immediately from your system and notify the
sender properly.
CONFIDENTIALITY
This e-mail and any attachment contain KONGSBERG information which may be
proprietary, confidential or subject to export regulations, and is only meant
for the intended recipient(s). Any disclosure, copying, distribution or use is
prohibited, if not otherwise explicitly agreed with KONGSBERG. If received in
error, please delete it immediately from your system and notify the sender
properly.
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Net-snmp-coders mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/net-snmp-coders