Source code of Windows XP (NT5)
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.

354 lines
11 KiB

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