SNMP Subagent Programmer's Guide

Programming Tutorials
SNMP Subagent Programmer’s Guide119728 2-61
Indexed Trap Generator
Logic
The source code for the main block and the locator and next functions is in the file
named tbltrapc.
Logic Flow
As Figure 2-6 illustrates, Indexed Trap Generator adds entries to the table before
initializing the management environment. After completing one mgmt_poll() call, the
subagent registers the MIB and the table, then prompts for an index value. If the value
matches that for an existing table entry, the subagent generates a trap; the run-time
library uses the locate function (locate_entry()) to find the entry to include in the trap
message. The user is again prompted for an index value after any pending SNMP
requests are processed.
Source Code
The source code for Indexed Trap Generator appears in Example 2-13. Numbers in the
example correspond to comments in the discussions located between here and the
example.
Global Declarations
The global declarations consist of several include and define statements as well as
definitions for structures that hold MIB object values. The user prompt is also defined:
1. The include file named locatorH defines the LOCATE_TRAP constant, used in the
locator function.
2. Two defines set up values used when the table is initialized.
3. The structure “mytable” is defined to allocate storage for the three MIB objects
included in the trap message.
4. The structure “master” contains four INTEGER fields. The first two fields,
current_card and current_port, are used during trap generation to figure out which
row to include in the trap. The next two fields, card_count and port_count, are for
values for MIB objects tblTrapCards and tblTrapPorts, respectively.
5. The user prompt is defined.
6. Include file stdioh is a C library file that supports I/O operations.