Article ID: 189131
Article Last Modified on 7/11/2005
BOOL WINAPI SnmpExtensionInit(
IN DWORD dwTimeZeroReference,
OUT HANDLE *hPollForTrapEvent,
OUT AsnObjectIdentifier *supportedView)
{
SECURITY_ATTRIBUTES sa;
SECURITY_DESCRIPTOR sd;
sa.nLength = sizeof(SECURITY_ATTRIBUTES);
sa.bInheritHandle = TRUE;
sa.lpSecurityDescriptor = &sd;
if(!InitializeSecurityDescriptor(&sd,
SECURITY_DESCRIPTOR_REVISION))
return FALSE; // Handle errors.
// Add a NULL DACL to the security descriptor.
if(!SetSecurityDescriptorDacl(&sd, TRUE, (PACL)NULL, FALSE))
return FALSE; // Handle errors.
// Record the time reference provided by the Extendible Agent.
dwTimeZero = dwTimeZeroReference;
// Create a named Event that will be used to communicate the
// occurrence of traps to the Extendible Agent. The Extension
// Agent will assert this Event when a trap has occurred. This
// is explained later.
// A named event is created with a null DACL such that other
// processes are able to signal this Event as this Extension
// agent does.
if ((*hPollForTrapEvent =
CreateEvent(&sa, FALSE, FALSE, TEXT("_MyTrapEvent"))) == NULL)
{
// Indicate error?, be sure that NULL is returned to
// Extendible Agent.
}
// Indicate the MIB view supported by this Extension Agent, an
// object identifier representing the sub root of the MIB that
// is supported.
*supportedView = MIB_OidPrefix; // NOTE! structure copy
// Record the trap Event. This example Extension Agent
// simulates traps by generating a trap after every given number
// of processed requests.
hSimulateTrap = *hPollForTrapEvent;
// Indicate that Extension Agent initialization was successful.
return TRUE;
} // end SnmpExtensionInit().
#include <windows.h>
#include <stdio.h>
void main(void)
{
HANDLE hTrapEvent;
char c;
hTrapEvent = OpenEvent(EVENT_MODIFY_STATE, FALSE,
TEXT("_MyTrapEvent"));
if (hTrapEvent == NULL)
{
printf(TEXT("Can't open the event _MyTrapEvent\n"));
return;
}
printf(TEXT("Hit t [enter] to trigger the sending of trap: \n"));
while (1)
{
scanf("%c", &c);
if (c == 't' || c == 'T')
SetEvent(hTrapEvent);
}
}
106387 How To Share Objects with a Service
128729 How To Add an SNMP Extension Agent to the NT Registry
Additional query words: SNMP trap event
Keywords: kbapi kbhowto kbnetwork kbsnmp KB189131