Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

227 lines
6.7 KiB

  1. /*++
  2. Copyright (c) 1992-1996 Microsoft Corporation
  3. Module Name:
  4. snmptst4.c
  5. Abstract:
  6. Driver routine to invoke an test the Extension Agent DLL.
  7. Environment:
  8. User Mode - Win32
  9. Revision History:
  10. 10-May-1996 DonRyan
  11. Removed banner from Technology Dynamics, Inc.
  12. --*/
  13. //--------------------------- WINDOWS DEPENDENCIES --------------------------
  14. #include <windows.h>
  15. //--------------------------- STANDARD DEPENDENCIES -- #include<xxxxx.h> ----
  16. #include <stdio.h>
  17. //--------------------------- MODULE DEPENDENCIES -- #include"xxxxx.h" ------
  18. #include <snmp.h>
  19. #include <snmputil.h>
  20. #include <authapi.h>
  21. //--------------------------- SELF-DEPENDENCY -- ONE #include"module.h" -----
  22. //--------------------------- PUBLIC VARIABLES --(same as in module.h file)--
  23. //--------------------------- PRIVATE CONSTANTS -----------------------------
  24. //--------------------------- PRIVATE STRUCTS -------------------------------
  25. //--------------------------- PRIVATE VARIABLES -----------------------------
  26. //--------------------------- PRIVATE PROTOTYPES ----------------------------
  27. //--------------------------- PRIVATE PROCEDURES ----------------------------
  28. //--------------------------- PUBLIC PROCEDURES -----------------------------
  29. typedef AsnObjectIdentifier View; // temp until view is defined...
  30. int __cdecl main(
  31. IN int argumentCount,
  32. IN char *argumentVector[])
  33. {
  34. HANDLE hExtension;
  35. FARPROC initAddr;
  36. FARPROC queryAddr;
  37. FARPROC trapAddr;
  38. DWORD timeZeroReference;
  39. HANDLE hPollForTrapEvent;
  40. View supportedView;
  41. INT i;
  42. INT numQueries = 10;
  43. UINT typ;
  44. extern INT nLogLevel;
  45. extern INT nLogType;
  46. nLogLevel = 15;
  47. nLogType = 1;
  48. // avoid compiler warning...
  49. UNREFERENCED_PARAMETER(argumentCount);
  50. UNREFERENCED_PARAMETER(argumentVector);
  51. timeZeroReference = GetCurrentTime()/10;
  52. // load the extension agent dll and resolve the entry points...
  53. if (GetModuleHandle("lmmib2.dll") == NULL)
  54. {
  55. if ((hExtension = LoadLibrary("lmmib2.dll")) == NULL)
  56. {
  57. dbgprintf(1, "error on LoadLibrary %d\n", GetLastError());
  58. }
  59. else if ((initAddr = GetProcAddress(hExtension,
  60. "SnmpExtensionInit")) == NULL)
  61. {
  62. dbgprintf(1, "error on GetProcAddress %d\n", GetLastError());
  63. }
  64. else if ((queryAddr = GetProcAddress(hExtension,
  65. "SnmpExtensionQuery")) == NULL)
  66. {
  67. dbgprintf(1, "error on GetProcAddress %d\n",
  68. GetLastError());
  69. }
  70. else if ((trapAddr = GetProcAddress(hExtension,
  71. "SnmpExtensionTrap")) == NULL)
  72. {
  73. dbgprintf(1, "error on GetProcAddress %d\n",
  74. GetLastError());
  75. }
  76. else
  77. {
  78. // initialize the extension agent via its init entry point...
  79. (*initAddr)(
  80. timeZeroReference,
  81. &hPollForTrapEvent,
  82. &supportedView);
  83. }
  84. } // end if (Already loaded)
  85. // create a trap thread to respond to traps from the extension agent...
  86. //rather than oomplicate this test routine, will poll for these events
  87. //below. normally this would be done by another thread in the extendible
  88. //agent.
  89. // loop here doing repetitive extension agent get queries...
  90. // poll for potential traps each iteration (see note above)...
  91. //block...
  92. {
  93. RFC1157VarBindList varBinds;
  94. AsnInteger errorStatus;
  95. AsnInteger errorIndex;
  96. UINT OID_Prefix[] = { 1, 3, 6, 1, 4, 1, 77 };
  97. AsnObjectIdentifier MIB_OidPrefix = { 7, OID_Prefix };
  98. errorStatus = 0;
  99. errorIndex = 0;
  100. varBinds.list = (RFC1157VarBind *)SnmpUtilMemAlloc( sizeof(RFC1157VarBind) );
  101. varBinds.len = 1;
  102. varBinds.list[0].name.idLength = MIB_OidPrefix.idLength;
  103. varBinds.list[0].name.ids = (UINT *)SnmpUtilMemAlloc( sizeof(UINT) *
  104. varBinds.list[0].name.idLength );
  105. memcpy( varBinds.list[0].name.ids, MIB_OidPrefix.ids,
  106. sizeof(UINT)*varBinds.list[0].name.idLength );
  107. varBinds.list[0].value.asnType = ASN_NULL;
  108. do
  109. {
  110. printf( "GET-NEXT of: " ); SnmpUtilPrintOid( &varBinds.list[0].name );
  111. printf( " " );
  112. (*queryAddr)( (AsnInteger)ASN_RFC1157_GETNEXTREQUEST,
  113. &varBinds,
  114. &errorStatus,
  115. &errorIndex
  116. );
  117. printf( "\n is " ); SnmpUtilPrintOid( &varBinds.list[0].name );
  118. if ( errorStatus )
  119. {
  120. printf( "\nErrorstatus: %lu\n\n", errorStatus );
  121. }
  122. else
  123. {
  124. printf( "\n = " ); SnmpUtilPrintAsnAny( &varBinds.list[0].value );
  125. }
  126. putchar( '\n' );
  127. }
  128. while ( varBinds.list[0].name.ids[7-1] != 78 );
  129. // Free the memory
  130. SnmpUtilVarBindListFree( &varBinds );
  131. #if 0
  132. // query potential traps (see notes above)
  133. if (hPollForTrapEvent != NULL)
  134. {
  135. DWORD dwResult;
  136. if ((dwResult = WaitForSingleObject(hPollForTrapEvent,
  137. 0/*immediate*/)) == 0xffffffff)
  138. {
  139. dbgprintf(1, "error on WaitForSingleObject %d\n",
  140. GetLastError());
  141. }
  142. else if (dwResult == 0 /*signaled*/)
  143. {
  144. AsnObjectIdentifier enterprise;
  145. AsnInteger genericTrap;
  146. AsnInteger specificTrap;
  147. AsnTimeticks timeStamp;
  148. RFC1157VarBindList variableBindings;
  149. while(
  150. (*trapAddr)(&enterprise, &genericTrap, &specificTrap,
  151. &timeStamp, &variableBindings)
  152. )
  153. {
  154. printf("trap: gen=%d spec=%d time=%d\n",
  155. genericTrap, specificTrap, timeStamp);
  156. //also print data
  157. } // end while ()
  158. } // end if (trap ready)
  159. } // end if (handling traps)
  160. #endif
  161. } // block
  162. return 0;
  163. } // end main()
  164. //-------------------------------- END --------------------------------------