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.

233 lines
7.0 KiB

  1. //++
  2. //
  3. // Copyright (C) Microsoft Corporation, 1987 - 1999
  4. //
  5. // Module Name:
  6. //
  7. // defgw.c
  8. //
  9. // Abstract:
  10. //
  11. // Queries into network drivers
  12. //
  13. // Author:
  14. //
  15. // Anilth - 4-20-1998
  16. //
  17. // Environment:
  18. //
  19. // User mode only.
  20. // Contains NT-specific code.
  21. //
  22. // Revision History:
  23. //
  24. // NSun 08/30/98
  25. //
  26. //--
  27. #include "precomp.h"
  28. //-------------------------------------------------------------------------//
  29. //###### D e f G w T e s t () ###########################################//
  30. //-------------------------------------------------------------------------//
  31. HRESULT
  32. DefGwTest(NETDIAG_PARAMS* pParams, NETDIAG_RESULT* pResults)
  33. //++
  34. //
  35. // Routine Description:
  36. //
  37. // Tests that the default gateway can be pinged. This doesn't really
  38. // confirms forwarding on that IP address but it's a start.
  39. //
  40. // Arguments:
  41. //
  42. // None.
  43. //
  44. // Return Value:
  45. //
  46. // TRUE: Test suceeded.
  47. // FALSE: Test failed
  48. //
  49. //--
  50. {
  51. DWORD nReplyCnt;
  52. IPAddr GwAddress;
  53. int nGwsReachable = 0;
  54. int i;
  55. PIP_ADAPTER_INFO pIpAdapterInfo;
  56. IP_ADDR_STRING Gateway;
  57. PrintStatusMessage(pParams, 4, IDS_DEFGW_STATUS_MSG);
  58. //
  59. // try to ping all gateways on all adapters
  60. //
  61. for( i = 0; i < pResults->cNumInterfaces; i++)
  62. {
  63. pIpAdapterInfo = pResults->pArrayInterface[i].IpConfig.pAdapterInfo;
  64. InitializeListHead( &pResults->pArrayInterface[i].DefGw.lmsgOutput );
  65. if (!pResults->pArrayInterface[i].IpConfig.fActive ||
  66. NETCARD_DISCONNECTED == pResults->pArrayInterface[i].dwNetCardStatus)
  67. continue;
  68. pResults->pArrayInterface[i].DefGw.dwNumReachable = 0;
  69. Gateway = pIpAdapterInfo->GatewayList;
  70. if ( Gateway.IpAddress.String[0] == 0 )
  71. {
  72. //No default gateway configured
  73. pResults->pArrayInterface[i].DefGw.dwNumReachable = -1;
  74. continue;
  75. }
  76. while ( TRUE ) {
  77. AddMessageToList(&pResults->pArrayInterface[i].DefGw.lmsgOutput, Nd_ReallyVerbose, IDS_DEFGW_12003, Gateway.IpAddress.String );
  78. //IDS_DEFGW_12003 " Pinging gateway %s "
  79. if ( IsIcmpResponseA(Gateway.IpAddress.String) )
  80. {
  81. AddMessageToListId(&pResults->pArrayInterface[i].DefGw.lmsgOutput, Nd_ReallyVerbose, IDS_DEFGW_12004 );
  82. //IDS_DEFGW_12004 "- reachable\n"
  83. nGwsReachable++;
  84. pResults->pArrayInterface[i].DefGw.dwNumReachable ++;
  85. }
  86. else {
  87. AddMessageToListId(&pResults->pArrayInterface[i].DefGw.lmsgOutput, Nd_ReallyVerbose, IDS_DEFGW_12005 );
  88. //IDS_DEFGW_12005 "- not reachable\n"
  89. }
  90. if ( Gateway.Next == NULL ) { break; }
  91. Gateway = *(Gateway.Next);
  92. }
  93. }
  94. //
  95. // No gateway is reachable - fatal.
  96. //
  97. if ( nGwsReachable == 0 )
  98. {
  99. PrintStatusMessage(pParams, 0, IDS_GLOBAL_FAIL_NL);
  100. pResults->DefGw.hrReachable = S_FALSE;
  101. }
  102. else
  103. {
  104. PrintStatusMessage(pParams, 0, IDS_GLOBAL_PASS_NL);
  105. pResults->DefGw.hrReachable = S_OK;
  106. }
  107. return pResults->DefGw.hrReachable;
  108. } /* END OF DefGwTest() */
  109. //----------------------------------------------------------------
  110. //
  111. // DefGwGlobalPrint
  112. //
  113. // Author NSun
  114. //
  115. //------------------------------------------------------------------
  116. void DefGwGlobalPrint(NETDIAG_PARAMS *pParams, NETDIAG_RESULT *pResults)
  117. {
  118. if (!pResults->IpConfig.fEnabled)
  119. {
  120. return;
  121. }
  122. if (pParams->fVerbose || !FHrOK(pResults->DefGw.hrReachable))
  123. {
  124. PrintNewLine(pParams, 2);
  125. PrintTestTitleResult(pParams,
  126. IDS_DEFGW_LONG,
  127. IDS_DEFGW_SHORT,
  128. TRUE,
  129. pResults->DefGw.hrReachable,
  130. 0);
  131. }
  132. if(FHrOK(pResults->DefGw.hrReachable))
  133. {
  134. if (pParams->fReallyVerbose)
  135. PrintMessage(pParams, IDS_DEFGW_12011 );
  136. //IDS_DEFGW_12011 "\n PASS - you have at least one reachable gateway.\n"
  137. }
  138. else
  139. {
  140. //IDS_DEFGW_12006 "\n"
  141. PrintMessage(pParams, IDS_DEFGW_12006 );
  142. //IDS_DEFGW_12007 " [FATAL] NO GATEWAYS ARE REACHABLE.\n"
  143. PrintMessage(pParams, IDS_DEFGW_12007 );
  144. //IDS_DEFGW_12008 " You have no connectivity to other network segments.\n"
  145. PrintMessage(pParams, IDS_DEFGW_12008 );
  146. //IDS_DEFGW_12009 " If you configured the IP protocol manually then\n"
  147. PrintMessage(pParams, IDS_DEFGW_12009 );
  148. //IDS_DEFGW_12010 " you need to add at least one valid gateway.\n"
  149. PrintMessage(pParams, IDS_DEFGW_12010 );
  150. }
  151. }
  152. //----------------------------------------------------------------
  153. //
  154. // DefGwPerInterfacePrint
  155. //
  156. // Author NSun
  157. //
  158. //------------------------------------------------------------------
  159. void DefGwPerInterfacePrint(NETDIAG_PARAMS *pParams, NETDIAG_RESULT *pResults, INTERFACE_RESULT *pInterfaceResults)
  160. {
  161. if (!pInterfaceResults->fActive ||
  162. !pInterfaceResults->IpConfig.fActive ||
  163. NETCARD_DISCONNECTED == pInterfaceResults->dwNetCardStatus)
  164. return;
  165. if (pParams->fVerbose)
  166. {
  167. PrintNewLine(pParams, 1);
  168. if(-1 == pInterfaceResults->DefGw.dwNumReachable) //test skipped on this interface
  169. PrintTestTitleResult(pParams, IDS_DEFGW_LONG, IDS_DEFGW_SHORT, FALSE, S_FALSE, 8);
  170. else if(pInterfaceResults->DefGw.dwNumReachable == 0)
  171. PrintTestTitleResult(pParams, IDS_DEFGW_LONG, IDS_DEFGW_SHORT, TRUE, S_FALSE, 8);
  172. else
  173. PrintTestTitleResult(pParams, IDS_DEFGW_LONG, IDS_DEFGW_SHORT, TRUE, S_OK, 8);
  174. }
  175. PrintMessageList(pParams, &pInterfaceResults->DefGw.lmsgOutput);
  176. if(pParams->fVerbose)
  177. {
  178. if(-1 == pInterfaceResults->DefGw.dwNumReachable)
  179. PrintMessage(pParams, IDS_DEFGW_12002 );
  180. //IDS_DEFGW_12002 " There is no gateway defined for this adapter.\n"
  181. else if( 0 == pInterfaceResults->DefGw.dwNumReachable)
  182. PrintMessage(pParams, IDS_DEFGW_12001);
  183. //IDS_DEFGW_12001 " No gateway reachable for this adapter. \n"
  184. else if (pParams->fReallyVerbose)
  185. PrintMessage(pParams, IDS_DEFGW_12012);
  186. //IDS_DEFGW_12012 " At least one gateway for this adapter is reachable. \n"
  187. PrintNewLine(pParams, 1);
  188. }
  189. }
  190. //----------------------------------------------------------------
  191. //
  192. // DefGwCleanup
  193. //
  194. // Author NSun
  195. //
  196. //------------------------------------------------------------------
  197. void DefGwCleanup(IN NETDIAG_PARAMS *pParams,
  198. IN OUT NETDIAG_RESULT *pResults)
  199. {
  200. int i;
  201. for(i = 0; i < pResults->cNumInterfaces; i++)
  202. {
  203. MessageListCleanUp(&pResults->pArrayInterface[i].DefGw.lmsgOutput);
  204. }
  205. }