SNMP Subagent Programmer's Guide

Programming Tutorials
SNMP Subagent Programmer’s Guide119728 2-63
Indexed Trap Generator
Main Control Block
The main block processes SNMP requests and generates traps:
7. The timeval structure is used to set up the timeout parameter for the second
mgmt_poll() call.
8. The entries in the table are initialized. An entry is created for four cards and their
three corresponding ports.
9. The management environment is initialized.
10. The MIB, named tblTrap, is registered.
11. As in Dynamic Directory, which also uses next and locator functions to locate
entries, the table is registered.
12. The first mgmt_poll() call completes when the NonStop agent acknowledges the
registrations. This waited call is included so that an attempt to send a trap does not
occur before the NonStop agent is ready to process it.
13. After mgmt_poll() completes, an infinite loop is executed until contact with the
NonStop agent is lost.
14. The user is prompted for card and port numbers. The C library functions fprintf()
and scanf() are defined in include file stdioh.
15. If the user’s input specifies an existing card and port number, the values are stored in
the structure that holds trap varbinds, and mgmt_trap() is called.
16. The timeout parameter value for the call to mgmt_poll() is set to 0.
17. Because the timout parameter is 0, mgmt_poll() executes without waiting. Any
outstanding SNMP requests are processed.
18. If the mgmt_poll() call indicates the NonStop agent is not available, the infinite loop
terminates and mgmt_term_env() terminates SNMP management.
Locator Function
The function named locate_entry is called by the run-time library when an entry needs
to be located to satisfy a manager request or to generate a trap:
19. The function is declared. The function uses three parameters:
20. If the operation is a trap operation, op has the value LOCATE_TRAP. Entry indexes
are set using user input.
21. The 1-based index values are checked to make sure they are within range.
ctxt The context from the second mgmt_new_instance() call.
indices The addresses of index values.
op An indication of the type of operation being performed. Values for this
parameter are constants defined in locatorH.