Platform SDK: Network Management

SnmpMgrGetTrap

The SnmpMgrGetTrap function returns outstanding trap data that the caller has not received if trap reception is enabled. This function is an element of the SNMP Management API.

BOOL SnmpMgrGetTrap(
  AsnObjectIdentifier *enterprise,   // generating enterprise
  AsnNetworkAddress *IPAddress,      // generating IP address
  AsnInteger *genericTrap,           // generic trap type
  AsnInteger *specificTrap,          // enterprise-specific type
  AsnTimeticks *timeStamp,           // time stamp
  SnmpVarBindList *variableBindings  // variable bindings
);

Parameters

enterprise
[out] Pointer to an object identifier to receive the enterprise that generated the SNMP trap.
IPAddress
[out] Pointer to a variable to receive the IP address of the enterprise that generated the SNMP trap.
genericTrap
[out] Pointer to a variable to receive an indicator of the generic trap. This parameter can be one of the following values.
Value Meaning
SNMP_GENERICTRAP_COLDSTART The agent is initializing protocol entities on the managed mode. It may alter objects in its view.
SNMP_GENERICTRAP_WARMSTART The agent is re-initializing itself but it will not alter objects in its view.
SNMP_GENERICTRAP_LINKDOWN An attached interface has changed from the up state to the down state. The first variable in the variable bindings list identifies the interface.
SNMP_GENERICTRAP_LINKUP An attached interface has changed from the down state to the up state. The first variable in the variable bindings list identifies the interface.
SNMP_GENERICTRAP_AUTHFAILURE An SNMP entity has sent an SNMP message, but it has falsely claimed to belong to a known community.
SNMP_GENERICTRAP_EGPNEIGHLOSS An EGP peer has changed to the down state. The first variable in the variable bindings list identifies the IP address of the EGP peer.
SNMP_GENERICTRAP_ENTERSPECIFIC An extraordinary event has occurred and it is identified in the specificTrap parameter with an enterprise-specific value.

specificTrap
[out] Pointer to a variable to receive an indication of the specific trap generated.
timeStamp
[out] Pointer to a variable to receive the time stamp.
variableBindings
[out] Pointer to an SnmpVarBindList structure to receive the variable bindings list.

Return Values

If the function returns a trap, the return value is nonzero.

You should call the SnmpMgrGetTrap function repeatedly until GetLastError returns zero. GetLastError may also return the following error codes.

Error Code Meaning
SNMP_MGMTAPI_TRAP_ERRORS Indicates errors were encountered; traps are not accessible.
SNMP_MGMTAPI_NOTRAPS Indicates no traps are available.
SNMP_MEM_ALLOC_ERROR Indicates a memory allocation error.

Remarks

The application must always call the SnmpMgrTrapListen function before calling the SnmpMgrGetTrap function. This is because the event handle pointed to by the phTrapAvailable parameter of the SnmpMgrTrapListen function enables the event-driven acquisition of SNMP traps. The SNMP Management API signals an application's event when the SNMP Trap Service delivers a trap.

The application can also poll the SnmpMgrGetTrap function for traps at regular intervals. In this case, the application should repeatedly call SnmpMgrGetTrap until the function returns zero.

Requirements

  Windows NT/2000: Requires Windows NT 3.1 or later.
  Windows 95/98: Unsupported.
  Header: Declared in Mgmtapi.h.
  Library: Use Mgmtapi.lib.

See Also

Simple Network Management Protocol (SNMP) Overview, SNMP Functions, SnmpMgrTrapListen, SnmpVarBindList