Putting lord of the ring aside, I need to create an SNMP agentX with only one 
handler for all OIDs. I need to implement it this way to dynamically handle an 
MIB definition. 


I used the mib2c command to create a mib module from my example MIB definition 
wich contain 2 scalars. I used this to get a starting point for the code (all 
my OIDs are scalar, and the total number of OIDs will be in the number of 
thousands). The agent I wish to create will not have access to the MIB 
definition before it starts up and makes contact with the device it is going to 
manage (this because the MIB definition can change and vary from system to 
system). 



This is my starting point of the generated code. I must parse the incoming OID 
request my self and then extract the its value from the device which will then 
be forwarded to the manager(requester). Can anyone point me in the right 
direction, some tutorials/examples about this would be great. 


/* 
* Note: this file originally auto-generated by mib2c using 
* $ 
*/ 

#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" 

/** Initializes the test module */ 
void init_test(void) { 
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 }; 

DEBUGMSGTL(("test", "Initializing\n")); 

netsnmp_register_scalar( 
netsnmp_create_handler_registration("test", handle_test, test_oid, 
OID_LENGTH(test_oid), HANDLER_CAN_RONLY )); 
} 

int handle_test(netsnmp_mib_handler *handler, netsnmp_handler_registration 
*reginfo, netsnmp_agent_request_info *reqinfo, netsnmp_request_info *requests) 
{ 
/* We are never called for a GETNEXT if it's registered as a 
"instance", as it's "magically" handled for us. */ 

/* 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. */ 



const OID request_oid = ... 
if (request_oid == testInfo_oid) { 
*thisWillBeMyPointerToTheData = "test"; 
} else if (request_oid == testPlacementCountry_oid) { 
*thisWillBeMyPointerToTheData = "test2"; 
} 

switch(reqinfo->mode) { 
case MODE_GET: 
snmp_set_var_typed_value(requests->requestvb, ASN_OCTET_STR, 
thisWillBeMyPointerToTheData, sizeof(thisWillBeMyPointerToTheData)); 
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; 
} 


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-users mailing list
Net-snmp-users@lists.sourceforge.net
Please see the following page to unsubscribe or change other options:
https://lists.sourceforge.net/lists/listinfo/net-snmp-users

Reply via email to