SNMP Manager Programmer's Guide

Programming Examples
SNMP Manager Programmer’s Guide134249
2-96
SNMPTRAP
Example 2-13 illustrates the contents of snmptrpc, the source code file for SNMPTRAP.
Numbers in the example correspond to numbers in the observations made between here
and the example.
1. The default components of the enterprise OID are initialized.
2. The Manager Services define SNMP_TRAP_PORT is used to initialize the
destination port value to 162.
3. The default value of the manager’s host is initialized.
4. Invocation line arguments are obtained.
5. OIDs are extracted just as in SNMPSET.
6. A UDP socket is obtained just as in SNMPGT.
7. If an enterprise OID was specified at invocation, its validity is checked. If none was
specified, the default value is assigned.
8. The manager’s host identifier is obtained.
9. The generic trap integer is assigned to the variable named generic. If the invocation
line specified this value as a string, the common utility str_to_trap() converts it to
the appropriate integer.
10. The SNMP_Create_Trap() function initializes a trap packet.
11. The OID of each variable binding is initialized, just as in SNMPSET.
12. Each variable binding is bound to the trap packet, just as in SNMPSET.
13. The trap packet is encoded, printed, and sent.