The SnmpMgrTrapListen function registers the ability of an SNMP manager application to receive SNMP traps from the SNMP Trap Service. This function is an element of the SNMP Management API.
BOOL SnmpMgrTrapListen(
HANDLE *phTrapAvailable // event handle indicating a trap
// is available
);
If the function succeeds, the return value is nonzero.
If the function fails, the return value is zero. To get extended error information, call GetLastError. GetLastError may return any of the following error codes.
Error Code | Description |
---|---|
SNMP_MEM_ALLOC_ERROR | Indicates a memory allocation error. |
SNMP_MGMTAPI_TRAP_DUPINIT | Indicates that this function has already been called. |
SNMP_MGMTAPI_AGAIN | Indicates an error occurred; the application can attempt to call the function again. |
This function may return other system errors as well.
It is important to note that the SnmpMgrTrapListen function succeeds on Windows NTŪ versions 4.0 and later only if the SNMP trap service has been started.
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 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.
Windows NT: Requires version 3.1 or later.
Windows: Unsupported.
Windows CE: Unsupported.
Header: Declared in mgmtapi.h.
Import Library: Use mgmtapi.lib.
Simple Network Management Protocol (SNMP) Overview, SNMP Functions, SnmpMgrGetTrap