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.

314 lines
10 KiB

  1. /*++
  2. Copyright (c) 1995 Microsoft Corporation
  3. Module Name:
  4. routes.c
  5. Abstract:
  6. IPX Router Console Monitoring and Configuration tool.
  7. Route Table monitoring.
  8. Author:
  9. Vadim Eydelman 06/07/1996
  10. --*/
  11. #include "precomp.h"
  12. #pragma hdrstop
  13. DWORD
  14. APIENTRY
  15. HelpRoute(
  16. IN int argc,
  17. IN WCHAR *argv[]
  18. )
  19. {
  20. DisplayIPXMessage (g_hModule, MSG_IPX_HELP_ROUTE);
  21. return 0;
  22. }
  23. DWORD
  24. APIENTRY
  25. ShowRoute (
  26. IN int argc,
  27. IN WCHAR *argv[]
  28. )
  29. {
  30. DWORD rc;
  31. PWCHAR InterfaceNameW = NULL;
  32. if (g_hMIBServer)
  33. {
  34. IPX_MIB_GET_INPUT_DATA MibGetInputData;
  35. PIPX_ROUTE pRt;
  36. DWORD sz;
  37. MibGetInputData.TableId = IPX_DEST_TABLE;
  38. if (argc == 0)
  39. {
  40. DisplayIPXMessage (g_hModule, MSG_ROUTE_TABLE_HDR);
  41. rc = MprAdminMIBEntryGetFirst(
  42. g_hMIBServer, PID_IPX, IPX_PROTOCOL_BASE,
  43. &MibGetInputData, sizeof(IPX_MIB_GET_INPUT_DATA),
  44. (LPVOID *)&pRt, &sz
  45. );
  46. while (rc == NO_ERROR)
  47. {
  48. DWORD rc1 = NO_ERROR;
  49. if ( pRt && pRt->InterfaceIndex != GLOBAL_INTERFACE_INDEX )
  50. {
  51. InterfaceNameW = HeapAlloc(
  52. GetProcessHeap(), 0,
  53. ( MAX_INTERFACE_NAME_LEN + 1 ) *
  54. sizeof( WCHAR )
  55. );
  56. if ( InterfaceNameW )
  57. {
  58. rc1 = GetIpxInterfaceName(
  59. g_hMIBServer, pRt->InterfaceIndex, InterfaceNameW
  60. );
  61. }
  62. else
  63. {
  64. rc1 = ERROR_NOT_ENOUGH_MEMORY;
  65. }
  66. }
  67. else
  68. {
  69. InterfaceNameW = VAL_DIALINCLIENT;
  70. if ( InterfaceNameW == NULL )
  71. {
  72. rc1 = ERROR_NOT_ENOUGH_MEMORY;
  73. }
  74. }
  75. if (rc1==NO_ERROR)
  76. {
  77. PWCHAR buffer;
  78. WCHAR IfDispName[ MAX_INTERFACE_NAME_LEN + 1 ];
  79. DWORD dwSize = sizeof(IfDispName);
  80. //======================================
  81. // Translate the Interface Name
  82. //======================================
  83. rc = IpmontrGetFriendlyNameFromIfName(
  84. InterfaceNameW, IfDispName, &dwSize
  85. );
  86. if ( rc == NO_ERROR )
  87. {
  88. buffer = GetEnumString(
  89. g_hModule, pRt->Protocol,
  90. NUM_TOKENS_IN_TABLE( IpxProtocols ),
  91. IpxProtocols
  92. );
  93. DisplayIPXMessage(
  94. g_hModule, MSG_ROUTE_TABLE_FMT,
  95. pRt->Network[0], pRt->Network[1],
  96. pRt->Network[2], pRt->Network[3],
  97. IfDispName, pRt->NextHopMacAddress[0],
  98. pRt->NextHopMacAddress[1], pRt->NextHopMacAddress[2],
  99. pRt->NextHopMacAddress[3], pRt->NextHopMacAddress[4],
  100. pRt->NextHopMacAddress[5], pRt->TickCount,
  101. pRt->HopCount, buffer
  102. );
  103. }
  104. }
  105. else
  106. {
  107. DisplayError (g_hModule, rc1);
  108. }
  109. memcpy(
  110. MibGetInputData.MibIndex.RoutingTableIndex.Network,
  111. pRt->Network,
  112. sizeof (MibGetInputData.MibIndex.RoutingTableIndex.Network)
  113. );
  114. if ( InterfaceNameW )
  115. {
  116. if ( pRt->InterfaceIndex != GLOBAL_INTERFACE_INDEX )
  117. {
  118. HeapFree( GetProcessHeap(), 0, InterfaceNameW );
  119. }
  120. else
  121. {
  122. FreeString( InterfaceNameW );
  123. }
  124. }
  125. InterfaceNameW = NULL;
  126. MprAdminBufferFree (pRt);
  127. rc = MprAdminMIBEntryGetNext(
  128. g_hMIBServer, PID_IPX, IPX_PROTOCOL_BASE,
  129. &MibGetInputData, sizeof(IPX_MIB_GET_INPUT_DATA),
  130. (LPVOID *)&pRt, &sz
  131. );
  132. }
  133. if (rc==ERROR_NO_MORE_ITEMS)
  134. {
  135. rc = NO_ERROR;
  136. }
  137. else
  138. {
  139. DisplayError (g_hModule, rc);
  140. }
  141. }
  142. else if (argc==1)
  143. {
  144. UINT n;
  145. ULONG val4;
  146. if ((swscanf (argv[0], L"%8lx%n", &val4, &n)==1)
  147. && (n==wcslen (argv[0])))
  148. {
  149. MibGetInputData.MibIndex.RoutingTableIndex.Network[0] = (BYTE)(val4>>24);
  150. MibGetInputData.MibIndex.RoutingTableIndex.Network[1] = (BYTE)(val4>>16);
  151. MibGetInputData.MibIndex.RoutingTableIndex.Network[2] = (BYTE)(val4>>8);
  152. MibGetInputData.MibIndex.RoutingTableIndex.Network[3] = (BYTE)val4;
  153. rc = MprAdminMIBEntryGet(
  154. g_hMIBServer, PID_IPX, IPX_PROTOCOL_BASE, &MibGetInputData,
  155. sizeof(IPX_MIB_GET_INPUT_DATA), (LPVOID *)&pRt, &sz
  156. );
  157. if ( rc==NO_ERROR )
  158. {
  159. if ( pRt && pRt->InterfaceIndex != GLOBAL_INTERFACE_INDEX )
  160. {
  161. InterfaceNameW = HeapAlloc(
  162. GetProcessHeap(), 0,
  163. ( MAX_INTERFACE_NAME_LEN + 1 ) *
  164. sizeof( WCHAR )
  165. );
  166. if ( InterfaceNameW )
  167. {
  168. rc = GetIpxInterfaceName(
  169. g_hMIBServer, pRt->InterfaceIndex, InterfaceNameW
  170. );
  171. }
  172. else
  173. {
  174. rc = ERROR_NOT_ENOUGH_MEMORY;
  175. }
  176. }
  177. else
  178. {
  179. InterfaceNameW = VAL_DIALINCLIENT;
  180. if ( InterfaceNameW == NULL )
  181. {
  182. rc = ERROR_NOT_ENOUGH_MEMORY;
  183. }
  184. }
  185. if (rc == NO_ERROR)
  186. {
  187. PWCHAR buffer;
  188. WCHAR IfDispName[ MAX_INTERFACE_NAME_LEN + 1 ];
  189. DWORD dwSize = sizeof(IfDispName);
  190. //======================================
  191. // Translate the Interface Name
  192. //======================================
  193. rc = IpmontrGetFriendlyNameFromIfName(
  194. InterfaceNameW, IfDispName, &dwSize
  195. );
  196. if ( rc == NO_ERROR )
  197. {
  198. buffer = GetEnumString(
  199. g_hModule, pRt->Protocol,
  200. NUM_TOKENS_IN_TABLE( IpxProtocols ),
  201. IpxProtocols
  202. );
  203. DisplayIPXMessage(
  204. g_hModule, MSG_ROUTE_SCREEN_FMT,
  205. pRt->Network[0], pRt->Network[1],
  206. pRt->Network[2], pRt->Network[3],
  207. InterfaceNameW,
  208. pRt->NextHopMacAddress[0], pRt->NextHopMacAddress[1],
  209. pRt->NextHopMacAddress[2], pRt->NextHopMacAddress[3],
  210. pRt->NextHopMacAddress[4], pRt->NextHopMacAddress[5],
  211. pRt->TickCount, pRt->HopCount,
  212. buffer
  213. );
  214. }
  215. }
  216. else
  217. {
  218. DisplayError (g_hModule, rc);
  219. }
  220. if ( InterfaceNameW )
  221. {
  222. if ( pRt->InterfaceIndex != GLOBAL_INTERFACE_INDEX )
  223. {
  224. HeapFree( GetProcessHeap(), 0, InterfaceNameW );
  225. }
  226. }
  227. InterfaceNameW = NULL;
  228. MprAdminMIBBufferFree( pRt );
  229. }
  230. else
  231. {
  232. DisplayError (g_hModule, rc);
  233. }
  234. }
  235. else
  236. {
  237. DisplayIPXMessage (g_hModule, MSG_IPX_HELP_ROUTE);
  238. rc = ERROR_INVALID_PARAMETER;
  239. }
  240. }
  241. else
  242. {
  243. DisplayIPXMessage (g_hModule, MSG_IPX_HELP_ROUTE);
  244. rc = ERROR_INVALID_PARAMETER;
  245. }
  246. }
  247. else
  248. {
  249. rc = ERROR_ROUTER_STOPPED;
  250. DisplayError (g_hModule, rc);
  251. }
  252. if ( InterfaceNameW )
  253. {
  254. }
  255. return rc;
  256. }