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.

2611 lines
63 KiB

  1. //=============================================================================
  2. // Copyright (c) 1999 Microsoft Corporation
  3. // File: ifip.c
  4. // Abstract:
  5. // This module implements the if/ip apis
  6. //
  7. // Author: K.S.Lokesh (lokeshs@) 8-1-99
  8. //=============================================================================
  9. #include "precomp.h"
  10. #pragma hdrstop
  11. #include "ifip.h"
  12. //
  13. // global variables
  14. //
  15. #define IFIP_IFNAME_MASK 0x0001
  16. #define IFIP_SOURCE_MASK 0X0002
  17. #define IFIP_ADDR_MASK 0X0004
  18. #define IFIP_MASK_MASK 0X0008
  19. #define IFIP_GATEWAY_MASK 0X0010
  20. #define IFIP_GWMETRIC_MASK 0X0020
  21. #define IFIP_INDEX_MASK 0X0040
  22. #define DHCP 1
  23. #define STATIC 2
  24. #define NONE ~0
  25. #define ALL ~0
  26. // The guid for this context
  27. //
  28. GUID g_IfIpGuid = IFIP_GUID;
  29. // The commands supported in this context
  30. //
  31. CMD_ENTRY g_IfIpAddCmdTable[] =
  32. {
  33. CREATE_CMD_ENTRY_EX(IFIP_ADD_IPADDR,IfIpHandleAddAddress,CMD_FLAG_LOCAL),
  34. CREATE_CMD_ENTRY_EX(IFIP_ADD_DNS,IfIpHandleAddDns,CMD_FLAG_LOCAL),
  35. CREATE_CMD_ENTRY_EX(IFIP_ADD_WINS,IfIpHandleAddWins,CMD_FLAG_LOCAL),
  36. };
  37. CMD_ENTRY g_IfIpSetCmdTable[] =
  38. {
  39. CREATE_CMD_ENTRY_EX(IFIP_SET_IPADDR,IfIpHandleSetAddress,CMD_FLAG_LOCAL),
  40. CREATE_CMD_ENTRY_EX(IFIP_SET_DNS,IfIpHandleSetDns,CMD_FLAG_LOCAL),
  41. CREATE_CMD_ENTRY_EX(IFIP_SET_WINS,IfIpHandleSetWins,CMD_FLAG_LOCAL),
  42. };
  43. CMD_ENTRY g_IfIpDelCmdTable[] =
  44. {
  45. CREATE_CMD_ENTRY_EX(IFIP_DEL_IPADDR,IfIpHandleDelAddress,CMD_FLAG_LOCAL),
  46. CREATE_CMD_ENTRY_EX(IFIP_DEL_DNS,IfIpHandleDelDns,CMD_FLAG_LOCAL),
  47. CREATE_CMD_ENTRY_EX(IFIP_DEL_WINS,IfIpHandleDelWins,CMD_FLAG_LOCAL),
  48. CREATE_CMD_ENTRY_EX(IFIP_DEL_ARPCACHE,IfIpHandleDelArpCache,CMD_FLAG_LOCAL),
  49. };
  50. CMD_ENTRY g_IfIpShowCmdTable[] =
  51. {
  52. CREATE_CMD_ENTRY_EX(IFIP_SHOW_CONFIG,IfIpHandleShowConfig,CMD_FLAG_LOCAL),
  53. CREATE_CMD_ENTRY_EX(IFIP_SHOW_IPADDR,IfIpHandleShowAddress,CMD_FLAG_LOCAL),
  54. CREATE_CMD_ENTRY_EX(IFIP_SHOW_OFFLOAD,IfIpHandleShowOffload,CMD_FLAG_LOCAL),
  55. CREATE_CMD_ENTRY_EX(IFIP_SHOW_DNS, IfIpHandleShowDns,CMD_FLAG_LOCAL),
  56. CREATE_CMD_ENTRY_EX(IFIP_SHOW_WINS, IfIpHandleShowWins,CMD_FLAG_LOCAL),
  57. CREATE_CMD_ENTRY(IPMIB_SHOW_INTERFACE, HandleIpMibShowObject),
  58. CREATE_CMD_ENTRY(IPMIB_SHOW_IPSTATS, HandleIpMibShowObject),
  59. CREATE_CMD_ENTRY(IPMIB_SHOW_IPADDRESS, HandleIpMibShowObject),
  60. CREATE_CMD_ENTRY(IPMIB_SHOW_IPNET, HandleIpMibShowObject),
  61. CREATE_CMD_ENTRY(IPMIB_SHOW_ICMP, HandleIpMibShowObject),
  62. CREATE_CMD_ENTRY(IPMIB_SHOW_TCPSTATS, HandleIpMibShowObject),
  63. CREATE_CMD_ENTRY(IPMIB_SHOW_TCPCONN, HandleIpMibShowObject),
  64. CREATE_CMD_ENTRY(IPMIB_SHOW_UDPSTATS, HandleIpMibShowObject),
  65. CREATE_CMD_ENTRY(IPMIB_SHOW_UDPCONN, HandleIpMibShowObject),
  66. CREATE_CMD_ENTRY_EX(IPMIB_SHOW_JOINS, HandleIpShowJoins,CMD_FLAG_LOCAL),
  67. };
  68. CMD_GROUP_ENTRY g_IfIpCmdGroups[] =
  69. {
  70. CREATE_CMD_GROUP_ENTRY(GROUP_ADD, g_IfIpAddCmdTable),
  71. CREATE_CMD_GROUP_ENTRY(GROUP_SET, g_IfIpSetCmdTable),
  72. CREATE_CMD_GROUP_ENTRY(GROUP_DELETE, g_IfIpDelCmdTable),
  73. CREATE_CMD_GROUP_ENTRY(GROUP_SHOW, g_IfIpShowCmdTable),
  74. };
  75. ULONG g_ulIfIpNumGroups = sizeof(g_IfIpCmdGroups)/sizeof(CMD_GROUP_ENTRY);
  76. CMD_ENTRY g_IfIpTopCmds[] =
  77. {
  78. CREATE_CMD_ENTRY_EX(IFIP_RESET, IfIpHandleReset, CMD_FLAG_LOCAL | CMD_FLAG_ONLINE),
  79. };
  80. ULONG g_ulIfIpNumTopCmds = sizeof(g_IfIpTopCmds)/sizeof(CMD_ENTRY);
  81. #define DispTokenErrMsg(hModule, dwMsgId, pwszTag, pwszValue) \
  82. DisplayMessage( hModule, dwMsgId, pwszValue, pwszTag)
  83. DWORD
  84. WINAPI
  85. IfIpStartHelper(
  86. IN CONST GUID *pguidParent,
  87. IN DWORD dwVersion)
  88. /*++
  89. Routine Description
  90. Used to initialize the helper.
  91. Arguments
  92. pguidParent Ifmon's guid
  93. Return Value
  94. NO_ERROR
  95. other error code
  96. --*/
  97. {
  98. DWORD dwErr = NO_ERROR;
  99. NS_CONTEXT_ATTRIBUTES attMyAttributes;
  100. // Initialize
  101. //
  102. ZeroMemory(&attMyAttributes, sizeof(attMyAttributes));
  103. attMyAttributes.pwszContext = L"ip";
  104. attMyAttributes.guidHelper = g_IfIpGuid;
  105. attMyAttributes.dwVersion = IFIP_VERSION;
  106. attMyAttributes.dwFlags = 0;
  107. attMyAttributes.ulNumTopCmds= g_ulIfIpNumTopCmds;
  108. attMyAttributes.pTopCmds = (CMD_ENTRY (*)[])&g_IfIpTopCmds;
  109. attMyAttributes.ulNumGroups = g_ulIfIpNumGroups;
  110. attMyAttributes.pCmdGroups = (CMD_GROUP_ENTRY (*)[])&g_IfIpCmdGroups;
  111. attMyAttributes.pfnDumpFn = IfIpDump;
  112. dwErr = RegisterContext( &attMyAttributes );
  113. return dwErr;
  114. }
  115. DWORD
  116. WINAPI
  117. IfIpDump(
  118. IN LPCWSTR pwszRouter,
  119. IN LPWSTR *ppwcArguments,
  120. IN DWORD dwArgCount,
  121. IN LPCVOID pvData
  122. )
  123. /*++
  124. Routine Description
  125. Used when dumping all contexts
  126. Arguments
  127. Return Value
  128. NO_ERROR
  129. --*/
  130. {
  131. DWORD dwErr;
  132. HANDLE hFile = (HANDLE)-1;
  133. DisplayMessage( g_hModule, DMP_IFIP_HEADER );
  134. DisplayMessageT(DMP_IFIP_PUSHD);
  135. IfIpShowAllInterfaceInfo(pwszRouter, TYPE_IP_ALL, hFile);
  136. DisplayMessageT(DMP_IFIP_POPD);
  137. DisplayMessage( g_hModule, DMP_IFIP_FOOTER );
  138. return NO_ERROR;
  139. }
  140. DWORD
  141. IfIpHandleSetAddress(
  142. IN LPCWSTR pwszMachine,
  143. IN OUT LPWSTR *ppwcArguments,
  144. IN DWORD dwCurrentIndex,
  145. IN DWORD dwArgCount,
  146. IN DWORD dwFlags,
  147. IN LPCVOID pvData,
  148. OUT BOOL *pbDone
  149. )
  150. /*++
  151. Routine Description
  152. Arguments
  153. Return Value
  154. NO_ERROR
  155. --*/
  156. {
  157. WCHAR wszInterfaceName[MAX_INTERFACE_NAME_LEN + 1] = L"\0";
  158. PWCHAR wszIfFriendlyName = NULL;
  159. DWORD dwBufferSize = sizeof(wszInterfaceName);
  160. DWORD dwErr = NO_ERROR,dwRes, dwErrIndex=-1;
  161. TAG_TYPE pttTags[] = {
  162. {TOKEN_NAME,FALSE,FALSE},
  163. {TOKEN_SOURCE,FALSE,FALSE},
  164. {TOKEN_ADDR,FALSE,FALSE},
  165. {TOKEN_MASK,FALSE,FALSE},
  166. {TOKEN_GATEWAY,FALSE,FALSE},
  167. {TOKEN_GWMETRIC,FALSE,FALSE}};
  168. PDWORD pdwTagType;
  169. DWORD dwNumOpt, dwBitVector=0;
  170. DWORD dwNumArg, i, j;
  171. DWORD dwAddSource, dwAddAddr, dwAddMask, dwAddGateway, dwAddGwmetric;
  172. PWCHAR pwszAddAddr, pwszAddMask, pwszAddGateway, pwszAddGwmetric;
  173. BOOL EmptyGateway = FALSE;
  174. // At least interface name & address should be specified.
  175. if (dwCurrentIndex +1 >= dwArgCount)
  176. {
  177. return ERROR_SHOW_USAGE;
  178. }
  179. dwNumArg = dwArgCount - dwCurrentIndex;
  180. pdwTagType = HeapAlloc(GetProcessHeap(),
  181. 0,
  182. dwNumArg * sizeof(DWORD));
  183. if (pdwTagType is NULL)
  184. {
  185. return ERROR_NOT_ENOUGH_MEMORY;
  186. }
  187. dwErr = MatchTagsInCmdLine(g_hModule,
  188. ppwcArguments,
  189. dwCurrentIndex,
  190. dwArgCount,
  191. pttTags,
  192. NUM_TAGS_IN_TABLE(pttTags),
  193. pdwTagType);
  194. if (dwErr isnot NO_ERROR)
  195. {
  196. IfutlFree(pdwTagType);
  197. if (dwErr is ERROR_INVALID_OPTION_TAG)
  198. {
  199. return ERROR_INVALID_SYNTAX;
  200. }
  201. return dwErr;
  202. }
  203. for ( i = 0; i < dwNumArg; i++)
  204. {
  205. switch (pdwTagType[i])
  206. {
  207. case 0 :
  208. {
  209. dwErr = GetIfNameFromFriendlyName(ppwcArguments[i + dwCurrentIndex],
  210. wszInterfaceName,&dwBufferSize);
  211. if (dwErr isnot NO_ERROR)
  212. {
  213. DisplayMessage(g_hModule, EMSG_INVALID_INTERFACE,
  214. ppwcArguments[i + dwCurrentIndex]);
  215. dwErr = ERROR_SUPPRESS_OUTPUT;
  216. break;
  217. }
  218. wszIfFriendlyName = ppwcArguments[i + dwCurrentIndex];
  219. dwBitVector |= IFIP_IFNAME_MASK;
  220. break;
  221. }
  222. case 1:
  223. {
  224. //
  225. // dhcp or static
  226. //
  227. TOKEN_VALUE rgEnums[] =
  228. {{TOKEN_VALUE_DHCP, DHCP},
  229. {TOKEN_VALUE_STATIC,STATIC}};
  230. dwErr = MatchEnumTag(g_hModule,
  231. ppwcArguments[i + dwCurrentIndex],
  232. NUM_TOKENS_IN_TABLE(rgEnums),
  233. rgEnums,
  234. &dwRes);
  235. if (dwErr != NO_ERROR)
  236. {
  237. dwErrIndex = i;
  238. i = dwNumArg;
  239. dwErr = ERROR_INVALID_PARAMETER;
  240. break;
  241. }
  242. dwAddSource = dwRes ;
  243. dwBitVector |= IFIP_SOURCE_MASK;
  244. break;
  245. }
  246. case 2:
  247. {
  248. //
  249. // ip address for static
  250. //
  251. dwErr = GetIpAddress(ppwcArguments[i + dwCurrentIndex],
  252. &dwAddAddr);
  253. if((dwErr != NO_ERROR) or CHECK_UNICAST_IP_ADDR(dwAddAddr))
  254. {
  255. DispTokenErrMsg(g_hModule,
  256. EMSG_BAD_OPTION_VALUE,
  257. pttTags[pdwTagType[i]].pwszTag,
  258. ppwcArguments[i + dwCurrentIndex]);
  259. dwErr = ERROR_SUPPRESS_OUTPUT;
  260. break;
  261. }
  262. pwszAddAddr = ppwcArguments[i + dwCurrentIndex];
  263. dwBitVector |= IFIP_ADDR_MASK;
  264. break;
  265. }
  266. case 3:
  267. {
  268. //
  269. // get mask
  270. //
  271. dwErr = GetIpAddress(ppwcArguments[i + dwCurrentIndex],
  272. &dwAddAddr);
  273. if((dwErr != NO_ERROR) or CHECK_NETWORK_MASK(dwAddAddr))
  274. {
  275. DispTokenErrMsg(g_hModule,
  276. EMSG_BAD_OPTION_VALUE,
  277. pttTags[pdwTagType[i]].pwszTag,
  278. ppwcArguments[i + dwCurrentIndex]);
  279. dwErr = ERROR_SUPPRESS_OUTPUT;
  280. break;
  281. }
  282. pwszAddMask = ppwcArguments[i + dwCurrentIndex];
  283. dwBitVector |= IFIP_MASK_MASK;
  284. break;
  285. }
  286. case 4:
  287. {
  288. //
  289. // get default gateway addr
  290. //
  291. TOKEN_VALUE rgEnums[] =
  292. {{TOKEN_VALUE_NONE, NONE}};
  293. dwErr = MatchEnumTag(g_hModule,
  294. ppwcArguments[i + dwCurrentIndex],
  295. NUM_TOKENS_IN_TABLE(rgEnums),
  296. rgEnums,
  297. &dwRes);
  298. if (dwErr == NO_ERROR) {
  299. EmptyGateway = TRUE;
  300. pwszAddGateway = pwszAddGwmetric = NULL;
  301. }
  302. else {
  303. dwErr = GetIpAddress(ppwcArguments[i + dwCurrentIndex], &dwAddAddr);
  304. if((dwErr != NO_ERROR) or CHECK_UNICAST_IP_ADDR(dwAddAddr))
  305. {
  306. DispTokenErrMsg(g_hModule,
  307. EMSG_BAD_OPTION_VALUE,
  308. pttTags[pdwTagType[i]].pwszTag,
  309. ppwcArguments[i + dwCurrentIndex]);
  310. dwErr = ERROR_SUPPRESS_OUTPUT;
  311. }
  312. pwszAddGateway = ppwcArguments[i + dwCurrentIndex];
  313. }
  314. dwBitVector |= IFIP_GATEWAY_MASK;
  315. break;
  316. }
  317. case 5:
  318. {
  319. //
  320. // gwmetric
  321. //
  322. dwAddGwmetric =
  323. _tcstoul(ppwcArguments[i + dwCurrentIndex], NULL, 10);
  324. if ( dwAddGwmetric > 9999 )
  325. {
  326. dwErrIndex = i;
  327. dwErr = ERROR_INVALID_PARAMETER;
  328. i = dwNumArg;
  329. break;
  330. }
  331. pwszAddGwmetric = ppwcArguments[i + dwCurrentIndex];
  332. dwBitVector |= IFIP_GWMETRIC_MASK;
  333. break;
  334. }
  335. default:
  336. {
  337. i = dwNumArg;
  338. dwErr = ERROR_INVALID_PARAMETER;
  339. break;
  340. }
  341. } //switch
  342. if (dwErr != NO_ERROR)
  343. break ;
  344. }
  345. switch(dwErr)
  346. {
  347. case NO_ERROR :
  348. break;
  349. case ERROR_INVALID_PARAMETER:
  350. if (dwErrIndex != -1)
  351. {
  352. DispTokenErrMsg(g_hModule,
  353. EMSG_BAD_OPTION_VALUE,
  354. pttTags[pdwTagType[dwErrIndex]].pwszTag,
  355. ppwcArguments[dwErrIndex + dwCurrentIndex]);
  356. dwErr = ERROR_SUPPRESS_OUTPUT;
  357. }
  358. break;
  359. default:
  360. // error message already printed
  361. break;
  362. }
  363. if (pdwTagType)
  364. IfutlFree(pdwTagType);
  365. if (dwErr != NO_ERROR)
  366. return dwErr;
  367. // interface name should be present
  368. if ( !(dwBitVector & IFIP_IFNAME_MASK)) {
  369. return ERROR_INVALID_SYNTAX;
  370. }
  371. if ( (dwBitVector & (IFIP_ADDR_MASK|IFIP_MASK_MASK))
  372. && (dwAddSource != STATIC))
  373. {
  374. return ERROR_INVALID_SYNTAX;
  375. }
  376. if (( (dwBitVector&IFIP_ADDR_MASK) && !(dwBitVector&IFIP_MASK_MASK) )
  377. ||( !(dwBitVector&IFIP_ADDR_MASK) && (dwBitVector&IFIP_MASK_MASK) )
  378. ||( (dwBitVector&IFIP_ADDR_MASK) && !(dwBitVector&IFIP_SOURCE_MASK) )
  379. ||( (dwBitVector&IFIP_GATEWAY_MASK) && !EmptyGateway && !(dwBitVector&IFIP_GWMETRIC_MASK) )
  380. ||( !(dwBitVector&IFIP_GATEWAY_MASK) && (dwBitVector&IFIP_GWMETRIC_MASK) )
  381. ||((dwAddSource==STATIC) && !(dwBitVector&IFIP_ADDR_MASK)
  382. && !(dwBitVector&IFIP_GATEWAY_MASK) )
  383. ||( (dwBitVector&IFIP_GWMETRIC_MASK) && EmptyGateway)
  384. )
  385. {
  386. return ERROR_INVALID_SYNTAX;
  387. }
  388. {
  389. GUID guid;
  390. CLSIDFromString(wszInterfaceName, &guid);
  391. if (dwAddSource == DHCP) {
  392. dwErr = IfIpSetDhcpModeMany(wszIfFriendlyName, &guid, REGISTER_UNCHANGED, TYPE_IPADDR) ;
  393. RETURN_ERROR_OKAY(dwErr);
  394. }
  395. else {
  396. if (dwBitVector&IFIP_ADDR_MASK) {
  397. dwErr = IfIpAddSetAddress(wszIfFriendlyName, &guid, pwszAddAddr, pwszAddMask, SET_FLAG);
  398. }
  399. if ( (dwBitVector&IFIP_GATEWAY_MASK) && (dwErr == NO_ERROR)) {
  400. dwErr = IfIpAddSetGateway(wszIfFriendlyName, &guid, pwszAddGateway, pwszAddGwmetric, SET_FLAG);
  401. RETURN_ERROR_OKAY(dwErr);
  402. }
  403. if (dwBitVector&IFIP_ADDR_MASK) {
  404. RETURN_ERROR_OKAY(dwErr);
  405. }
  406. if (!(dwBitVector&IFIP_ADDR_MASK) && !(dwBitVector&IFIP_GATEWAY_MASK)) {
  407. DisplayMessage(g_hModule, EMSG_STATIC_INPUT);
  408. return ERROR_SUPPRESS_OUTPUT;
  409. }
  410. }
  411. };
  412. RETURN_ERROR_OKAY(dwErr);
  413. }
  414. DWORD
  415. IfIpHandleSetDns(
  416. IN LPCWSTR pwszMachine,
  417. IN OUT LPWSTR *ppwcArguments,
  418. IN DWORD dwCurrentIndex,
  419. IN DWORD dwArgCount,
  420. IN DWORD dwFlags,
  421. IN LPCVOID pvData,
  422. OUT BOOL *pbDone
  423. )
  424. /*++
  425. Routine Description
  426. Arguments
  427. Return Value
  428. --*/
  429. {
  430. DWORD dwErr;
  431. dwErr = IfIpSetMany(
  432. ppwcArguments,
  433. dwCurrentIndex,
  434. dwArgCount,
  435. pbDone,
  436. TYPE_DNS
  437. );
  438. RETURN_ERROR_OKAY(dwErr);
  439. }
  440. DWORD
  441. IfIpHandleSetWins(
  442. IN LPCWSTR pwszMachine,
  443. IN OUT LPWSTR *ppwcArguments,
  444. IN DWORD dwCurrentIndex,
  445. IN DWORD dwArgCount,
  446. IN DWORD dwFlags,
  447. IN LPCVOID pvData,
  448. OUT BOOL *pbDone
  449. )
  450. /*++
  451. Routine Description
  452. Arguments
  453. Return Value
  454. --*/
  455. {
  456. DWORD dwErr;
  457. dwErr = IfIpSetMany(
  458. ppwcArguments,
  459. dwCurrentIndex,
  460. dwArgCount,
  461. pbDone,
  462. TYPE_WINS
  463. );
  464. RETURN_ERROR_OKAY(dwErr);
  465. }
  466. DWORD
  467. IfIpSetMany(
  468. IN PWCHAR *ppwcArguments,
  469. IN DWORD dwCurrentIndex,
  470. IN DWORD dwArgCount,
  471. IN BOOL *pbDone,
  472. IN DWORD Type
  473. )
  474. /*++
  475. Routine Description
  476. Arguments
  477. Return Value
  478. --*/
  479. {
  480. WCHAR wszInterfaceName[MAX_INTERFACE_NAME_LEN + 1] = L"\0";
  481. PWCHAR wszIfFriendlyName = NULL;
  482. DWORD dwBufferSize = sizeof(wszInterfaceName);
  483. DWORD dwErr = NO_ERROR,dwRes, dwErrIndex=-1;
  484. TAG_TYPE pttTags[] = {
  485. {TOKEN_NAME,FALSE,FALSE},
  486. {TOKEN_SOURCE,FALSE,FALSE},
  487. {TOKEN_ADDR,FALSE,FALSE},
  488. {TOKEN_REGISTER,FALSE,FALSE}};
  489. PDWORD pdwTagType;
  490. DWORD dwNumOpt, dwBitVector=0;
  491. DWORD dwNumArg, i, j;
  492. DWORD dwAddSource, dwAddAddr;
  493. DWORD dwRegisterMode = REGISTER_UNCHANGED;
  494. PWCHAR pwszAddAddr;
  495. // At least interface name,source should be specified.
  496. if (dwCurrentIndex +1 >= dwArgCount)
  497. {
  498. return ERROR_SHOW_USAGE;
  499. }
  500. dwNumArg = dwArgCount - dwCurrentIndex;
  501. pdwTagType = HeapAlloc(GetProcessHeap(),
  502. 0,
  503. dwNumArg * sizeof(DWORD));
  504. if (pdwTagType is NULL)
  505. {
  506. return ERROR_NOT_ENOUGH_MEMORY;
  507. }
  508. dwErr = MatchTagsInCmdLine(g_hModule,
  509. ppwcArguments,
  510. dwCurrentIndex,
  511. dwArgCount,
  512. pttTags,
  513. NUM_TAGS_IN_TABLE(pttTags),
  514. pdwTagType);
  515. if (dwErr isnot NO_ERROR)
  516. {
  517. IfutlFree(pdwTagType);
  518. if (dwErr is ERROR_INVALID_OPTION_TAG)
  519. {
  520. return ERROR_INVALID_SYNTAX;
  521. }
  522. return dwErr;
  523. }
  524. for ( i = 0; i < dwNumArg; i++)
  525. {
  526. switch (pdwTagType[i])
  527. {
  528. case 0 :
  529. {
  530. dwErr = GetIfNameFromFriendlyName(ppwcArguments[i + dwCurrentIndex],
  531. wszInterfaceName,&dwBufferSize);
  532. if (dwErr isnot NO_ERROR)
  533. {
  534. DisplayMessage(g_hModule, EMSG_INVALID_INTERFACE,
  535. ppwcArguments[i + dwCurrentIndex]);
  536. dwErr = ERROR_SUPPRESS_OUTPUT;
  537. break;
  538. }
  539. wszIfFriendlyName = ppwcArguments[i + dwCurrentIndex];
  540. dwBitVector |= IFIP_IFNAME_MASK;
  541. break;
  542. }
  543. case 1:
  544. {
  545. //
  546. // dhcp or static
  547. //
  548. TOKEN_VALUE rgEnums[] =
  549. {{TOKEN_VALUE_DHCP, DHCP},
  550. {TOKEN_VALUE_STATIC,STATIC}};
  551. dwErr = MatchEnumTag(g_hModule,
  552. ppwcArguments[i + dwCurrentIndex],
  553. NUM_TOKENS_IN_TABLE(rgEnums),
  554. rgEnums,
  555. &dwRes);
  556. if (dwErr != NO_ERROR)
  557. {
  558. dwErrIndex = i;
  559. i = dwNumArg;
  560. dwErr = ERROR_INVALID_PARAMETER;
  561. break;
  562. }
  563. dwAddSource = dwRes ;
  564. dwBitVector |= IFIP_SOURCE_MASK;
  565. //
  566. // If DHCP, then ADDR argument is not needed, so if the
  567. // syntax looks right (only one more argument), but we
  568. // classified the last argument as ADDR, then reclassify
  569. // it as REGISTER.
  570. //
  571. if ((dwRes == DHCP) && (i+2 == dwNumArg) && (pdwTagType[i+1] == 2))
  572. {
  573. pdwTagType[i+1] = 3;
  574. }
  575. break;
  576. }
  577. case 2:
  578. {
  579. //
  580. // dns/wins address
  581. //
  582. TOKEN_VALUE rgEnums[] =
  583. {{TOKEN_VALUE_NONE, NONE}};
  584. dwErr = MatchEnumTag(g_hModule,
  585. ppwcArguments[i + dwCurrentIndex],
  586. NUM_TOKENS_IN_TABLE(rgEnums),
  587. rgEnums,
  588. &dwRes);
  589. if (dwErr == NO_ERROR) {
  590. pwszAddAddr = NULL;
  591. }
  592. else {
  593. dwErr = GetIpAddress(ppwcArguments[i + dwCurrentIndex], &dwAddAddr);
  594. if((dwErr != NO_ERROR) or CHECK_UNICAST_IP_ADDR(dwAddAddr))
  595. {
  596. DispTokenErrMsg(g_hModule,
  597. EMSG_BAD_OPTION_VALUE,
  598. pttTags[pdwTagType[i]].pwszTag,
  599. ppwcArguments[i + dwCurrentIndex]);
  600. dwErr = ERROR_SUPPRESS_OUTPUT;
  601. break;
  602. }
  603. pwszAddAddr = ppwcArguments[i + dwCurrentIndex];
  604. }
  605. dwBitVector |= IFIP_ADDR_MASK;
  606. break;
  607. }
  608. case 3:
  609. {
  610. //
  611. // ddns enabled or disabled
  612. //
  613. TOKEN_VALUE rgEnums[] =
  614. {{TOKEN_VALUE_NONE, REGISTER_NONE},
  615. {TOKEN_VALUE_PRIMARY, REGISTER_PRIMARY},
  616. {TOKEN_VALUE_BOTH, REGISTER_BOTH}};
  617. dwErr = MatchEnumTag(g_hModule,
  618. ppwcArguments[i + dwCurrentIndex],
  619. NUM_TOKENS_IN_TABLE(rgEnums),
  620. rgEnums,
  621. &dwRes);
  622. if (dwErr != NO_ERROR)
  623. {
  624. dwErrIndex = i;
  625. i = dwNumArg;
  626. dwErr = ERROR_INVALID_PARAMETER;
  627. break;
  628. }
  629. dwRegisterMode = dwRes ;
  630. break;
  631. }
  632. default:
  633. {
  634. i = dwNumArg;
  635. dwErr = ERROR_INVALID_PARAMETER;
  636. break;
  637. }
  638. } //switch
  639. if (dwErr != NO_ERROR)
  640. break ;
  641. }
  642. switch(dwErr)
  643. {
  644. case NO_ERROR :
  645. break;
  646. case ERROR_INVALID_PARAMETER:
  647. if (dwErrIndex != -1)
  648. {
  649. DispTokenErrMsg(g_hModule,
  650. EMSG_BAD_OPTION_VALUE,
  651. pttTags[pdwTagType[dwErrIndex]].pwszTag,
  652. ppwcArguments[dwErrIndex + dwCurrentIndex]);
  653. dwErr = ERROR_SUPPRESS_OUTPUT;
  654. }
  655. break;
  656. default:
  657. // error message already printed
  658. break;
  659. }
  660. if (pdwTagType)
  661. IfutlFree(pdwTagType);
  662. if (dwErr != NO_ERROR)
  663. return dwErr;
  664. // interface name and source should be present
  665. if ( !(dwBitVector & IFIP_IFNAME_MASK)
  666. || (! (dwBitVector & IFIP_SOURCE_MASK))) {
  667. return ERROR_INVALID_SYNTAX;
  668. }
  669. if ( ((dwBitVector & IFIP_ADDR_MASK) && (dwAddSource != STATIC))
  670. ||(!(dwBitVector & IFIP_ADDR_MASK) && (dwAddSource == STATIC)) )
  671. {
  672. return ERROR_INVALID_SYNTAX;
  673. }
  674. {
  675. GUID guid;
  676. CLSIDFromString(wszInterfaceName, &guid);
  677. if (dwAddSource == DHCP) {
  678. return IfIpSetDhcpModeMany(wszIfFriendlyName, &guid, dwRegisterMode, Type) ;
  679. }
  680. else {
  681. return IfIpAddSetDelMany(wszIfFriendlyName, &guid, pwszAddAddr, 0, dwRegisterMode, Type, SET_FLAG);
  682. }
  683. }
  684. return dwErr;
  685. }
  686. DWORD
  687. IfIpHandleAddAddress(
  688. IN LPCWSTR pwszMachine,
  689. IN OUT LPWSTR *ppwcArguments,
  690. IN DWORD dwCurrentIndex,
  691. IN DWORD dwArgCount,
  692. IN DWORD dwFlags,
  693. IN LPCVOID pvData,
  694. OUT BOOL *pbDone
  695. )
  696. /*++
  697. Routine Description
  698. Arguments
  699. Return Value
  700. --*/
  701. {
  702. WCHAR wszInterfaceName[MAX_INTERFACE_NAME_LEN + 1] = L"\0";
  703. PWCHAR wszIfFriendlyName = NULL;
  704. DWORD dwBufferSize = sizeof(wszInterfaceName);
  705. DWORD dwErr = NO_ERROR,dwRes, dwErrIndex=-1;
  706. TAG_TYPE pttTags[] = {
  707. {TOKEN_NAME,FALSE,FALSE},
  708. {TOKEN_ADDR,FALSE,FALSE},
  709. {TOKEN_MASK,FALSE,FALSE},
  710. {TOKEN_GATEWAY,FALSE,FALSE},
  711. {TOKEN_GWMETRIC,FALSE,FALSE}};
  712. PDWORD pdwTagType;
  713. DWORD dwNumOpt, dwBitVector=0;
  714. DWORD dwNumArg, i, j;
  715. DWORD dwAddSource, dwAddAddr, dwAddMask, dwAddGateway, dwAddGwmetric;
  716. PWCHAR pwszAddAddr, pwszAddMask, pwszAddGateway, pwszAddGwmetric;
  717. if (dwCurrentIndex >= dwArgCount)
  718. {
  719. // No arguments specified. At least interface name should be specified.
  720. return ERROR_SHOW_USAGE;
  721. }
  722. dwNumArg = dwArgCount - dwCurrentIndex;
  723. pdwTagType = HeapAlloc(GetProcessHeap(),
  724. 0,
  725. dwNumArg * sizeof(DWORD));
  726. if (pdwTagType is NULL)
  727. {
  728. return ERROR_NOT_ENOUGH_MEMORY;
  729. }
  730. dwErr = MatchTagsInCmdLine(g_hModule,
  731. ppwcArguments,
  732. dwCurrentIndex,
  733. dwArgCount,
  734. pttTags,
  735. NUM_TAGS_IN_TABLE(pttTags),
  736. pdwTagType);
  737. if (dwErr isnot NO_ERROR)
  738. {
  739. IfutlFree(pdwTagType);
  740. if (dwErr is ERROR_INVALID_OPTION_TAG)
  741. {
  742. return ERROR_INVALID_SYNTAX;
  743. }
  744. return dwErr;
  745. }
  746. for ( i = 0; i < dwNumArg; i++)
  747. {
  748. switch (pdwTagType[i])
  749. {
  750. case 0 :
  751. {
  752. dwErr = GetIfNameFromFriendlyName(ppwcArguments[i + dwCurrentIndex],
  753. wszInterfaceName,&dwBufferSize);
  754. if (dwErr isnot NO_ERROR)
  755. {
  756. DisplayMessage(g_hModule, EMSG_INVALID_INTERFACE,
  757. ppwcArguments[i + dwCurrentIndex]);
  758. dwErr = ERROR_SUPPRESS_OUTPUT;
  759. break;
  760. }
  761. wszIfFriendlyName = ppwcArguments[i + dwCurrentIndex];
  762. dwBitVector |= IFIP_IFNAME_MASK;
  763. break;
  764. }
  765. case 1:
  766. {
  767. //
  768. // ip address for static
  769. //
  770. dwErr = GetIpAddress(ppwcArguments[i + dwCurrentIndex], &dwAddAddr);
  771. if((dwErr != NO_ERROR) or CHECK_UNICAST_IP_ADDR(dwAddAddr))
  772. {
  773. DispTokenErrMsg(g_hModule,
  774. EMSG_BAD_OPTION_VALUE,
  775. pttTags[pdwTagType[i]].pwszTag,
  776. ppwcArguments[i + dwCurrentIndex]);
  777. dwErr = ERROR_SUPPRESS_OUTPUT;
  778. break;
  779. }
  780. pwszAddAddr = ppwcArguments[i + dwCurrentIndex];
  781. dwBitVector |= IFIP_ADDR_MASK;
  782. break;
  783. }
  784. case 2:
  785. {
  786. //
  787. // get mask
  788. //
  789. dwErr = GetIpAddress(ppwcArguments[i + dwCurrentIndex], &dwAddAddr);
  790. if((dwErr != NO_ERROR) or CHECK_NETWORK_MASK(dwAddAddr))
  791. {
  792. DispTokenErrMsg(g_hModule,
  793. EMSG_BAD_OPTION_VALUE,
  794. pttTags[pdwTagType[i]].pwszTag,
  795. ppwcArguments[i + dwCurrentIndex]);
  796. dwErr = ERROR_SUPPRESS_OUTPUT;
  797. break;
  798. }
  799. pwszAddMask = ppwcArguments[i + dwCurrentIndex];
  800. dwBitVector |= IFIP_MASK_MASK;
  801. break;
  802. }
  803. case 3:
  804. {
  805. //
  806. // get default gateway addr
  807. //
  808. dwErr = GetIpAddress(ppwcArguments[i + dwCurrentIndex],
  809. &dwAddAddr);
  810. if((dwErr != NO_ERROR) or CHECK_UNICAST_IP_ADDR(dwAddAddr))
  811. {
  812. DispTokenErrMsg(g_hModule,
  813. EMSG_BAD_OPTION_VALUE,
  814. pttTags[pdwTagType[i]].pwszTag,
  815. ppwcArguments[i + dwCurrentIndex]);
  816. dwErr = ERROR_SUPPRESS_OUTPUT;
  817. break;
  818. }
  819. pwszAddGateway = ppwcArguments[i + dwCurrentIndex];
  820. dwBitVector |= IFIP_GATEWAY_MASK;
  821. break;
  822. }
  823. case 4:
  824. {
  825. //
  826. // gwmetric
  827. //
  828. dwAddGwmetric =
  829. _tcstoul(ppwcArguments[i + dwCurrentIndex], NULL, 10);
  830. if ( dwAddGwmetric > 9999 )
  831. {
  832. dwErrIndex = i;
  833. dwErr = ERROR_INVALID_PARAMETER;
  834. i = dwNumArg;
  835. break;
  836. }
  837. pwszAddGwmetric = ppwcArguments[i + dwCurrentIndex];
  838. dwBitVector |= IFIP_GWMETRIC_MASK;
  839. break;
  840. }
  841. default:
  842. {
  843. i = dwNumArg;
  844. dwErr = ERROR_INVALID_PARAMETER;
  845. break;
  846. }
  847. } //switch
  848. if (dwErr != NO_ERROR)
  849. break ;
  850. }
  851. // interface name should be present
  852. if (!pttTags[0].bPresent)
  853. {
  854. dwErr = ERROR_INVALID_SYNTAX;
  855. }
  856. switch(dwErr)
  857. {
  858. case NO_ERROR :
  859. break;
  860. case ERROR_INVALID_PARAMETER:
  861. if (dwErrIndex != -1)
  862. {
  863. DispTokenErrMsg(g_hModule,
  864. EMSG_BAD_OPTION_VALUE,
  865. pttTags[pdwTagType[dwErrIndex]].pwszTag,
  866. ppwcArguments[dwErrIndex + dwCurrentIndex]);
  867. dwErr = ERROR_SUPPRESS_OUTPUT;
  868. }
  869. break;
  870. default:
  871. // error message already printed
  872. break;
  873. }
  874. if (pdwTagType)
  875. IfutlFree(pdwTagType);
  876. if (dwErr != NO_ERROR)
  877. return dwErr;
  878. // interface name should be present
  879. if ( !(dwBitVector & IFIP_IFNAME_MASK) ) {
  880. return ERROR_INVALID_SYNTAX;
  881. }
  882. if (( (dwBitVector&IFIP_ADDR_MASK) && !(dwBitVector&IFIP_MASK_MASK) )
  883. ||( !(dwBitVector&IFIP_ADDR_MASK) && (dwBitVector&IFIP_MASK_MASK) )
  884. ||( (dwBitVector&IFIP_GATEWAY_MASK) && !(dwBitVector&IFIP_GWMETRIC_MASK) )
  885. ||( !(dwBitVector&IFIP_GATEWAY_MASK) && (dwBitVector&IFIP_GWMETRIC_MASK) )
  886. )
  887. {
  888. return ERROR_INVALID_SYNTAX;
  889. }
  890. {
  891. GUID guid;
  892. if (FAILED(CLSIDFromString(wszInterfaceName, &guid))) {
  893. return ERROR_INVALID_PARAMETER;
  894. }
  895. if (dwBitVector&IFIP_ADDR_MASK) {
  896. dwErr = IfIpAddSetAddress(wszIfFriendlyName, &guid, pwszAddAddr, pwszAddMask, ADD_FLAG);
  897. }
  898. if ( (dwBitVector&IFIP_GATEWAY_MASK) && (dwErr == NO_ERROR)) {
  899. dwErr = IfIpAddSetGateway(wszIfFriendlyName, &guid, pwszAddGateway, pwszAddGwmetric, ADD_FLAG);
  900. RETURN_ERROR_OKAY(dwErr);
  901. }
  902. if (dwBitVector&IFIP_ADDR_MASK) {
  903. RETURN_ERROR_OKAY(dwErr);
  904. }
  905. if (!(dwBitVector&IFIP_ADDR_MASK) && !(dwBitVector&IFIP_GATEWAY_MASK)) {
  906. DisplayMessage(g_hModule, EMSG_STATIC_INPUT);
  907. return ERROR_SUPPRESS_OUTPUT;
  908. }
  909. }
  910. RETURN_ERROR_OKAY(dwErr);
  911. }
  912. DWORD
  913. IfIpHandleAddDns(
  914. IN LPCWSTR pwszMachine,
  915. IN OUT LPWSTR *ppwcArguments,
  916. IN DWORD dwCurrentIndex,
  917. IN DWORD dwArgCount,
  918. IN DWORD dwFlags,
  919. IN LPCVOID pvData,
  920. OUT BOOL *pbDone
  921. )
  922. /*++
  923. Routine Description
  924. Arguments
  925. Return Value
  926. --*/
  927. {
  928. DWORD dwErr;
  929. dwErr = IfIpAddMany(
  930. ppwcArguments,
  931. dwCurrentIndex,
  932. dwArgCount,
  933. pbDone,
  934. TYPE_DNS
  935. );
  936. RETURN_ERROR_OKAY(dwErr);
  937. }
  938. DWORD
  939. IfIpHandleAddWins(
  940. IN LPCWSTR pwszMachine,
  941. IN OUT LPWSTR *ppwcArguments,
  942. IN DWORD dwCurrentIndex,
  943. IN DWORD dwArgCount,
  944. IN DWORD dwFlags,
  945. IN LPCVOID pvData,
  946. OUT BOOL *pbDone
  947. )
  948. /*++
  949. Routine Description
  950. Arguments
  951. Return Value
  952. --*/
  953. {
  954. DWORD dwErr;
  955. dwErr = IfIpAddMany(
  956. ppwcArguments,
  957. dwCurrentIndex,
  958. dwArgCount,
  959. pbDone,
  960. TYPE_WINS
  961. );
  962. RETURN_ERROR_OKAY(dwErr);
  963. }
  964. DWORD
  965. IfIpAddMany(
  966. IN PWCHAR *ppwcArguments,
  967. IN DWORD dwCurrentIndex,
  968. IN DWORD dwArgCount,
  969. IN BOOL *pbDone,
  970. IN DWORD Type
  971. )
  972. /*++
  973. Routine Description
  974. Arguments
  975. Return Value
  976. --*/
  977. {
  978. WCHAR wszInterfaceName[MAX_INTERFACE_NAME_LEN + 1] = L"\0";
  979. PWCHAR wszIfFriendlyName = NULL;
  980. DWORD dwBufferSize = sizeof(wszInterfaceName);
  981. DWORD dwErr = NO_ERROR,dwRes, dwErrIndex=-1;
  982. TAG_TYPE pttTags[] = {
  983. {TOKEN_NAME,FALSE,FALSE},
  984. {TOKEN_ADDR,FALSE,FALSE},
  985. {TOKEN_INDEX,FALSE,FALSE}};
  986. PDWORD pdwTagType;
  987. DWORD dwNumOpt, dwBitVector=0;
  988. DWORD dwNumArg, i, j;
  989. DWORD dwAddSource, dwAddAddr, dwAddIndex=~(0);
  990. PWCHAR pwszAddAddr;
  991. // At least interface name/new address should be specified.
  992. if (dwCurrentIndex +1 >= dwArgCount)
  993. {
  994. return ERROR_SHOW_USAGE;
  995. }
  996. dwNumArg = dwArgCount - dwCurrentIndex;
  997. pdwTagType = HeapAlloc(GetProcessHeap(),
  998. 0,
  999. dwNumArg * sizeof(DWORD));
  1000. if (pdwTagType is NULL)
  1001. {
  1002. return ERROR_NOT_ENOUGH_MEMORY;
  1003. }
  1004. dwErr = MatchTagsInCmdLine(g_hModule,
  1005. ppwcArguments,
  1006. dwCurrentIndex,
  1007. dwArgCount,
  1008. pttTags,
  1009. NUM_TAGS_IN_TABLE(pttTags),
  1010. pdwTagType);
  1011. if (dwErr isnot NO_ERROR)
  1012. {
  1013. IfutlFree(pdwTagType);
  1014. if (dwErr is ERROR_INVALID_OPTION_TAG)
  1015. {
  1016. return ERROR_INVALID_SYNTAX;
  1017. }
  1018. return dwErr;
  1019. }
  1020. for ( i = 0; i < dwNumArg; i++)
  1021. {
  1022. switch (pdwTagType[i])
  1023. {
  1024. case 0 :
  1025. {
  1026. dwErr = GetIfNameFromFriendlyName(ppwcArguments[i + dwCurrentIndex],
  1027. wszInterfaceName,&dwBufferSize);
  1028. if (dwErr isnot NO_ERROR)
  1029. {
  1030. DisplayMessage(g_hModule, EMSG_INVALID_INTERFACE,
  1031. ppwcArguments[i + dwCurrentIndex]);
  1032. dwErr = ERROR_SUPPRESS_OUTPUT;
  1033. break;
  1034. }
  1035. wszIfFriendlyName = ppwcArguments[i + dwCurrentIndex];
  1036. dwBitVector |= IFIP_IFNAME_MASK;
  1037. break;
  1038. }
  1039. case 1:
  1040. {
  1041. //
  1042. // dns/wins address
  1043. //
  1044. dwErr = GetIpAddress(ppwcArguments[i + dwCurrentIndex], &dwAddAddr);
  1045. if((dwErr != NO_ERROR) or CHECK_UNICAST_IP_ADDR(dwAddAddr))
  1046. {
  1047. DispTokenErrMsg(g_hModule,
  1048. EMSG_BAD_OPTION_VALUE,
  1049. pttTags[pdwTagType[i]].pwszTag,
  1050. ppwcArguments[i + dwCurrentIndex]);
  1051. dwErr = ERROR_SUPPRESS_OUTPUT;
  1052. break;
  1053. }
  1054. pwszAddAddr = ppwcArguments[i + dwCurrentIndex];
  1055. dwBitVector |= IFIP_ADDR_MASK;
  1056. break;
  1057. }
  1058. case 2:
  1059. {
  1060. //
  1061. // index
  1062. //
  1063. dwAddIndex =
  1064. _tcstoul(ppwcArguments[i + dwCurrentIndex], NULL, 10);
  1065. if ( (dwAddIndex <= 0 || dwAddIndex > 999) )
  1066. {
  1067. dwErrIndex = i;
  1068. dwErr = ERROR_INVALID_PARAMETER;
  1069. i = dwNumArg;
  1070. break;
  1071. }
  1072. dwBitVector |= IFIP_INDEX_MASK;
  1073. break;
  1074. }
  1075. default:
  1076. {
  1077. i = dwNumArg;
  1078. dwErr = ERROR_INVALID_PARAMETER;
  1079. break;
  1080. }
  1081. } //switch
  1082. if (dwErr != NO_ERROR)
  1083. break ;
  1084. }
  1085. switch(dwErr)
  1086. {
  1087. case NO_ERROR :
  1088. break;
  1089. case ERROR_INVALID_PARAMETER:
  1090. if (dwErrIndex != -1)
  1091. {
  1092. DispTokenErrMsg(g_hModule,
  1093. EMSG_BAD_OPTION_VALUE,
  1094. pttTags[pdwTagType[dwErrIndex]].pwszTag,
  1095. ppwcArguments[dwErrIndex + dwCurrentIndex]);
  1096. dwErr = ERROR_SUPPRESS_OUTPUT;
  1097. }
  1098. break;
  1099. default:
  1100. // error message already printed
  1101. break;
  1102. }
  1103. if (pdwTagType)
  1104. IfutlFree(pdwTagType);
  1105. if (dwErr != NO_ERROR)
  1106. return dwErr;
  1107. // interface name and new address should be present
  1108. if ( !(dwBitVector & IFIP_IFNAME_MASK)
  1109. || (! (dwBitVector & IFIP_ADDR_MASK))) {
  1110. return ERROR_INVALID_SYNTAX;
  1111. }
  1112. {
  1113. GUID guid;
  1114. CLSIDFromString(wszInterfaceName, &guid);
  1115. return IfIpAddSetDelMany(wszIfFriendlyName, &guid, pwszAddAddr, dwAddIndex, REGISTER_UNCHANGED, Type, ADD_FLAG);
  1116. }
  1117. return dwErr;
  1118. }
  1119. DWORD
  1120. IfIpHandleDelAddress(
  1121. IN LPCWSTR pwszMachine,
  1122. IN OUT LPWSTR *ppwcArguments,
  1123. IN DWORD dwCurrentIndex,
  1124. IN DWORD dwArgCount,
  1125. IN DWORD dwFlags,
  1126. IN LPCVOID pvData,
  1127. OUT BOOL *pbDone
  1128. )
  1129. /*++
  1130. Routine Description
  1131. Arguments
  1132. Return Value
  1133. --*/
  1134. {
  1135. WCHAR wszInterfaceName[MAX_INTERFACE_NAME_LEN + 1] = L"\0";
  1136. PWCHAR wszIfFriendlyName = NULL;
  1137. DWORD dwBufferSize = sizeof(wszInterfaceName);
  1138. DWORD dwErr = NO_ERROR,dwRes, dwErrIndex=-1;
  1139. TAG_TYPE pttTags[] = {
  1140. {TOKEN_NAME,FALSE,FALSE},
  1141. {TOKEN_ADDR,FALSE,FALSE},
  1142. {TOKEN_GATEWAY,FALSE,FALSE}};
  1143. PDWORD pdwTagType;
  1144. DWORD dwNumOpt, dwBitVector=0;
  1145. DWORD dwNumArg, i, j, Flags = 0;
  1146. PWCHAR pwszDelAddr=NULL, pwszDelGateway=NULL;
  1147. // At least interface name and ipaddr/gateway should be specified.
  1148. if (dwCurrentIndex + 1 >= dwArgCount)
  1149. {
  1150. return ERROR_SHOW_USAGE;
  1151. }
  1152. dwNumArg = dwArgCount - dwCurrentIndex;
  1153. pdwTagType = HeapAlloc(GetProcessHeap(),
  1154. 0,
  1155. dwNumArg * sizeof(DWORD));
  1156. if (pdwTagType is NULL)
  1157. {
  1158. return ERROR_NOT_ENOUGH_MEMORY;
  1159. }
  1160. dwErr = MatchTagsInCmdLine(g_hModule,
  1161. ppwcArguments,
  1162. dwCurrentIndex,
  1163. dwArgCount,
  1164. pttTags,
  1165. NUM_TAGS_IN_TABLE(pttTags),
  1166. pdwTagType);
  1167. if (dwErr isnot NO_ERROR)
  1168. {
  1169. IfutlFree(pdwTagType);
  1170. if (dwErr is ERROR_INVALID_OPTION_TAG)
  1171. {
  1172. return ERROR_INVALID_SYNTAX;
  1173. }
  1174. return dwErr;
  1175. }
  1176. for ( i = 0; i < dwNumArg; i++)
  1177. {
  1178. switch (pdwTagType[i])
  1179. {
  1180. case 0 :
  1181. {
  1182. // get IfName
  1183. dwErr = GetIfNameFromFriendlyName(ppwcArguments[i + dwCurrentIndex],
  1184. wszInterfaceName,&dwBufferSize);
  1185. if (dwErr isnot NO_ERROR)
  1186. {
  1187. DisplayMessage(g_hModule, EMSG_INVALID_INTERFACE,
  1188. ppwcArguments[i + dwCurrentIndex]);
  1189. dwErr = ERROR_SUPPRESS_OUTPUT;
  1190. break;
  1191. }
  1192. wszIfFriendlyName = ppwcArguments[i + dwCurrentIndex];
  1193. dwBitVector |= IFIP_IFNAME_MASK;
  1194. break;
  1195. }
  1196. case 1:
  1197. {
  1198. //
  1199. // ip address for static
  1200. //
  1201. ULONG dwDelAddr;
  1202. dwErr = GetIpAddress(ppwcArguments[i + dwCurrentIndex],
  1203. &dwDelAddr);
  1204. if((dwErr != NO_ERROR) or CHECK_UNICAST_IP_ADDR(dwDelAddr))
  1205. {
  1206. DispTokenErrMsg(g_hModule,
  1207. EMSG_BAD_OPTION_VALUE,
  1208. pttTags[pdwTagType[i]].pwszTag,
  1209. ppwcArguments[i + dwCurrentIndex]);
  1210. dwErr = ERROR_SUPPRESS_OUTPUT;
  1211. break;
  1212. }
  1213. pwszDelAddr = ppwcArguments[i + dwCurrentIndex];
  1214. dwBitVector |= IFIP_ADDR_MASK;
  1215. Flags |= TYPE_ADDR;
  1216. break;
  1217. }
  1218. case 2:
  1219. {
  1220. //
  1221. // get default gateway addr
  1222. //
  1223. ULONG dwDelGateway;
  1224. TOKEN_VALUE rgEnums[] =
  1225. {{TOKEN_VALUE_ALL, ALL}};
  1226. dwErr = MatchEnumTag(g_hModule,
  1227. ppwcArguments[i + dwCurrentIndex],
  1228. NUM_TOKENS_IN_TABLE(rgEnums),
  1229. rgEnums,
  1230. &dwRes);
  1231. if (dwErr == NO_ERROR) {
  1232. pwszDelGateway = NULL;
  1233. }
  1234. else {
  1235. dwErr = NO_ERROR;
  1236. dwErr = GetIpAddress(ppwcArguments[i + dwCurrentIndex],
  1237. &dwDelGateway);
  1238. if((dwErr != NO_ERROR) or CHECK_UNICAST_IP_ADDR(dwDelGateway))
  1239. {
  1240. DispTokenErrMsg(g_hModule,
  1241. EMSG_BAD_OPTION_VALUE,
  1242. pttTags[pdwTagType[i]].pwszTag,
  1243. ppwcArguments[i + dwCurrentIndex]);
  1244. dwErr = ERROR_SUPPRESS_OUTPUT;
  1245. break;
  1246. }
  1247. pwszDelGateway = ppwcArguments[i + dwCurrentIndex];
  1248. }
  1249. dwBitVector |= IFIP_GATEWAY_MASK;
  1250. Flags |= TYPE_GATEWAY;
  1251. break;
  1252. }
  1253. default:
  1254. {
  1255. i = dwNumArg;
  1256. dwErr = ERROR_INVALID_PARAMETER;
  1257. break;
  1258. }
  1259. } //switch
  1260. if (dwErr != NO_ERROR)
  1261. break ;
  1262. }
  1263. switch(dwErr)
  1264. {
  1265. case NO_ERROR :
  1266. break;
  1267. case ERROR_INVALID_PARAMETER:
  1268. if (dwErrIndex != -1)
  1269. {
  1270. DispTokenErrMsg(g_hModule,
  1271. EMSG_BAD_OPTION_VALUE,
  1272. pttTags[pdwTagType[dwErrIndex]].pwszTag,
  1273. ppwcArguments[dwErrIndex + dwCurrentIndex]);
  1274. dwErr = ERROR_SUPPRESS_OUTPUT;
  1275. }
  1276. break;
  1277. default:
  1278. // error message already printed
  1279. break;
  1280. }
  1281. if (pdwTagType)
  1282. IfutlFree(pdwTagType);
  1283. if (dwErr != NO_ERROR)
  1284. return dwErr;
  1285. // interface name and addr/all should be present
  1286. if ( !(dwBitVector & IFIP_IFNAME_MASK)
  1287. || !(dwBitVector & (IFIP_GATEWAY_MASK | IFIP_ADDR_MASK))
  1288. ) {
  1289. return ERROR_INVALID_SYNTAX;
  1290. }
  1291. {
  1292. GUID guid;
  1293. CLSIDFromString(wszInterfaceName, &guid);
  1294. dwErr = IfIpHandleDelIpaddrEx(wszIfFriendlyName, &guid, pwszDelAddr, pwszDelGateway, Flags);
  1295. RETURN_ERROR_OKAY(dwErr);
  1296. }
  1297. RETURN_ERROR_OKAY(dwErr);
  1298. }
  1299. DWORD
  1300. IfIpHandleDelDns(
  1301. IN LPCWSTR pwszMachine,
  1302. IN OUT LPWSTR *ppwcArguments,
  1303. IN DWORD dwCurrentIndex,
  1304. IN DWORD dwArgCount,
  1305. IN DWORD dwFlags,
  1306. IN LPCVOID pvData,
  1307. OUT BOOL *pbDone
  1308. )
  1309. /*++
  1310. Routine Description
  1311. Arguments
  1312. Return Value
  1313. --*/
  1314. {
  1315. DWORD dwErr;
  1316. dwErr = IfIpDelMany(
  1317. ppwcArguments,
  1318. dwCurrentIndex,
  1319. dwArgCount,
  1320. pbDone,
  1321. TYPE_DNS
  1322. );
  1323. RETURN_ERROR_OKAY(dwErr);
  1324. }
  1325. DWORD
  1326. IfIpHandleDelWins(
  1327. IN LPCWSTR pwszMachine,
  1328. IN OUT LPWSTR *ppwcArguments,
  1329. IN DWORD dwCurrentIndex,
  1330. IN DWORD dwArgCount,
  1331. IN DWORD dwFlags,
  1332. IN LPCVOID pvData,
  1333. OUT BOOL *pbDone
  1334. )
  1335. /*++
  1336. Routine Description
  1337. Arguments
  1338. Return Value
  1339. --*/
  1340. {
  1341. DWORD dwErr;
  1342. dwErr = IfIpDelMany(
  1343. ppwcArguments,
  1344. dwCurrentIndex,
  1345. dwArgCount,
  1346. pbDone,
  1347. TYPE_WINS
  1348. );
  1349. RETURN_ERROR_OKAY(dwErr);
  1350. }
  1351. DWORD
  1352. IfIpDelMany(
  1353. IN PWCHAR *ppwcArguments,
  1354. IN DWORD dwCurrentIndex,
  1355. IN DWORD dwArgCount,
  1356. IN BOOL *pbDone,
  1357. IN DISPLAY_TYPE Type
  1358. )
  1359. /*++
  1360. Routine Description
  1361. Arguments
  1362. Return Value
  1363. --*/
  1364. {
  1365. WCHAR wszInterfaceName[MAX_INTERFACE_NAME_LEN + 1] = L"\0";
  1366. PWCHAR wszIfFriendlyName = NULL;
  1367. DWORD dwBufferSize = sizeof(wszInterfaceName);
  1368. DWORD dwErr = NO_ERROR,dwRes, dwErrIndex=-1;
  1369. TAG_TYPE pttTags[] = {
  1370. {TOKEN_NAME,FALSE,FALSE},
  1371. {TOKEN_ADDR,FALSE,FALSE}};
  1372. PDWORD pdwTagType;
  1373. DWORD dwNumOpt, dwBitVector=0;
  1374. DWORD dwNumArg, i, j;
  1375. PWCHAR pwszDelAddr=NULL;
  1376. // At least interface name/address should be specified.
  1377. if (dwCurrentIndex +1 >= dwArgCount)
  1378. {
  1379. return ERROR_SHOW_USAGE;
  1380. }
  1381. dwNumArg = dwArgCount - dwCurrentIndex;
  1382. pdwTagType = HeapAlloc(GetProcessHeap(),
  1383. 0,
  1384. dwNumArg * sizeof(DWORD));
  1385. if (pdwTagType is NULL)
  1386. {
  1387. return ERROR_NOT_ENOUGH_MEMORY;
  1388. }
  1389. dwErr = MatchTagsInCmdLine(g_hModule,
  1390. ppwcArguments,
  1391. dwCurrentIndex,
  1392. dwArgCount,
  1393. pttTags,
  1394. NUM_TAGS_IN_TABLE(pttTags),
  1395. pdwTagType);
  1396. if (dwErr isnot NO_ERROR)
  1397. {
  1398. IfutlFree(pdwTagType);
  1399. if (dwErr is ERROR_INVALID_OPTION_TAG)
  1400. {
  1401. return ERROR_INVALID_SYNTAX;
  1402. }
  1403. return dwErr;
  1404. }
  1405. for ( i = 0; i < dwNumArg; i++)
  1406. {
  1407. switch (pdwTagType[i])
  1408. {
  1409. case 0 :
  1410. {
  1411. // get IfName
  1412. dwErr = GetIfNameFromFriendlyName(ppwcArguments[i + dwCurrentIndex],
  1413. wszInterfaceName,&dwBufferSize);
  1414. if (dwErr isnot NO_ERROR)
  1415. {
  1416. DisplayMessage(g_hModule, EMSG_INVALID_INTERFACE,
  1417. ppwcArguments[i + dwCurrentIndex]);
  1418. dwErr = ERROR_SUPPRESS_OUTPUT;
  1419. break;
  1420. }
  1421. wszIfFriendlyName = ppwcArguments[i + dwCurrentIndex];
  1422. dwBitVector |= IFIP_IFNAME_MASK;
  1423. break;
  1424. }
  1425. case 1:
  1426. {
  1427. //
  1428. // address
  1429. //
  1430. ULONG dwDelAddr;
  1431. TOKEN_VALUE rgEnums[] =
  1432. {{TOKEN_VALUE_ALL, ALL}};
  1433. dwErr = MatchEnumTag(g_hModule,
  1434. ppwcArguments[i + dwCurrentIndex],
  1435. NUM_TOKENS_IN_TABLE(rgEnums),
  1436. rgEnums,
  1437. &dwRes);
  1438. if (dwErr == NO_ERROR) {
  1439. pwszDelAddr = NULL;
  1440. }
  1441. else {
  1442. dwErr = GetIpAddress(ppwcArguments[i + dwCurrentIndex], &dwDelAddr);
  1443. if((dwErr != NO_ERROR) or CHECK_UNICAST_IP_ADDR(dwDelAddr))
  1444. {
  1445. DispTokenErrMsg(g_hModule,
  1446. EMSG_BAD_OPTION_VALUE,
  1447. pttTags[pdwTagType[i]].pwszTag,
  1448. ppwcArguments[i + dwCurrentIndex]);
  1449. dwErr = ERROR_SUPPRESS_OUTPUT;
  1450. break;
  1451. }
  1452. pwszDelAddr = ppwcArguments[i + dwCurrentIndex];
  1453. }
  1454. dwBitVector |= IFIP_ADDR_MASK;
  1455. break;
  1456. }
  1457. default:
  1458. {
  1459. i = dwNumArg;
  1460. dwErr = ERROR_INVALID_PARAMETER;
  1461. break;
  1462. }
  1463. } //switch
  1464. if (dwErr != NO_ERROR)
  1465. break ;
  1466. }
  1467. switch(dwErr)
  1468. {
  1469. case NO_ERROR :
  1470. break;
  1471. case ERROR_INVALID_PARAMETER:
  1472. if (dwErrIndex != -1)
  1473. {
  1474. DispTokenErrMsg(g_hModule,
  1475. EMSG_BAD_OPTION_VALUE,
  1476. pttTags[pdwTagType[dwErrIndex]].pwszTag,
  1477. ppwcArguments[dwErrIndex + dwCurrentIndex]);
  1478. dwErr = ERROR_SUPPRESS_OUTPUT;
  1479. }
  1480. break;
  1481. default:
  1482. // error message already printed
  1483. break;
  1484. }
  1485. if (pdwTagType)
  1486. IfutlFree(pdwTagType);
  1487. if (dwErr != NO_ERROR)
  1488. return dwErr;
  1489. // interface name and address should be present
  1490. if ( !(dwBitVector & IFIP_IFNAME_MASK)
  1491. || !(dwBitVector & IFIP_ADDR_MASK)) {
  1492. return ERROR_INVALID_SYNTAX;
  1493. }
  1494. {
  1495. GUID guid;
  1496. CLSIDFromString(wszInterfaceName, &guid);
  1497. return IfIpAddSetDelMany(wszIfFriendlyName, &guid, pwszDelAddr, 0, REGISTER_UNCHANGED, Type, DEL_FLAG);
  1498. }
  1499. }
  1500. DWORD
  1501. IfIpHandleShowAddress(
  1502. IN LPCWSTR pwszMachine,
  1503. IN OUT LPWSTR *ppwcArguments,
  1504. IN DWORD dwCurrentIndex,
  1505. IN DWORD dwArgCount,
  1506. IN DWORD dwFlags,
  1507. IN LPCVOID pvData,
  1508. OUT BOOL *pbDone
  1509. )
  1510. /*++
  1511. Routine Description
  1512. Arguments
  1513. Return Value
  1514. --*/
  1515. {
  1516. return IfIpShowMany(
  1517. pwszMachine,
  1518. ppwcArguments,
  1519. dwCurrentIndex,
  1520. dwArgCount,
  1521. pbDone,
  1522. TYPE_IPADDR
  1523. );
  1524. }
  1525. DWORD
  1526. IfIpHandleShowConfig(
  1527. IN LPCWSTR pwszMachine,
  1528. IN OUT LPWSTR *ppwcArguments,
  1529. IN DWORD dwCurrentIndex,
  1530. IN DWORD dwArgCount,
  1531. IN DWORD dwFlags,
  1532. IN LPCVOID pvData,
  1533. OUT BOOL *pbDone
  1534. )
  1535. /*++
  1536. Routine Description
  1537. Arguments
  1538. Return Value
  1539. --*/
  1540. {
  1541. return IfIpShowMany(
  1542. pwszMachine,
  1543. ppwcArguments,
  1544. dwCurrentIndex,
  1545. dwArgCount,
  1546. pbDone,
  1547. TYPE_IP_ALL
  1548. );
  1549. }
  1550. DWORD
  1551. IfIpHandleShowOffload(
  1552. IN LPCWSTR pwszMachine,
  1553. IN OUT LPWSTR *ppwcArguments,
  1554. IN DWORD dwCurrentIndex,
  1555. IN DWORD dwArgCount,
  1556. IN DWORD dwFlags,
  1557. IN LPCVOID pvData,
  1558. OUT BOOL *pbDone
  1559. )
  1560. /*++
  1561. Routine Description
  1562. Arguments
  1563. Return Value
  1564. --*/
  1565. {
  1566. return IfIpShowMany(
  1567. pwszMachine,
  1568. ppwcArguments,
  1569. dwCurrentIndex,
  1570. dwArgCount,
  1571. pbDone,
  1572. TYPE_OFFLOAD
  1573. );
  1574. }
  1575. DWORD
  1576. IfIpHandleShowDns(
  1577. IN LPCWSTR pwszMachine,
  1578. IN OUT LPWSTR *ppwcArguments,
  1579. IN DWORD dwCurrentIndex,
  1580. IN DWORD dwArgCount,
  1581. IN DWORD dwFlags,
  1582. IN LPCVOID pvData,
  1583. OUT BOOL *pbDone
  1584. )
  1585. /*++
  1586. Routine Description
  1587. Arguments
  1588. Return Value
  1589. --*/
  1590. {
  1591. return IfIpShowMany(
  1592. pwszMachine,
  1593. ppwcArguments,
  1594. dwCurrentIndex,
  1595. dwArgCount,
  1596. pbDone,
  1597. TYPE_DNS
  1598. );
  1599. }
  1600. DWORD
  1601. IfIpHandleShowWins(
  1602. IN LPCWSTR pwszMachine,
  1603. IN OUT LPWSTR *ppwcArguments,
  1604. IN DWORD dwCurrentIndex,
  1605. IN DWORD dwArgCount,
  1606. IN DWORD dwFlags,
  1607. IN LPCVOID pvData,
  1608. OUT BOOL *pbDone
  1609. )
  1610. /*++
  1611. Routine Description
  1612. Arguments
  1613. Return Value
  1614. --*/
  1615. {
  1616. return IfIpShowMany(
  1617. pwszMachine,
  1618. ppwcArguments,
  1619. dwCurrentIndex,
  1620. dwArgCount,
  1621. pbDone,
  1622. TYPE_WINS
  1623. );
  1624. }
  1625. DWORD
  1626. IfIpShowMany(
  1627. IN LPCWSTR pwszMachineName,
  1628. IN PWCHAR *ppwcArguments,
  1629. IN DWORD dwCurrentIndex,
  1630. IN DWORD dwArgCount,
  1631. IN BOOL *pbDone,
  1632. IN DISPLAY_TYPE dtType
  1633. )
  1634. /*++
  1635. Routine Description
  1636. Arguments
  1637. Return Value
  1638. --*/
  1639. {
  1640. DWORD dwErr = NO_ERROR;
  1641. ULONG Flags = 0, IfIndex;
  1642. WCHAR wszInterfaceName[MAX_INTERFACE_NAME_LEN + 1] = L"\0";
  1643. PWCHAR wszIfFriendlyName = NULL;
  1644. DWORD dwBufferSize = sizeof(wszInterfaceName);
  1645. TAG_TYPE pttTags[] = {
  1646. {TOKEN_NAME,FALSE,FALSE}};
  1647. PDWORD pdwTagType;
  1648. DWORD dwNumOpt, dwBitVector=0;
  1649. DWORD dwNumArg, i;
  1650. BOOLEAN bAll = FALSE;
  1651. //
  1652. // get interface friendly name
  1653. //
  1654. if (dwCurrentIndex > dwArgCount)
  1655. {
  1656. // No arguments specified. At least interface name should be specified.
  1657. return ERROR_SHOW_USAGE;
  1658. }
  1659. else if (dwCurrentIndex == dwArgCount)
  1660. {
  1661. // show for all interfaces
  1662. bAll = TRUE;
  1663. }
  1664. else {
  1665. dwNumArg = dwArgCount - dwCurrentIndex;
  1666. pdwTagType = HeapAlloc(GetProcessHeap(),
  1667. 0,
  1668. dwNumArg * sizeof(DWORD));
  1669. if (pdwTagType is NULL)
  1670. {
  1671. return ERROR_NOT_ENOUGH_MEMORY;
  1672. }
  1673. dwErr = MatchTagsInCmdLine(g_hModule,
  1674. ppwcArguments,
  1675. dwCurrentIndex,
  1676. dwArgCount,
  1677. pttTags,
  1678. NUM_TAGS_IN_TABLE(pttTags),
  1679. pdwTagType);
  1680. if (dwErr isnot NO_ERROR)
  1681. {
  1682. IfutlFree(pdwTagType);
  1683. if (dwErr is ERROR_INVALID_OPTION_TAG)
  1684. {
  1685. return ERROR_INVALID_SYNTAX;
  1686. }
  1687. return dwErr;
  1688. }
  1689. for ( i = 0; i < dwNumArg; i++)
  1690. {
  1691. switch (pdwTagType[i])
  1692. {
  1693. case 0 :
  1694. {
  1695. dwErr = GetIfNameFromFriendlyName(ppwcArguments[i + dwCurrentIndex],
  1696. wszInterfaceName,&dwBufferSize);
  1697. if (dwErr isnot NO_ERROR)
  1698. {
  1699. DisplayMessage(g_hModule, EMSG_INVALID_INTERFACE,
  1700. ppwcArguments[i + dwCurrentIndex]);
  1701. dwErr = ERROR_SUPPRESS_OUTPUT;
  1702. break;
  1703. }
  1704. wszIfFriendlyName = ppwcArguments[i + dwCurrentIndex];
  1705. dwBitVector |= IFIP_IFNAME_MASK;
  1706. break;
  1707. }
  1708. default:
  1709. {
  1710. dwErr = ERROR_INVALID_PARAMETER;
  1711. break;
  1712. }
  1713. } //switch
  1714. if (dwErr != NO_ERROR)
  1715. break ;
  1716. }
  1717. // interface name should be present
  1718. if (!pttTags[0].bPresent)
  1719. {
  1720. dwErr = ERROR_INVALID_SYNTAX;
  1721. }
  1722. if (pdwTagType)
  1723. IfutlFree(pdwTagType);
  1724. }
  1725. if (dwErr != NO_ERROR)
  1726. return dwErr;
  1727. //
  1728. // show for all interfaces
  1729. //
  1730. if (bAll) {
  1731. dwErr = IfIpShowAllInterfaceInfo(pwszMachineName, dtType, NULL);
  1732. }
  1733. // show for specified interface
  1734. else {
  1735. GUID guid;
  1736. dwErr = IfutlGetIfIndexFromInterfaceName(
  1737. wszInterfaceName,
  1738. &IfIndex);
  1739. CLSIDFromString(wszInterfaceName, &guid);
  1740. dwErr = IfIpShowManyEx(pwszMachineName,
  1741. IfIndex, wszIfFriendlyName, &guid, dtType, NULL);
  1742. if (dwErr != NO_ERROR)
  1743. return dwErr;
  1744. }
  1745. return dwErr;
  1746. }
  1747. DWORD
  1748. IfIpShowAllInterfaceInfo(
  1749. LPCWSTR pwszMachineName,
  1750. DISPLAY_TYPE dtType,
  1751. HANDLE hFile
  1752. )
  1753. /*++
  1754. Routine Description
  1755. Arguments
  1756. Return Value
  1757. --*/
  1758. {
  1759. GUID TmpGuid;
  1760. PWCHAR TmpGuidStr;
  1761. WCHAR wszIfFriendlyName[MAX_INTERFACE_NAME_LEN + 1];
  1762. PIP_INTERFACE_NAME_INFO pTable;
  1763. DWORD dwErr, dwCount, i, dwBufferSize;
  1764. // get interface index
  1765. dwErr = NhpAllocateAndGetInterfaceInfoFromStack(
  1766. &pTable,
  1767. &dwCount,
  1768. FALSE,
  1769. GetProcessHeap(),
  1770. 0);
  1771. if (dwErr != NO_ERROR)
  1772. return dwErr;
  1773. for (i=0; i<dwCount; i++) {
  1774. // Don't dump the properties for
  1775. // Demand Dial (IF_CONNECTION_DEMAND),
  1776. // Dial Out (IF_CONNECTION_DEMAND),
  1777. // or Dial in (IF_CONNECTION_PASSIVE) interfaces
  1778. // i.e. dump properties for Dedicated connections only
  1779. if ( pTable[i].ConnectionType != IF_CONNECTION_DEDICATED )
  1780. continue;
  1781. // If InterfaceGuid is all Zeros we will use DeviceGuid to get the
  1782. // friendly name
  1783. if ( IsEqualCLSID(&(pTable[i].InterfaceGuid), &GUID_NULL) ) {
  1784. TmpGuid = pTable[i].DeviceGuid;
  1785. }
  1786. else {
  1787. TmpGuid = pTable[i].InterfaceGuid;
  1788. }
  1789. // get ifname as a string
  1790. dwErr = StringFromCLSID(&TmpGuid, &TmpGuidStr);
  1791. if (dwErr != S_OK)
  1792. return dwErr;
  1793. // get friendly name
  1794. dwBufferSize = sizeof(wszIfFriendlyName);
  1795. IfutlGetInterfaceDescription(TmpGuidStr, wszIfFriendlyName,
  1796. &dwBufferSize);
  1797. IfIpShowManyEx(pwszMachineName, pTable[i].Index, wszIfFriendlyName,
  1798. &TmpGuid, dtType, hFile);
  1799. CoTaskMemFree(TmpGuidStr);
  1800. }
  1801. return dwErr==S_OK ? NO_ERROR : dwErr;
  1802. }
  1803. DWORD
  1804. IfIpHandleDelArpCache(
  1805. IN LPCWSTR pwszMachine,
  1806. IN OUT LPWSTR *ppwcArguments,
  1807. IN DWORD dwCurrentIndex,
  1808. IN DWORD dwArgCount,
  1809. IN DWORD dwFlags,
  1810. IN LPCVOID pvData,
  1811. OUT BOOL *pbDone
  1812. )
  1813. /*++
  1814. Routine Description
  1815. Arguments
  1816. Return Value
  1817. --*/
  1818. {
  1819. DWORD dwErr, dwCount, i, j, dwNumArg;
  1820. TAG_TYPE Tags[] = {{TOKEN_NAME,FALSE,FALSE}};
  1821. PDWORD pdwTagType;
  1822. WCHAR wszInterfaceName[MAX_INTERFACE_NAME_LEN + 1] = L"\0";
  1823. DWORD dwBufferSize = sizeof(wszInterfaceName);
  1824. GUID Guid;
  1825. PIP_INTERFACE_NAME_INFO pTable;
  1826. dwErr = NhpAllocateAndGetInterfaceInfoFromStack(&pTable,
  1827. &dwCount,
  1828. FALSE,
  1829. GetProcessHeap(),
  1830. 0);
  1831. if (dwErr != NO_ERROR)
  1832. {
  1833. return dwErr;
  1834. }
  1835. dwNumArg = dwArgCount - dwCurrentIndex;
  1836. if(dwNumArg == 0)
  1837. {
  1838. for(i = 0 ; i < dwCount; i++)
  1839. {
  1840. dwErr = FlushIpNetTableFromStack(pTable[i].Index);
  1841. }
  1842. return ERROR_OKAY;
  1843. }
  1844. pdwTagType = HeapAlloc(GetProcessHeap(),
  1845. 0,
  1846. dwNumArg * sizeof(DWORD));
  1847. if (pdwTagType is NULL)
  1848. {
  1849. return ERROR_NOT_ENOUGH_MEMORY;
  1850. }
  1851. dwErr = MatchTagsInCmdLine(g_hModule,
  1852. ppwcArguments,
  1853. dwCurrentIndex,
  1854. dwArgCount,
  1855. Tags,
  1856. NUM_TAGS_IN_TABLE(Tags),
  1857. pdwTagType);
  1858. if(dwErr isnot NO_ERROR)
  1859. {
  1860. IfutlFree(pdwTagType);
  1861. if(dwErr is ERROR_INVALID_OPTION_TAG)
  1862. {
  1863. return ERROR_INVALID_SYNTAX;
  1864. }
  1865. return dwErr;
  1866. }
  1867. for(j = 0; j < dwNumArg; j++)
  1868. {
  1869. switch(pdwTagType[j])
  1870. {
  1871. case 0 :
  1872. {
  1873. dwErr = GetIfNameFromFriendlyName(
  1874. ppwcArguments[j + dwCurrentIndex],
  1875. wszInterfaceName,
  1876. &dwBufferSize);
  1877. if (dwErr isnot NO_ERROR)
  1878. {
  1879. j = dwNumArg;
  1880. break;
  1881. }
  1882. CLSIDFromString(wszInterfaceName, &Guid);
  1883. for(i = 0; i < dwCount; i ++)
  1884. {
  1885. if(IsEqualGUID(&Guid,
  1886. &(pTable[i].DeviceGuid)))
  1887. {
  1888. FlushIpNetTableFromStack(pTable[i].Index);
  1889. break;
  1890. }
  1891. }
  1892. if(i == dwCount)
  1893. {
  1894. DisplayMessage(g_hModule,
  1895. MSG_NO_SUCH_IF,
  1896. ppwcArguments[j + dwCurrentIndex]);
  1897. dwErr = ERROR_SUPPRESS_OUTPUT;
  1898. }
  1899. break;
  1900. }
  1901. default:
  1902. {
  1903. j = dwNumArg;
  1904. dwErr = ERROR_INVALID_SYNTAX;
  1905. break;
  1906. }
  1907. }
  1908. }
  1909. if(dwErr == NO_ERROR)
  1910. {
  1911. dwErr = ERROR_OKAY;
  1912. }
  1913. return dwErr;
  1914. }
  1915. DWORD
  1916. TrRepair(
  1917. FILE* LogFile
  1918. );
  1919. DWORD
  1920. IfIpHandleReset(
  1921. IN LPCWSTR pwszMachine,
  1922. IN OUT LPWSTR *ppwcArguments,
  1923. IN DWORD dwCurrentIndex,
  1924. IN DWORD dwArgCount,
  1925. IN DWORD dwFlags,
  1926. IN LPCVOID pvData,
  1927. OUT BOOL *pbDone
  1928. )
  1929. /*++
  1930. Routine Description
  1931. Arguments
  1932. Return Value
  1933. --*/
  1934. {
  1935. DWORD dwErr, i;
  1936. TAG_TYPE pttTags[] = {{TOKEN_NAME,TRUE,FALSE}};
  1937. DWORD rgdwTagType[sizeof(pttTags)/sizeof(TAG_TYPE)];
  1938. PCWSTR pwszLogFileName;
  1939. FILE *LogFile;
  1940. // Parse arguments
  1941. dwErr = PreprocessCommand(g_hModule,
  1942. ppwcArguments,
  1943. dwCurrentIndex,
  1944. dwArgCount,
  1945. pttTags,
  1946. sizeof(pttTags)/sizeof(TAG_TYPE),
  1947. 0,
  1948. sizeof(pttTags)/sizeof(TAG_TYPE),
  1949. rgdwTagType );
  1950. if (dwErr isnot NO_ERROR) {
  1951. return dwErr;
  1952. }
  1953. for (i=0; (dwErr == NO_ERROR) && (i<dwArgCount-dwCurrentIndex); i++) {
  1954. switch(rgdwTagType[i]) {
  1955. case 0: // NAME
  1956. pwszLogFileName = ppwcArguments[i + dwCurrentIndex];
  1957. break;
  1958. default:
  1959. dwErr = ERROR_INVALID_SYNTAX;
  1960. break;
  1961. }
  1962. }
  1963. if (dwErr isnot NO_ERROR) {
  1964. return dwErr;
  1965. }
  1966. // Open the log file for append.
  1967. //
  1968. LogFile = _wfopen(pwszLogFileName, L"a+");
  1969. if (LogFile == NULL) {
  1970. DisplayMessage(g_hModule, EMSG_OPEN_APPEND);
  1971. return ERROR_SUPPRESS_OUTPUT;
  1972. }
  1973. dwErr = TrRepair(LogFile);
  1974. fprintf(LogFile, "<completed>\n\n");
  1975. fclose(LogFile);
  1976. return dwErr;
  1977. }