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.

189 lines
5.8 KiB

  1. /*++
  2. Copyright (c) 1999, Microsoft Corporation
  3. Module Name:
  4. sample\utils.h
  5. Abstract:
  6. The file contains the header for utils.c.
  7. --*/
  8. // definitions...
  9. #define is ==
  10. #define isnot !=
  11. #define or ||
  12. #define and &&
  13. #define ever ;;
  14. #define GetGlobalConfiguration IpmontrGetInfoBlockFromGlobalInfo
  15. #define SetGlobalConfiguration IpmontrSetInfoBlockInGlobalInfo
  16. #define DeleteGlobalConfiguration IpmontrDeleteInfoBlockFromGlobalInfo
  17. #define GetInterfaceConfiguration IpmontrGetInfoBlockFromInterfaceInfo
  18. #define SetInterfaceConfiguration IpmontrSetInfoBlockInInterfaceInfo
  19. #define DeleteInterfaceConfiguration IpmontrDeleteInfoBlockFromInterfaceInfo
  20. #define InterfaceNameFromGuid IpmontrGetFriendlyNameFromIfName
  21. #define InterfaceGuidFromName IpmontrGetIfNameFromFriendlyName
  22. #define InterfaceNameFromIndex IpmontrGetFriendlyNameFromIfIndex
  23. #define InterfaceIndexFromName IpmontrGetIfIndexFromFriendlyName
  24. #define DeleteProtocol IpmontrDeleteProtocol
  25. // typedefs...
  26. typedef enum { GET_EXACT, GET_FIRST, GET_NEXT } MODE;
  27. typedef enum { FORMAT_TABLE, FORMAT_VERBOSE, FORMAT_DUMP } FORMAT;
  28. typedef DWORD (*PGET_INDEX_FUNCTION) (
  29. IN HANDLE hMibServer,
  30. IN PWCHAR pwszArgument,
  31. OUT PDWORD pdwIfIndex
  32. );
  33. typedef VOID (*PPRINT_FUNCTION)(
  34. IN HANDLE hConsole,
  35. IN HANDLE hMibServer,
  36. IN PVOID pvOutput,
  37. IN FORMAT fFormat
  38. );
  39. typedef struct _MIB_OBJECT_ENTRY
  40. {
  41. PWCHAR pwszObjectName;
  42. DWORD dwObjectId;
  43. PGET_INDEX_FUNCTION pfnGetIndex;
  44. DWORD dwHeaderMessageId;
  45. PPRINT_FUNCTION pfnPrint;
  46. } MIB_OBJECT_ENTRY, *PMIB_OBJECT_ENTRY;
  47. // macros...
  48. #define VerifyInstalled(dwProtocolId, dwNameId) \
  49. { \
  50. if (!IsProtocolInstalled(dwProtocolId, dwNameId, TRUE)) \
  51. return ERROR_SUPPRESS_OUTPUT; \
  52. }
  53. #define ProcessError() \
  54. { \
  55. if (dwErr is ERROR_INVALID_PARAMETER) \
  56. { \
  57. DisplayError(g_hModule, \
  58. EMSG_BAD_OPTION_VALUE, \
  59. ppwcArguments[dwCurrentIndex + i], \
  60. pttTags[pdwTagType[i]].pwszTag); \
  61. dwErr = ERROR_SHOW_USAGE; \
  62. } \
  63. }
  64. #define UnicodeIpAddress(pwszUnicodeIpAddress, pszAsciiIpAddress) \
  65. MultiByteToWideChar(GetConsoleOutputCP(), \
  66. 0, \
  67. (pszAsciiIpAddress), \
  68. -1, \
  69. (pwszUnicodeIpAddress), \
  70. ADDR_LENGTH + 1)
  71. #define INET_NTOA(x) (inet_ntoa(*(struct in_addr*)&(x)))
  72. #define MALLOC(x) HeapAlloc(GetProcessHeap(), 0, x)
  73. #define FREE(x) HeapFree(GetProcessHeap(), 0, x)
  74. // inline functions...
  75. BOOL
  76. __inline
  77. IsInterfaceInstalled(
  78. IN PWCHAR pwszInterfaceGuid,
  79. IN DWORD dwProtocolId
  80. )
  81. {
  82. DWORD dwErr = NO_ERROR;
  83. PBYTE pbBuffer = NULL;
  84. dwErr = GetInterfaceConfiguration(pwszInterfaceGuid,
  85. dwProtocolId,
  86. &pbBuffer,
  87. NULL,
  88. NULL,
  89. NULL);
  90. if (pbBuffer) FREE(pbBuffer);
  91. return (dwErr is NO_ERROR);
  92. }
  93. DWORD
  94. __inline
  95. QuotedInterfaceNameFromGuid (
  96. IN PWCHAR pwszInterfaceGuid,
  97. OUT PWCHAR *ppwszQuotedInterfaceName
  98. )
  99. {
  100. DWORD dwErr = NO_ERROR;
  101. DWORD dwSize = MAX_INTERFACE_NAME_LEN + 1;
  102. WCHAR pwszInterfaceName[MAX_INTERFACE_NAME_LEN + 1] = L"\0";
  103. dwErr = InterfaceNameFromGuid(pwszInterfaceGuid,
  104. pwszInterfaceName,
  105. &dwSize);
  106. if (dwErr is NO_ERROR)
  107. {
  108. *ppwszQuotedInterfaceName = MakeQuotedString(pwszInterfaceName);
  109. if (*ppwszQuotedInterfaceName is NULL)
  110. dwErr = ERROR_NOT_ENOUGH_MEMORY;
  111. }
  112. return dwErr;
  113. }
  114. // functions...
  115. BOOL
  116. IsProtocolInstalled(
  117. IN DWORD dwProtocolId,
  118. IN DWORD dwNameId,
  119. IN DWORD dwLogUninstalled
  120. );
  121. DWORD
  122. GetIfIndex(
  123. IN HANDLE hMibServer,
  124. IN PWCHAR pwszArgument,
  125. OUT PDWORD pdwIfIndex
  126. );
  127. DWORD
  128. MibGet(
  129. IN HANDLE hMibServer,
  130. IN MODE mMode,
  131. IN PVOID pvIn,
  132. IN DWORD dwInSize,
  133. OUT PVOID *ppvOut
  134. );
  135. DWORD
  136. GetString(
  137. IN HANDLE hModule,
  138. IN FORMAT fFormat,
  139. IN DWORD dwValue,
  140. IN PVALUE_TOKEN vtTable,
  141. IN PVALUE_STRING vsTable,
  142. IN DWORD dwNumArgs,
  143. OUT PTCHAR *pptszString
  144. );