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.

317 lines
6.8 KiB

  1. //++
  2. //
  3. // Copyright (C) Microsoft Corporation, 1987 - 1999
  4. //
  5. // Module Name:
  6. //
  7. // format.c
  8. //
  9. // Abstract:
  10. //
  11. // Test to ensure that a workstation has network (IP) connectivity to
  12. // the outside.
  13. //
  14. // Author:
  15. //
  16. // 15-Dec-1997 (cliffv)
  17. // Anilth - 4-20-1998
  18. //
  19. // Environment:
  20. //
  21. // User mode only.
  22. // Contains NT-specific code.
  23. //
  24. // Revision History:
  25. //
  26. // 1-June-1998 (denisemi) add DnsServerHasDCRecords to check DC dns records
  27. // registration
  28. //
  29. // 26-June-1998 (t-rajkup) add general tcp/ip , dhcp and routing,
  30. // winsock, ipx, wins and netbt information.
  31. //--
  32. //
  33. // Common include files.
  34. //
  35. #include "precomp.h"
  36. #include "ipcfgtest.h"
  37. void FormatWin32Error(DWORD dwErr, TCHAR *pszBuffer, UINT cchBuffer)
  38. {
  39. DWORD dwErrMsg;
  40. assert(dwErr != ERROR_SUCCESS);
  41. dwErrMsg = FormatMessage(
  42. FORMAT_MESSAGE_FROM_SYSTEM,
  43. NULL,
  44. dwErr,
  45. 0,
  46. pszBuffer,
  47. cchBuffer,
  48. NULL);
  49. pszBuffer[cchBuffer-1] = 0;
  50. }
  51. static TCHAR s_szPass[32] = _T("");
  52. static TCHAR s_szFail[32] = _T("");
  53. static TCHAR s_szSkip[32] = _T("");
  54. void PrintTestTitleResult(NETDIAG_PARAMS *pParams, UINT idsTestLongName, UINT idsTestShortName,
  55. BOOL fPerformed, HRESULT hr, int nIndent)
  56. {
  57. TCHAR szBuffer[256];
  58. TCHAR szTitle[256];
  59. TCHAR szTitleTest[256];
  60. LPTSTR pszPassFail = NULL;
  61. int cch, i;
  62. TCHAR szContactInfo[MAX_CONTACT_STRING] = _T("");
  63. if (s_szPass[0] == 0)
  64. {
  65. LoadString(NULL, IDS_GLOBAL_PASS, s_szPass, DimensionOf(s_szPass));
  66. LoadString(NULL, IDS_GLOBAL_FAIL, s_szFail, DimensionOf(s_szFail));
  67. LoadString(NULL, IDS_GLOBAL_SKIP, s_szSkip, DimensionOf(s_szSkip));
  68. }
  69. // Fill the buffer up with ' .'
  70. for ( i=0; i<DimensionOf(szBuffer); i+= 2)
  71. {
  72. szBuffer[i] = _T(' ');
  73. szBuffer[i+1] = _T('.');
  74. }
  75. // Fill up the indents
  76. for ( i=0; i<nIndent; i++)
  77. szBuffer[i] = _T(' ');
  78. // Add the test name
  79. LoadString(NULL, idsTestLongName, szTitle,
  80. DimensionOf(szTitle));
  81. szTitle[DimensionOf(szTitle)-1] = 0;
  82. wsprintf(szTitleTest, _T("%s test"), szTitle);
  83. cch = StrLen(szTitleTest);
  84. // Do NOT use StrCpyN or lstrcpyn here!
  85. // They will automatically fill in a terminating NULl character
  86. // which I do not want.
  87. _tcsncpy(szBuffer+nIndent, szTitleTest, cch);
  88. if (!fPerformed)
  89. pszPassFail = s_szSkip;
  90. else
  91. {
  92. if (FHrOK(hr))
  93. pszPassFail = s_szPass;
  94. else
  95. {
  96. TCHAR szTitleShort[256];
  97. pszPassFail = s_szFail;
  98. LoadString(NULL, idsTestShortName, szTitleShort,
  99. DimensionOf(szTitleShort));
  100. LoadContact(szTitleShort, szContactInfo, DimensionOf(szContactInfo));
  101. }
  102. }
  103. if ((nIndent + cch) > 35)
  104. wsprintf(szBuffer+nIndent+cch, _T(": %s\n"), pszPassFail);
  105. else
  106. wsprintf(szBuffer+35, _T(": %s\n"), pszPassFail);
  107. PrintMessageSz(pParams, szBuffer);
  108. //print the contact info if any
  109. if (_tcslen(szContactInfo))
  110. {
  111. // Fill up the indents
  112. for ( i=0; i<nIndent; i++)
  113. {
  114. szBuffer[i] = _T(' ');
  115. }
  116. szBuffer[i] = 0;
  117. PrintMessageSz(pParams, szBuffer);
  118. PrintMessage(pParams, IDS_CONTACT, szContactInfo);
  119. }
  120. }
  121. void PrintNewLine(NETDIAG_PARAMS *pParams, int cNewLine)
  122. {
  123. int i;
  124. for ( i=0; i<cNewLine; i++)
  125. PrintMessageSz(pParams, _T("\n"));
  126. }
  127. LPTSTR MAP_YES_NO(BOOL fYes)
  128. {
  129. static TCHAR s_szYes[64] = _T("");
  130. static TCHAR s_szNo[64] = _T("");
  131. if (s_szYes[0] == 0)
  132. {
  133. LoadString(NULL, IDS_GLOBAL_YES, s_szYes, DimensionOf(s_szYes));
  134. LoadString(NULL, IDS_GLOBAL_NO, s_szNo, DimensionOf(s_szNo));
  135. }
  136. return fYes ? s_szYes : s_szNo;
  137. }
  138. LPTSTR MAP_ON_OFF(BOOL fOn)
  139. {
  140. static TCHAR s_szOn[64] = _T("");
  141. static TCHAR s_szOff[64] = _T("");
  142. if (s_szOn[0] == 0)
  143. {
  144. LoadString(NULL, IDS_GLOBAL_ON, s_szOn, DimensionOf(s_szOn));
  145. LoadString(NULL, IDS_GLOBAL_OFF, s_szOff, DimensionOf(s_szOff));
  146. }
  147. return fOn ? s_szOn : s_szOff;
  148. }
  149. LPTSTR MapWinsNodeType(UINT Parm)
  150. {
  151. static BOOL s_fMapWinsNodeTypeInit = FALSE;
  152. static LPTSTR s_pszWinsNodeType[LAST_NODE_TYPE+1];
  153. DWORD dwParm = LAST_NODE_TYPE + 1;
  154. if (!s_fMapWinsNodeTypeInit)
  155. {
  156. s_fMapWinsNodeTypeInit = TRUE;
  157. // Load all of the strings, (they can be leaked)
  158. s_pszWinsNodeType[0] = NULL;
  159. s_pszWinsNodeType[1] = LoadAndAllocString(IDS_GLOBAL_BROADCAST_NODE);
  160. s_pszWinsNodeType[2] = LoadAndAllocString(IDS_GLOBAL_PEER_PEER_NODE);
  161. s_pszWinsNodeType[3] = LoadAndAllocString(IDS_GLOBAL_MIXED_NODE);
  162. s_pszWinsNodeType[4] = LoadAndAllocString(IDS_GLOBAL_HYBRID_NODE);
  163. assert(LAST_NODE_TYPE == 4);
  164. }
  165. //
  166. // 1, 2, 4, 8 => log2(n) + 1 [1, 2, 3, 4]
  167. //
  168. switch (Parm) {
  169. case 0:
  170. //
  171. // according to JStew value of 0 will be treated as BNode (default)
  172. //
  173. case BNODE:
  174. dwParm = 1;
  175. break;
  176. case PNODE:
  177. dwParm = 2;
  178. break;
  179. case MNODE:
  180. dwParm = 3;
  181. break;
  182. case HNODE:
  183. dwParm = 4;
  184. break;
  185. }
  186. if ((dwParm >= FIRST_NODE_TYPE) && (dwParm <= LAST_NODE_TYPE)) {
  187. return s_pszWinsNodeType[dwParm];
  188. }
  189. //
  190. // if no node type is defined then we default to Hybrid
  191. //
  192. return s_pszWinsNodeType[LAST_NODE_TYPE];
  193. }
  194. #define MAX_ADAPTER_TYPES 8
  195. LPTSTR MapAdapterType(UINT type)
  196. {
  197. static BOOL s_fInitMapAdapterType = FALSE;
  198. static LPTSTR s_pszAdapterTypes[MAX_ADAPTER_TYPES];
  199. if (!s_fInitMapAdapterType)
  200. {
  201. s_fInitMapAdapterType = TRUE;
  202. s_pszAdapterTypes[0] = LoadAndAllocString(IDS_GLOBAL_ADAPTER_OTHER);
  203. s_pszAdapterTypes[1] = LoadAndAllocString(IDS_GLOBAL_ADAPTER_ETHERNET);
  204. s_pszAdapterTypes[2] = LoadAndAllocString(IDS_GLOBAL_ADAPTER_TOKEN_RING);
  205. s_pszAdapterTypes[3] = LoadAndAllocString(IDS_GLOBAL_ADAPTER_FDDI);
  206. s_pszAdapterTypes[4] = LoadAndAllocString(IDS_GLOBAL_ADAPTER_PPP);
  207. s_pszAdapterTypes[5] = LoadAndAllocString(IDS_GLOBAL_ADAPTER_LOOPBACK);
  208. s_pszAdapterTypes[6] = LoadAndAllocString(IDS_GLOBAL_ADAPTER_SLIP);
  209. s_pszAdapterTypes[7] = LoadAndAllocString(IDS_GLOBAL_ADAPTER_UNKNOWN);
  210. }
  211. switch (type)
  212. {
  213. case IF_TYPE_OTHER:
  214. return s_pszAdapterTypes[0];
  215. case IF_TYPE_ETHERNET_CSMACD:
  216. return s_pszAdapterTypes[1];
  217. case IF_TYPE_ISO88025_TOKENRING:
  218. return s_pszAdapterTypes[2];
  219. case IF_TYPE_FDDI:
  220. return s_pszAdapterTypes[3];
  221. case IF_TYPE_PPP:
  222. return s_pszAdapterTypes[4];
  223. case IF_TYPE_SOFTWARE_LOOPBACK:
  224. return s_pszAdapterTypes[5];
  225. case IF_TYPE_SLIP:
  226. return s_pszAdapterTypes[6];
  227. default:
  228. return s_pszAdapterTypes[7];
  229. }
  230. return _T("");
  231. }
  232. void PrintError(NETDIAG_PARAMS *pParams, UINT idsContext, HRESULT hr)
  233. {
  234. PTSTR ptzSysMsg = NULL;
  235. UINT cch = FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
  236. NULL, hr, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
  237. (PTSTR)&ptzSysMsg, 0, NULL);
  238. if (!cch) // not found with system
  239. {
  240. TCHAR t[20];
  241. _ultot(hr, t, 16);
  242. PrintMessage(pParams, idsContext, ptzSysMsg);
  243. }
  244. else
  245. {
  246. PrintMessage(pParams, idsContext, ptzSysMsg);
  247. LocalFree(ptzSysMsg);
  248. }
  249. }