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.

253 lines
5.2 KiB

  1. #include "inc.h"
  2. CMD_ENTRY g_rgArpCmdTable[] = {
  3. {TOKEN_PRINT, PrintArp},
  4. {TOKEN_FLUSH, FlushArp},
  5. };
  6. VOID
  7. HandleArp(
  8. LONG lNumArgs,
  9. PWCHAR rgpwszArgs[]
  10. )
  11. {
  12. LONG lIndex;
  13. if(lNumArgs < 2)
  14. {
  15. DisplayMessage(HMSG_ARP_USAGE);
  16. return;
  17. }
  18. lIndex = ParseCommand(g_rgArpCmdTable,
  19. sizeof(g_rgArpCmdTable)/sizeof(CMD_ENTRY),
  20. rgpwszArgs[1]);
  21. if(lIndex is -1)
  22. {
  23. DisplayMessage(HMSG_ARP_USAGE);
  24. return;
  25. }
  26. g_rgArpCmdTable[lIndex].pfnHandler(lNumArgs - 1,
  27. &rgpwszArgs[1]);
  28. return;
  29. }
  30. VOID
  31. PrintArp(
  32. LONG lNumArgs,
  33. PWCHAR rgpwszArgs[]
  34. )
  35. {
  36. DWORD dwResult, i;
  37. PMIB_IPNETTABLE pTable;
  38. dwResult = AllocateAndGetIpNetTableFromStack(&pTable,
  39. TRUE,
  40. GetProcessHeap(),
  41. HEAP_NO_SERIALIZE,
  42. FALSE);
  43. if(dwResult isnot NO_ERROR)
  44. {
  45. PWCHAR pwszEntry;
  46. pwszEntry = MakeString(STR_ARPTABLE);
  47. if(pwszEntry)
  48. {
  49. DisplayMessage(EMSG_RETRIEVAL_ERROR1,
  50. dwResult,
  51. pwszEntry);
  52. FreeString(pwszEntry);
  53. }
  54. else
  55. {
  56. DisplayMessage(EMSG_RETRIEVAL_ERROR2,
  57. dwResult);
  58. }
  59. return;
  60. }
  61. if(pTable->dwNumEntries is 0)
  62. {
  63. PWCHAR pwszEntryType;
  64. pwszEntryType = MakeString(TOKEN_ARP);
  65. if(pwszEntryType)
  66. {
  67. DisplayMessage(EMSG_NO_ENTRIES1,
  68. pwszEntryType);
  69. FreeString(pwszEntryType);
  70. }
  71. else
  72. {
  73. DisplayMessage(EMSG_NO_ENTRIES2);
  74. }
  75. HeapFree(GetProcessHeap(),
  76. HEAP_NO_SERIALIZE,
  77. pTable);
  78. return;
  79. }
  80. DisplayMessage(MSG_ARPTABLE_HDR);
  81. for(i = 0; i < pTable->dwNumEntries; i++)
  82. {
  83. ADDR_STRING rgwcAddr;
  84. PWCHAR pwszType;
  85. WCHAR rgwcPhysAddr[3*MAXLEN_PHYSADDR + 8];
  86. NetworkToUnicode(pTable->table[i].dwAddr,
  87. rgwcAddr);
  88. switch(pTable->table[i].dwType)
  89. {
  90. case MIB_IPNET_TYPE_OTHER:
  91. {
  92. pwszType = MakeString(STR_OTHER);
  93. break;
  94. }
  95. case MIB_IPNET_TYPE_INVALID:
  96. {
  97. pwszType = MakeString(STR_INVALID);
  98. break;
  99. }
  100. case MIB_IPNET_TYPE_DYNAMIC:
  101. {
  102. pwszType = MakeString(STR_DYNAMIC);
  103. break;
  104. }
  105. case MIB_IPNET_TYPE_STATIC:
  106. {
  107. pwszType = MakeString(STR_STATIC);
  108. break;
  109. }
  110. }
  111. PhysAddrToUnicode(rgwcPhysAddr,
  112. pTable->table[i].bPhysAddr,
  113. pTable->table[i].dwPhysAddrLen);
  114. wprintf(L"%-15s\t\t%-24s\t%-4d\t\t%s\n",
  115. rgwcAddr,
  116. rgwcPhysAddr,
  117. pTable->table[i].dwIndex,
  118. pwszType);
  119. FreeString(pwszType);
  120. }
  121. HeapFree(GetProcessHeap(),
  122. HEAP_NO_SERIALIZE,
  123. pTable);
  124. }
  125. VOID
  126. FlushArp(
  127. LONG lNumArgs,
  128. PWCHAR rgpwszArgs[]
  129. )
  130. {
  131. DWORD i, dwIfIndex, dwResult;
  132. BOOL bFound;
  133. PMIB_IPADDRTABLE pTable;
  134. //
  135. // Parse the rest of the arguments
  136. // The command line at this point should read:
  137. // FLUSH <ifIndex>
  138. //
  139. if(lNumArgs < 2)
  140. {
  141. DisplayMessage(HMSG_ARP_FLUSH_USAGE);
  142. return;
  143. }
  144. dwIfIndex = wcstoul(rgpwszArgs[1],
  145. NULL,
  146. 10);
  147. //
  148. // Get the route table and see if such a route exists
  149. //
  150. dwResult = AllocateAndGetIpAddrTableFromStack(&pTable,
  151. TRUE,
  152. GetProcessHeap(),
  153. HEAP_NO_SERIALIZE);
  154. if(dwResult isnot NO_ERROR)
  155. {
  156. PWCHAR pwszEntry;
  157. pwszEntry = MakeString(STR_ADDRTABLE);
  158. if(pwszEntry)
  159. {
  160. DisplayMessage(EMSG_RETRIEVAL_ERROR1,
  161. dwResult,
  162. pwszEntry);
  163. FreeString(pwszEntry);
  164. }
  165. else
  166. {
  167. DisplayMessage(EMSG_RETRIEVAL_ERROR2,
  168. dwResult);
  169. }
  170. return;
  171. }
  172. for(bFound = FALSE, i = 0;
  173. i < pTable->dwNumEntries;
  174. i++)
  175. {
  176. if(pTable->table[i].dwIndex is dwIfIndex)
  177. {
  178. bFound = TRUE;
  179. break;
  180. }
  181. }
  182. HeapFree(GetProcessHeap(),
  183. HEAP_NO_SERIALIZE,
  184. pTable);
  185. if(!bFound)
  186. {
  187. DisplayMessage(EMSG_ARP_NO_SUCH_IF,
  188. dwIfIndex);
  189. return;
  190. }
  191. dwResult = FlushIpNetTableFromStack(dwIfIndex);
  192. if(dwResult isnot NO_ERROR)
  193. {
  194. DisplayMessage(EMSG_UNABLE_TO_FLUSH_ARP,
  195. dwIfIndex,
  196. dwResult);
  197. }
  198. }