The demo_module_6 code is located by default in /usr/demo/sma_snmp/demo_module_6. The README_demo_module_6 file within that directory contains instructions that describe how to perform the following tasks:
Compile source files to generate a shared library object that implements a module
Set up the agent with an SNMPv3 user
Set up the agent to dynamically load the module
Test the module with snmp commands to show that the module is functioning as expected
The demo_module_6 example shows how to write a module that registers an object in two different contexts. The example also shows how to check for the contextName in a request and return a different value depending on the value of the contextName.
demo_module_6 registers one object, filesize, in two different contexts, fileX, and fileY. The OIDs are registered by 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. The get_filesize() function checks the contextName in the reginfo structure that is passed to the function by the SMA. 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.