

<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>https://net-snmp.sourceforge.io/wiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Aw</id>
		<title>Net-SNMP Wiki - User contributions [en]</title>
		<link rel="self" type="application/atom+xml" href="https://net-snmp.sourceforge.io/wiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Aw"/>
		<link rel="alternate" type="text/html" href="https://net-snmp.sourceforge.io/wiki/index.php/Special:Contributions/Aw"/>
		<updated>2026-05-01T17:55:21Z</updated>
		<subtitle>User contributions</subtitle>
		<generator>MediaWiki 1.26.3</generator>

	<entry>
		<id>https://net-snmp.sourceforge.io/wiki/index.php?title=TUT:Writing_a_Dynamically_Loadable_Object&amp;diff=2519</id>
		<title>TUT:Writing a Dynamically Loadable Object</title>
		<link rel="alternate" type="text/html" href="https://net-snmp.sourceforge.io/wiki/index.php?title=TUT:Writing_a_Dynamically_Loadable_Object&amp;diff=2519"/>
				<updated>2007-04-05T13:22:08Z</updated>
		
		<summary type="html">&lt;p&gt;Aw: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;First off, you need to write a mib module first before you can do this part of the tutorial. We assume you have read and completed the [[TUT:Writing_a_MIB_Module | mib module portion]] of the toolkit tutorial. This part of the tutorial shows how to install a dynamic module into the agent, assuming you already have written a mib-module which we&amp;#039;ll then compile into a dynamic module. For example purposes, we&amp;#039;ll refer to some example MIB objects and code: the [http://www.net-snmp.org/tutorial/tutorial-5/toolkit/mib_module/NET-SNMP-TUTORIAL-MIB.txt NET-SNMP-TUTORIAL-MIB] MIB, and the [http://www.net-snmp.org/tutorial/tutorial-5/toolkit/demon/nstAgentSubagentObject.c example mib module] and it&amp;#039;s [http://www.net-snmp.org/tutorial/tutorial-5/toolkit/demon/nstAgentSubagentObject.h header file]. &lt;br /&gt;
