NetSh.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  1. /*++
  2. Copyright (c) Microsoft Corporation. All rights reserved.
  3. Module Name:
  4. netsh.h
  5. Abstract:
  6. This file contains definitions which are needed by all NetSh helper DLLs.
  7. --*/
  8. #ifndef _NETSH_H_
  9. #define _NETSH_H_
  10. #if _MSC_VER > 1000
  11. #pragma once
  12. #endif
  13. #pragma warning(push)
  14. #pragma warning(disable:4201) // nameless struct/union
  15. #ifdef __cplusplus
  16. extern "C" {
  17. #endif
  18. //
  19. // Error codes
  20. //
  21. #define NETSH_ERROR_BASE 15000
  22. #define ERROR_NO_ENTRIES (NETSH_ERROR_BASE + 0)
  23. #define ERROR_INVALID_SYNTAX (NETSH_ERROR_BASE + 1)
  24. #define ERROR_PROTOCOL_NOT_IN_TRANSPORT (NETSH_ERROR_BASE + 2)
  25. #define ERROR_NO_CHANGE (NETSH_ERROR_BASE + 3)
  26. #define ERROR_CMD_NOT_FOUND (NETSH_ERROR_BASE + 4)
  27. #define ERROR_ENTRY_PT_NOT_FOUND (NETSH_ERROR_BASE + 5)
  28. #define ERROR_DLL_LOAD_FAILED (NETSH_ERROR_BASE + 6)
  29. #define ERROR_INIT_DISPLAY (NETSH_ERROR_BASE + 7)
  30. #define ERROR_TAG_ALREADY_PRESENT (NETSH_ERROR_BASE + 8)
  31. #define ERROR_INVALID_OPTION_TAG (NETSH_ERROR_BASE + 9)
  32. #define ERROR_NO_TAG (NETSH_ERROR_BASE + 10)
  33. #define ERROR_MISSING_OPTION (NETSH_ERROR_BASE + 11)
  34. #define ERROR_TRANSPORT_NOT_PRESENT (NETSH_ERROR_BASE + 12)
  35. #define ERROR_SHOW_USAGE (NETSH_ERROR_BASE + 13)
  36. #define ERROR_INVALID_OPTION_VALUE (NETSH_ERROR_BASE + 14)
  37. #define ERROR_OKAY (NETSH_ERROR_BASE + 15)
  38. #define ERROR_CONTINUE_IN_PARENT_CONTEXT (NETSH_ERROR_BASE + 16)
  39. #define ERROR_SUPPRESS_OUTPUT (NETSH_ERROR_BASE + 17)
  40. #define ERROR_HELPER_ALREADY_REGISTERED (NETSH_ERROR_BASE + 18)
  41. #define ERROR_CONTEXT_ALREADY_REGISTERED (NETSH_ERROR_BASE + 19)
  42. #define NETSH_ERROR_END ERROR_CONTEXT_ALREADY_REGISTERED
  43. // Flags
  44. enum NS_CMD_FLAGS
  45. {
  46. CMD_FLAG_PRIVATE = 0x01, // not valid in sub-contexts
  47. CMD_FLAG_INTERACTIVE = 0x02, // not valid from outside netsh
  48. CMD_FLAG_LOCAL = 0x08, // not valid from a remote machine
  49. CMD_FLAG_ONLINE = 0x10, // not valid in offline/non-commit mode
  50. CMD_FLAG_HIDDEN = 0x20, // hide from help but allow execution
  51. CMD_FLAG_LIMIT_MASK = 0xffff,
  52. CMD_FLAG_PRIORITY = 0x80000000 // ulPriority field is used*/
  53. };
  54. typedef enum _NS_REQS
  55. {
  56. NS_REQ_ZERO = 0,
  57. NS_REQ_PRESENT = 1,
  58. NS_REQ_ALLOW_MULTIPLE = 2,
  59. NS_REQ_ONE_OR_MORE = 3
  60. } NS_REQS;
  61. enum NS_EVENTS
  62. {
  63. NS_EVENT_LOOP = 0x00010000,
  64. NS_EVENT_LAST_N = 0x00000001,
  65. NS_EVENT_LAST_SECS = 0x00000002,
  66. NS_EVENT_FROM_N = 0x00000004,
  67. NS_EVENT_FROM_START = 0x00000008
  68. };
  69. enum NS_MODE_CHANGE
  70. {
  71. NETSH_COMMIT = 0,
  72. NETSH_UNCOMMIT = 1,
  73. NETSH_FLUSH = 2,
  74. NETSH_COMMIT_STATE = 3,
  75. NETSH_SAVE = 4
  76. };
  77. #define NS_GET_EVENT_IDS_FN_NAME "GetEventIds"
  78. #define MAX_NAME_LEN MAX_DLL_NAME
  79. #define NETSH_VERSION_50 0x0005000
  80. #define NETSH_ARG_DELIMITER L"="
  81. #define NETSH_CMD_DELIMITER L" "
  82. #define NETSH_MAX_TOKEN_LENGTH 64
  83. #define NETSH_MAX_CMD_TOKEN_LENGTH 128
  84. #define NETSH_ROOT_GUID { 0, 0, 0, { 0, 0, 0, 0, 0, 0, 0, 0 } }
  85. #define DEFAULT_CONTEXT_PRIORITY 100
  86. typedef struct _TOKEN_VALUE
  87. {
  88. LPCWSTR pwszToken; // literal token string
  89. DWORD dwValue; // ID of info string
  90. } TOKEN_VALUE, *PTOKEN_VALUE;
  91. // Macros
  92. #define CREATE_CMD_ENTRY(t,f) {CMD_##t, f, HLP_##t, HLP_##t##_EX, CMD_FLAG_PRIVATE, NULL}
  93. #define CREATE_CMD_ENTRY_EX(t,f,i) {CMD_##t, f, HLP_##t, HLP_##t##_EX, i, NULL}
  94. #define CREATE_CMD_ENTRY_EX_VER(t,f,i,v) {CMD_##t, f, HLP_##t, HLP_##t##_EX, i, v}
  95. #define CREATE_CMD_GROUP_ENTRY(t,s) {CMD_##t, HLP_##t, sizeof(s)/sizeof(CMD_ENTRY), 0, s, NULL }
  96. #define CREATE_CMD_GROUP_ENTRY_EX(t,s,i) {CMD_##t, HLP_##t, sizeof(s)/sizeof(CMD_ENTRY), i, s, NULL }
  97. #define CREATE_CMD_GROUP_ENTRY_EX_VER(t,s,i,v) {CMD_##t, HLP_##t, sizeof(s)/sizeof(CMD_ENTRY), i, s, v }
  98. #define NUM_TOKENS_IN_TABLE(TokenArray) sizeof(TokenArray)/sizeof(TOKEN_VALUE)
  99. #define NUM_TAGS_IN_TABLE(TagsArray) sizeof(TagsArray)/sizeof(TAG_TYPE)
  100. #define GET_RESOURCE_STRING_FN_NAME "GetResourceString"
  101. // Callbacks
  102. typedef
  103. DWORD
  104. (WINAPI GET_RESOURCE_STRING_FN)(
  105. IN DWORD dwMsgID, // resource identifier
  106. OUT LPWSTR lpBuffer, // resource buffer
  107. IN DWORD nBufferMax // size of buffer in characters
  108. );
  109. typedef GET_RESOURCE_STRING_FN *PGET_RESOURCE_STRING_FN;
  110. typedef
  111. DWORD
  112. (WINAPI NS_CONTEXT_COMMIT_FN)(
  113. IN DWORD dwAction
  114. );
  115. typedef NS_CONTEXT_COMMIT_FN *PNS_CONTEXT_COMMIT_FN;
  116. typedef
  117. DWORD
  118. (WINAPI NS_CONTEXT_CONNECT_FN)(
  119. IN LPCWSTR pwszMachine
  120. );
  121. typedef NS_CONTEXT_CONNECT_FN *PNS_CONTEXT_CONNECT_FN;
  122. typedef struct _NS_CONTEXT_ATTRIBUTES NS_CONTEXT_ATTRIBUTES;
  123. typedef
  124. DWORD
  125. (WINAPI NS_CONTEXT_DUMP_FN)(
  126. IN LPCWSTR pwszRouter,
  127. IN OUT LPWSTR *ppwcArguments,
  128. IN DWORD dwArgCount,
  129. IN LPCVOID pvData
  130. );
  131. typedef NS_CONTEXT_DUMP_FN *PNS_CONTEXT_DUMP_FN;
  132. typedef
  133. DWORD
  134. (WINAPI NS_DLL_STOP_FN)(
  135. IN DWORD dwReserved
  136. );
  137. typedef NS_DLL_STOP_FN *PNS_DLL_STOP_FN;
  138. typedef
  139. DWORD
  140. (WINAPI NS_HELPER_START_FN)(
  141. IN CONST GUID *pguidParent,
  142. IN DWORD dwVersion
  143. );
  144. typedef NS_HELPER_START_FN *PNS_HELPER_START_FN;
  145. typedef
  146. DWORD
  147. (WINAPI NS_HELPER_STOP_FN)(
  148. IN DWORD dwReserved
  149. );
  150. typedef NS_HELPER_STOP_FN *PNS_HELPER_STOP_FN;
  151. typedef DWORD (FN_HANDLE_CMD)(
  152. IN LPCWSTR pwszMachine,
  153. IN OUT LPWSTR *ppwcArguments,
  154. IN DWORD dwCurrentIndex,
  155. IN DWORD dwArgCount,
  156. IN DWORD dwFlags,
  157. IN LPCVOID pvData,
  158. OUT BOOL *pbDone
  159. );
  160. typedef FN_HANDLE_CMD *PFN_HANDLE_CMD;
  161. typedef
  162. BOOL
  163. (WINAPI NS_OSVERSIONCHECK)(
  164. IN UINT CIMOSType, // WMI: Win32_OperatingSystem OSType
  165. IN UINT CIMOSProductSuite, // WMI: Win32_OperatingSystem OSProductSuite
  166. IN LPCWSTR CIMOSVersion, // WMI: Win32_OperatingSystem Version
  167. IN LPCWSTR CIMOSBuildNumber, // WMI: Win32_OperatingSystem BuildNumber
  168. IN LPCWSTR CIMServicePackMajorVersion, // WMI: Win32_OperatingSystem ServicePackMajorVersion
  169. IN LPCWSTR CIMServicePackMinorVersion, // WMI: Win32_OperatingSystem ServicePackMinorVersion
  170. IN UINT CIMProcessorArchitecture, // WMI: Win32_Processor Architecture
  171. IN DWORD dwReserved
  172. );
  173. typedef NS_OSVERSIONCHECK *PNS_OSVERSIONCHECK;
  174. // Structures
  175. typedef struct _NS_HELPER_ATTRIBUTES
  176. {
  177. union
  178. {
  179. struct
  180. {
  181. DWORD dwVersion;
  182. DWORD dwReserved;
  183. };
  184. ULONGLONG _ullAlign;
  185. };
  186. GUID guidHelper; // GUID associated with the helper
  187. PNS_HELPER_START_FN pfnStart; // Function to start this helper
  188. PNS_HELPER_STOP_FN pfnStop; // Function to stop this helper
  189. } NS_HELPER_ATTRIBUTES, *PNS_HELPER_ATTRIBUTES;
  190. typedef struct _CMD_ENTRY
  191. {
  192. LPCWSTR pwszCmdToken; // The token for the command
  193. PFN_HANDLE_CMD pfnCmdHandler; // The function which handles this command
  194. DWORD dwShortCmdHelpToken; // The short help message
  195. DWORD dwCmdHlpToken; // The message to display if the only thing after the command is a help token (HELP, /?, -?, ?)
  196. DWORD dwFlags; // Flags (see CMD_FLAGS_xxx above)
  197. PNS_OSVERSIONCHECK pOsVersionCheck; // Check for the version of the OS this command can run against
  198. } CMD_ENTRY, *PCMD_ENTRY;
  199. typedef struct _CMD_GROUP_ENTRY
  200. {
  201. LPCWSTR pwszCmdGroupToken; // The token for the command verb
  202. DWORD dwShortCmdHelpToken; // The message to display in a command listing.
  203. ULONG ulCmdGroupSize; // The number of entries in the cmd table
  204. DWORD dwFlags; // Flags (see CMD_FLAG_xxx)
  205. PCMD_ENTRY pCmdGroup; // The command table
  206. PNS_OSVERSIONCHECK pOsVersionCheck; // Check for the version of the OS this command can run against
  207. } CMD_GROUP_ENTRY, *PCMD_GROUP_ENTRY;
  208. typedef struct _NS_CONTEXT_ATTRIBUTES
  209. {
  210. union
  211. {
  212. struct
  213. {
  214. DWORD dwVersion;
  215. DWORD dwReserved;
  216. };
  217. ULONGLONG _ullAlign;
  218. };
  219. LPWSTR pwszContext; // Name of the context
  220. GUID guidHelper; // GUID of the helper servicing this context
  221. DWORD dwFlags; // Flags limiting when context is available. (See CMD_FLAG_xxx)
  222. ULONG ulPriority; // Priority field is only relevant if CMD_FLAG_PRIORITY is set in dwFlags
  223. ULONG ulNumTopCmds; // Number of top-level commands
  224. struct _CMD_ENTRY (*pTopCmds)[]; // Array of top-level commands
  225. ULONG ulNumGroups; // Number of command groups
  226. struct _CMD_GROUP_ENTRY (*pCmdGroups)[]; // Array of command groups
  227. PNS_CONTEXT_COMMIT_FN pfnCommitFn;
  228. PNS_CONTEXT_DUMP_FN pfnDumpFn;
  229. PNS_CONTEXT_CONNECT_FN pfnConnectFn;
  230. PVOID pReserved;
  231. PNS_OSVERSIONCHECK pfnOsVersionCheck;
  232. } NS_CONTEXT_ATTRIBUTES, *PNS_CONTEXT_ATTRIBUTES;
  233. typedef CONST struct _NS_CONTEXT_ATTRIBUTES * PCNS_CONTEXT_ATTRIBUTES;
  234. typedef struct _TAG_TYPE
  235. {
  236. LPCWSTR pwszTag; // tag string
  237. DWORD dwRequired; // required or not
  238. BOOL bPresent; // present or not
  239. } TAG_TYPE, *PTAG_TYPE;
  240. typedef
  241. DWORD
  242. (NS_DLL_INIT_FN)(
  243. IN DWORD dwNetshVersion,
  244. OUT PVOID pReserved
  245. );
  246. typedef NS_DLL_INIT_FN *PNS_DLL_INIT_FN;
  247. // Exports
  248. DWORD WINAPI GetHostMachineInfo(
  249. OUT UINT *puiCIMOSType, // WMI: Win32_OperatingSystem OSType
  250. OUT UINT *puiCIMOSProductSuite, // WMI: Win32_OperatingSystem OSProductSuite
  251. OUT LPWSTR pszCIMOSVersion, // WMI: Win32_OperatingSystem Version
  252. OUT LPWSTR pszCIMOSBuildNumber, // WMI: Win32_OperatingSystem BuildNumber
  253. OUT LPWSTR pszCIMServicePackMajorVersion, // WMI: Win32_OperatingSystem ServicePackMajorVersion
  254. OUT LPWSTR pszCIMServicePackMinorVersion, // WMI: Win32_OperatingSystem ServicePackMinorVersion
  255. OUT UINT *puiCIMProcessorArchitecture); // WMI: Win32_Processor Architecture
  256. DWORD WINAPI MatchEnumTag(
  257. IN HANDLE hModule,
  258. IN LPCWSTR pwcArg,
  259. IN DWORD dwNumArg,
  260. IN CONST TOKEN_VALUE *pEnumTable,
  261. OUT PDWORD pdwValue
  262. );
  263. BOOL WINAPI MatchToken(
  264. IN LPCWSTR pwszUserToken,
  265. IN LPCWSTR pwszCmdToken
  266. );
  267. DWORD WINAPI PreprocessCommand(
  268. IN HANDLE hModule,
  269. IN OUT LPWSTR *ppwcArguments,
  270. IN DWORD dwCurrentIndex,
  271. IN DWORD dwArgCount,
  272. IN OUT PTAG_TYPE pttTags,
  273. IN DWORD dwTagCount,
  274. IN DWORD dwMinArgs,
  275. IN DWORD dwMaxArgs,
  276. OUT DWORD *pdwTagType
  277. );
  278. DWORD PrintError(
  279. IN HANDLE hModule, OPTIONAL
  280. IN DWORD dwErrId,
  281. ...
  282. );
  283. DWORD PrintMessageFromModule(
  284. IN HANDLE hModule,
  285. IN DWORD dwMsgId,
  286. ...
  287. );
  288. DWORD PrintMessage(
  289. IN LPCWSTR pwszFormat,
  290. ...
  291. );
  292. DWORD WINAPI RegisterContext(
  293. IN CONST NS_CONTEXT_ATTRIBUTES *pChildContext
  294. );
  295. DWORD WINAPI RegisterHelper(
  296. IN CONST GUID *pguidParentContext,
  297. IN CONST NS_HELPER_ATTRIBUTES *pfnRegisterSubContext
  298. );
  299. #ifdef __cplusplus
  300. }
  301. #endif
  302. #pragma warning(pop)
  303. #endif // _NETSH_H_