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.

177 lines
4.4 KiB

  1. /*++
  2. Copyright (c) 1999, Microsoft Corporation
  3. Module Name:
  4. sample\common.c
  5. Abstract:
  6. The file contains interactions with netsh and functions common across
  7. all contexts registered by this helper DLL (IPSAMPLEMON).
  8. --*/
  9. #include "precomp.h"
  10. #pragma hdrstop
  11. // statics
  12. static const GUID g_IpGuid = IPMONTR_GUID;
  13. // generate a new GUID for each helper (uuidgen)
  14. // aedb0ad8-1496-11d3-8005-08002bc35d9c
  15. static const GUID g_MyGuid =
  16. { 0xaedb0ad8, 0x1496, 0x11d3, {0x80, 0x5, 0x8, 0x0, 0x2b, 0xc3, 0x5d, 0x9c} };
  17. // globals...
  18. // variables
  19. HANDLE g_hModule; // set by DllMain
  20. DWORD
  21. WINAPI
  22. IpsamplemonStartHelper(
  23. IN CONST GUID *pguidParent,
  24. IN DWORD dwVersion
  25. )
  26. /*++
  27. Routine Description
  28. Registers contexts. Called by netsh to start helper.
  29. Arguments
  30. pguidParent GUID of parent helper (IPMON)
  31. dwVersion Version number of parent helper
  32. Return Value
  33. Error code returned from registering last context.
  34. --*/
  35. {
  36. DWORD dwErr;
  37. // the following types depend on the parent helper (IPMON)
  38. IP_CONTEXT_ATTRIBUTES icaMyAttributes;
  39. // register the SAMPLE context
  40. SampleInitialize(); // initialize sample's global information
  41. ZeroMemory(&icaMyAttributes, sizeof(icaMyAttributes));
  42. icaMyAttributes.guidHelper = g_MyGuid; // context's helper
  43. icaMyAttributes.dwVersion = g_ceSample.dwVersion;
  44. icaMyAttributes.pwszContext = g_ceSample.pwszName;
  45. icaMyAttributes.pfnDumpFn = g_ceSample.pfnDump;
  46. icaMyAttributes.ulNumTopCmds= g_ceSample.ulNumTopCmds;
  47. icaMyAttributes.pTopCmds = (CMD_ENTRY (*)[])
  48. g_ceSample.pTopCmds;
  49. icaMyAttributes.ulNumGroups = g_ceSample.ulNumGroupCmds;
  50. icaMyAttributes.pCmdGroups = (CMD_GROUP_ENTRY (*)[])
  51. g_ceSample.pGroupCmds;
  52. dwErr = RegisterContext(&icaMyAttributes);
  53. return dwErr;
  54. }
  55. DWORD
  56. WINAPI
  57. InitHelperDll(
  58. IN DWORD dwNetshVersion,
  59. OUT PNS_DLL_ATTRIBUTES pDllTable
  60. )
  61. /*++
  62. Routine Description
  63. Registers helper. Called by netsh.
  64. Arguments
  65. pUtilityTable netsh functions
  66. pDllTable DLL attributes
  67. Return Value
  68. Error code returned from registering helper.
  69. --*/
  70. {
  71. DWORD dwErr;
  72. NS_HELPER_ATTRIBUTES nhaMyAttributes;
  73. pDllTable->dwVersion = NETSH_VERSION_50;
  74. pDllTable->pfnStopFn = NULL;
  75. // Register helper. One option is to register a single helper that
  76. // registers a context for each protocol supported. Alternatively we
  77. // could register a different helper for each protocol, where each
  78. // helper registers a single context. There's only a difference if we
  79. // support sub-helpers. Since a sub-helper registers with a parent
  80. // helper, not a parent context, it is valid in every context its
  81. // parent helper registers.
  82. ZeroMemory(&nhaMyAttributes, sizeof(NS_HELPER_ATTRIBUTES));
  83. // attributes of this helper
  84. // version
  85. nhaMyAttributes.guidHelper = g_MyGuid;
  86. nhaMyAttributes.dwVersion = SAMPLE_HELPER_VERSION;
  87. // start function
  88. nhaMyAttributes.pfnStart = IpsamplemonStartHelper;
  89. // define stop function if need to perform cleanup before unload
  90. nhaMyAttributes.pfnStop = NULL;
  91. dwErr = RegisterHelper(&g_IpGuid, // GUID of parent helper (IPMON)
  92. &nhaMyAttributes);
  93. return dwErr;
  94. }
  95. BOOL
  96. WINAPI
  97. DllMain(
  98. IN HINSTANCE hInstance,
  99. IN DWORD dwReason,
  100. IN PVOID pvImpLoad
  101. )
  102. /*++
  103. Routine Description
  104. DLL entry and exit point handler.
  105. Arguments
  106. hInstance Instance handle of DLL
  107. dwReason Reason function called
  108. pvImpLoad Implicitly loaded DLL?
  109. Return Value
  110. TRUE Successfully loaded DLL
  111. --*/
  112. {
  113. switch(dwReason)
  114. {
  115. case DLL_PROCESS_ATTACH:
  116. g_hModule = hInstance;
  117. DisableThreadLibraryCalls(hInstance);
  118. break;
  119. case DLL_PROCESS_DETACH:
  120. break;
  121. default:
  122. break;
  123. }
  124. return TRUE;
  125. }