&lt;br /&gt;
Note: For this to work, you must have compiled the net-snmp package with dynamicly loadable module support turned on, as well as built it with --enable-shared turned on. (It&amp;#039;s on by default, if your system supports it). You can check for support in your agent but looking at the output of the &amp;quot;snmpd -H&amp;quot; command for the &amp;quot;dlmod&amp;quot; token. If its listed, the compiled agent supports it. &lt;br /&gt;
&lt;br /&gt;
Note: All command line options below assume you have an appropriately setup ~/.snmp/snmp.conf file that allows you to not have to specify a snmp version number, community name, username, or whatever else in order to talk to your agent. The agent, of course, must have a matching /usr/local/share/snmp/snmpd.conf file (or equivalent). &lt;br /&gt;
&lt;br /&gt;
Here are the files discussed in this example so you can download them: &lt;br /&gt;
&lt;br /&gt;
{{TUT:File-Table-Top-and-basics}}&lt;br /&gt;
|-&lt;br /&gt;
| [http://www.net-snmp.org/tutorial/tutorial-5/toolkit/dlmod/nstAgentPluginObject.h nstAgentPluginObject.h] || The mib module&amp;#039;s header file&lt;br /&gt;
|-&lt;br /&gt;
| [http://www.net-snmp.org/tutorial/tutorial-5/toolkit/dlmod/nstAgentPluginObject.c nstAgentPluginObject.c] || The mib module&amp;#039;s C source code&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The shared object loader calls the &amp;quot;init_nstAgentPluginObject()&amp;quot; function in the above code when it gets loaded, and calls the &amp;quot;deinit_nstAgentPluginObject()&amp;quot; when (and if) the module is unloaded. These function names to use are built by adding the shared object&amp;#039;s module name (UCD-DLMOD-MIB::dlmodName) to the `init_&amp;#039; and `deinit_&amp;#039; prefixes. &lt;br /&gt;
&lt;br /&gt;
=== Steps to build the shared object ===&lt;br /&gt;
&lt;br /&gt;
# First off we must get the [http://www.net-snmp.org/tutorial/tutorial-5/toolkit/demoapp/Makefile Makefile] file, the [http://www.net-snmp.org/tutorial/tutorial-5/toolkit/dlmod/nstAgentPluginObject.h nstAgentPluginObject.h] file, and the [http://www.net-snmp.org/tutorial/tutorial-5/toolkit/dlmod/nstAgentPluginObject.c nstAgentPluginObject.c] file. &lt;br /&gt;
# &amp;#039;&amp;#039;&amp;#039;make nstAgentPluginObject.so&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
=== Steps to test the shared object via runtime MIB configuration ===&lt;br /&gt;
&lt;br /&gt;
# Start the snmpd and watch the dlmod and nstAgentPluginObject modules interact using the debugging flag (this assumes you already have access control set up properly for your agent): &lt;br /&gt;
#:% &amp;#039;&amp;#039;&amp;#039;snmpd -f -L -DnstAgentPluginObject,dlmod&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
# In another window, test to make sure that the agent doesn&amp;#039;t currently support the nstAgentPluginObject (if you get different results running this command you need to recompile the net-snmp agent without the nstAgentPluginObject mib module compiled in directly): &lt;br /&gt;
#:% &amp;#039;&amp;#039;&amp;#039;snmpget localhost NET-SNMP-TUTORIAL-MIB::nstAgentPluginObject.0&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
#:nstAgentPluginObject.0 = No Such Object available on this agent at this OID          &lt;br /&gt;
# Then, run snmpset to create a new row in the dlmod table: &lt;br /&gt;
#:% &amp;#039;&amp;#039;&amp;#039;snmpset localhost UCD-DLMOD-MIB::dlmodStatus.1 i create&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
#:dlmodStatus.1 = create(6)&lt;br /&gt;
# See that the row was created: &lt;br /&gt;
#:% &amp;#039;&amp;#039;&amp;#039;snmptable localhost UCD-DLMOD-MIB::dlmodTable  &amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
#:SNMP table: dlmodTable&lt;br /&gt;
#:&lt;br /&gt;
#:dlmodName dlmodPath dlmodError dlmodStatus&lt;br /&gt;
#:                                   unloaded&lt;br /&gt;
#Then set the properties of the row up to point to our new object and to give it a name: &lt;br /&gt;
#:% &amp;#039;&amp;#039;&amp;#039;snmpset localhost UCD-DLMOD-MIB::dlmodName.1 s &amp;quot;nstAgentPluginObject&amp;quot; UCD-DLMOD-MIB::dlmodPath.1 s &amp;quot;/path/to/nstAgentPluginObject.so&amp;quot;  &amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
#:dlmodName.1 = &amp;quot;nstAgentPluginObject&amp;quot; &lt;br /&gt;
#:dlmodName.1 = &amp;quot;/path/to/nstAgentPluginObject.so&amp;quot;&lt;br /&gt;
#:&lt;br /&gt;
#:% &amp;#039;&amp;#039;&amp;#039;snmptable localhost UCD-DLMOD-MIB::dlmodTable  &amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
#: SNMP table: dlmodTable&lt;br /&gt;
#: &lt;br /&gt;
#:    dlmodName dlmodPath                 dlmodError   dlmodStatus&lt;br /&gt;
#: nstAgentPluginObject /path/to/nstAgentPluginObject.so                  unloaded&lt;br /&gt;
#Finally, load the shared object into the running agent: &lt;br /&gt;
#:% &amp;#039;&amp;#039;&amp;#039;snmpset localhost UCD-DLMOD-MIB::dlmodStatus.1 i load  &amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
#:dlmodStatus.1 = loaded(1)&lt;br /&gt;
#:&lt;br /&gt;
#:% snmptable localhost UCD-DLMOD-MIB::dlmodTable  &lt;br /&gt;
#:SNMP table: dlmodTable&lt;br /&gt;
#: &lt;br /&gt;
#:    dlmodName                      dlmodPath dlmodError dlmodStatus&lt;br /&gt;
#: nstAgentPluginObject /path/to/nstAgentPluginObject.so                 loaded&lt;br /&gt;
#If everything above was done correctly, then the following command should work and will access the shared object&amp;#039;s data: &lt;br /&gt;
#:% &amp;#039;&amp;#039;&amp;#039;snmpget localhost NET-SNMP-TUTORIAL-MIB::nstAgentPluginObject.0  &amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
#: nstAgentPluginObject.0 = INTEGER: 3&lt;br /&gt;
&lt;br /&gt;
=== Loading via the snmpd.conf file ===&lt;br /&gt;
You can also load shared objects using the &amp;quot;dlmod&amp;quot; token in the snmpd.conf file by putting a line like this in your snmpd.conf file: &lt;br /&gt;
      dlmod nstAgentPluginObject /path/to/nstAgentPluginObject.so&lt;br /&gt;
    &lt;br /&gt;
The first argument specifies the shared object&amp;#039;s module name (UCD-DLMOD-MIB::dlmodName) and second argument specifies the full pathname of the shared object file. &lt;br /&gt;
&lt;br /&gt;
{{TUT:LIST}}&lt;/div&gt;</summary>
		<author><name>Aw</name></author>	</entry>

	</feed>