Leaked source code of windows server 2003
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.

2612 lines
65 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. #pragma prefast(suppress:1, "pwszAddAddr is initialized if IFIP_IFNAME_MASK is set")
  1116. return IfIpAddSetDelMany(wszIfFriendlyName, &guid, pwszAddAddr, dwAddIndex, REGISTER_UNCHANGED, Type, ADD_FLAG);
  1117. }
  1118. return dwErr;
  1119. }
  1120. DWORD
  1121. IfIpHandleDelAddress(
  1122. IN LPCWSTR pwszMachine,
  1123. IN OUT LPWSTR *ppwcArguments,
  1124. IN DWORD dwCurrentIndex,
  1125. IN DWORD dwArgCount,
  1126. IN DWORD dwFlags,
  1127. IN LPCVOID pvData,
  1128. OUT BOOL *pbDone
  1129. )
  1130. /*++
  1131. Routine Description
  1132. Arguments
  1133. Return Value
  1134. --*/
  1135. {
  1136. WCHAR wszInterfaceName[MAX_INTERFACE_NAME_LEN + 1] = L"\0";
  1137. PWCHAR wszIfFriendlyName = NULL;
  1138. DWORD dwBufferSize = sizeof(wszInterfaceName);
  1139. DWORD dwErr = NO_ERROR,dwRes, dwErrIndex=-1;
  1140. TAG_TYPE pttTags[] = {
  1141. {TOKEN_NAME,FALSE,FALSE},
  1142. {TOKEN_ADDR,FALSE,FALSE},
  1143. {TOKEN_GATEWAY,FALSE,FALSE}};
  1144. PDWORD pdwTagType;
  1145. DWORD dwNumOpt, dwBitVector=0;
  1146. DWORD dwNumArg, i, j, Flags = 0;
  1147. PWCHAR pwszDelAddr=NULL, pwszDelGateway=NULL;
  1148. // At least interface name and ipaddr/gateway should be specified.
  1149. if (dwCurrentIndex + 1 >= dwArgCount)
  1150. {
  1151. return ERROR_SHOW_USAGE;
  1152. }
  1153. dwNumArg = dwArgCount - dwCurrentIndex;
  1154. pdwTagType = HeapAlloc(GetProcessHeap(),
  1155. 0,
  1156. dwNumArg * sizeof(DWORD));
  1157. if (pdwTagType is NULL)
  1158. {
  1159. return ERROR_NOT_ENOUGH_MEMORY;
  1160. }
  1161. dwErr = MatchTagsInCmdLine(g_hModule,
  1162. ppwcArguments,
  1163. dwCurrentIndex,
  1164. dwArgCount,
  1165. pttTags,
  1166. NUM_TAGS_IN_TABLE(pttTags),
  1167. pdwTagType);
  1168. if (dwErr isnot NO_ERROR)
  1169. {
  1170. IfutlFree(pdwTagType);
  1171. if (dwErr is ERROR_INVALID_OPTION_TAG)
  1172. {
  1173. return ERROR_INVALID_SYNTAX;
  1174. }
  1175. return dwErr;
  1176. }
  1177. for ( i = 0; i < dwNumArg; i++)
  1178. {
  1179. switch (pdwTagType[i])
  1180. {
  1181. case 0 :
  1182. {
  1183. // get IfName
  1184. dwErr = GetIfNameFromFriendlyName(ppwcArguments[i + dwCurrentIndex],
  1185. wszInterfaceName,&dwBufferSize);
  1186. if (dwErr isnot NO_ERROR)
  1187. {
  1188. DisplayMessage(g_hModule, EMSG_INVALID_INTERFACE,
  1189. ppwcArguments[i + dwCurrentIndex]);
  1190. dwErr = ERROR_SUPPRESS_OUTPUT;
  1191. break;
  1192. }
  1193. wszIfFriendlyName = ppwcArguments[i + dwCurrentIndex];
  1194. dwBitVector |= IFIP_IFNAME_MASK;
  1195. break;
  1196. }
  1197. case 1:
  1198. {
  1199. //
  1200. // ip address for static
  1201. //
  1202. ULONG dwDelAddr;
  1203. dwErr = GetIpAddress(ppwcArguments[i + dwCurrentIndex],
  1204. &dwDelAddr);
  1205. if((dwErr != NO_ERROR) or CHECK_UNICAST_IP_ADDR(dwDelAddr))
  1206. {
  1207. DispTokenErrMsg(g_hModule,
  1208. EMSG_BAD_OPTION_VALUE,
  1209. pttTags[pdwTagType[i]].pwszTag,
  1210. ppwcArguments[i + dwCurrentIndex]);
  1211. dwErr = ERROR_SUPPRESS_OUTPUT;
  1212. break;
  1213. }
  1214. pwszDelAddr = ppwcArguments[i + dwCurrentIndex];
  1215. dwBitVector |= IFIP_ADDR_MASK;
  1216. Flags |= TYPE_ADDR;
  1217. break;
  1218. }
  1219. case 2:
  1220. {
  1221. //
  1222. // get default gateway addr
  1223. //
  1224. ULONG dwDelGateway;
  1225. TOKEN_VALUE rgEnums[] =
  1226. {{TOKEN_VALUE_ALL, ALL}};
  1227. dwErr = MatchEnumTag(g_hModule,
  1228. ppwcArguments[i + dwCurrentIndex],
  1229. NUM_TOKENS_IN_TABLE(rgEnums),
  1230. rgEnums,
  1231. &dwRes);
  1232. if (dwErr == NO_ERROR) {
  1233. pwszDelGateway = NULL;
  1234. }
  1235. else {
  1236. dwErr = NO_ERROR;
  1237. dwErr = GetIpAddress(ppwcArguments[i + dwCurrentIndex],
  1238. &dwDelGateway);
  1239. if((dwErr != NO_ERROR) or CHECK_UNICAST_IP_ADDR(dwDelGateway))
  1240. {
  1241. DispTokenErrMsg(g_hModule,
  1242. EMSG_BAD_OPTION_VALUE,
  1243. pttTags[pdwTagType[i]].pwszTag,
  1244. ppwcArguments[i + dwCurrentIndex]);
  1245. dwErr = ERROR_SUPPRESS_OUTPUT;
  1246. break;
  1247. }
  1248. pwszDelGateway = ppwcArguments[i + dwCurrentIndex];
  1249. }
  1250. dwBitVector |= IFIP_GATEWAY_MASK;
  1251. Flags |= TYPE_GATEWAY;
  1252. break;
  1253. }
  1254. default:
  1255. {
  1256. i = dwNumArg;
  1257. dwErr = ERROR_INVALID_PARAMETER;
  1258. break;
  1259. }
  1260. } //switch
  1261. if (dwErr != NO_ERROR)
  1262. break ;
  1263. }
  1264. switch(dwErr)
  1265. {
  1266. case NO_ERROR :
  1267. break;
  1268. case ERROR_INVALID_PARAMETER:
  1269. if (dwErrIndex != -1)
  1270. {
  1271. DispTokenErrMsg(g_hModule,
  1272. EMSG_BAD_OPTION_VALUE,
  1273. pttTags[pdwTagType[dwErrIndex]].pwszTag,
  1274. ppwcArguments[dwErrIndex + dwCurrentIndex]);
  1275. dwErr = ERROR_SUPPRESS_OUTPUT;
  1276. }
  1277. break;
  1278. default:
  1279. // error message already printed
  1280. break;
  1281. }
  1282. if (pdwTagType)
  1283. IfutlFree(pdwTagType);
  1284. if (dwErr != NO_ERROR)
  1285. return dwErr;
  1286. // interface name and addr/all should be present
  1287. if ( !(dwBitVector & IFIP_IFNAME_MASK)
  1288. || !(dwBitVector & (IFIP_GATEWAY_MASK | IFIP_ADDR_MASK))
  1289. ) {
  1290. return ERROR_INVALID_SYNTAX;
  1291. }
  1292. {
  1293. GUID guid;
  1294. CLSIDFromString(wszInterfaceName, &guid);
  1295. dwErr = IfIpHandleDelIpaddrEx(wszIfFriendlyName, &guid, pwszDelAddr, pwszDelGateway, Flags);
  1296. RETURN_ERROR_OKAY(dwErr);
  1297. }
  1298. RETURN_ERROR_OKAY(dwErr);
  1299. }
  1300. DWORD
  1301. IfIpHandleDelDns(
  1302. IN LPCWSTR pwszMachine,
  1303. IN OUT LPWSTR *ppwcArguments,
  1304. IN DWORD dwCurrentIndex,
  1305. IN DWORD dwArgCount,
  1306. IN DWORD dwFlags,
  1307. IN LPCVOID pvData,
  1308. OUT BOOL *pbDone
  1309. )
  1310. /*++
  1311. Routine Description
  1312. Arguments
  1313. Return Value
  1314. --*/
  1315. {
  1316. DWORD dwErr;
  1317. dwErr = IfIpDelMany(
  1318. ppwcArguments,
  1319. dwCurrentIndex,
  1320. dwArgCount,
  1321. pbDone,
  1322. TYPE_DNS
  1323. );
  1324. RETURN_ERROR_OKAY(dwErr);
  1325. }
  1326. DWORD
  1327. IfIpHandleDelWins(
  1328. IN LPCWSTR pwszMachine,
  1329. IN OUT LPWSTR *ppwcArguments,
  1330. IN DWORD dwCurrentIndex,
  1331. IN DWORD dwArgCount,
  1332. IN DWORD dwFlags,
  1333. IN LPCVOID pvData,
  1334. OUT BOOL *pbDone
  1335. )
  1336. /*++
  1337. Routine Description
  1338. Arguments
  1339. Return Value
  1340. --*/
  1341. {
  1342. DWORD dwErr;
  1343. dwErr = IfIpDelMany(
  1344. ppwcArguments,
  1345. dwCurrentIndex,
  1346. dwArgCount,
  1347. pbDone,
  1348. TYPE_WINS
  1349. );
  1350. RETURN_ERROR_OKAY(dwErr);
  1351. }
  1352. DWORD
  1353. IfIpDelMany(
  1354. IN PWCHAR *ppwcArguments,
  1355. IN DWORD dwCurrentIndex,
  1356. IN DWORD dwArgCount,
  1357. IN BOOL *pbDone,
  1358. IN DISPLAY_TYPE Type
  1359. )
  1360. /*++
  1361. Routine Description
  1362. Arguments
  1363. Return Value
  1364. --*/
  1365. {
  1366. WCHAR wszInterfaceName[MAX_INTERFACE_NAME_LEN + 1] = L"\0";
  1367. PWCHAR wszIfFriendlyName = NULL;
  1368. DWORD dwBufferSize = sizeof(wszInterfaceName);
  1369. DWORD dwErr = NO_ERROR,dwRes, dwErrIndex=-1;
  1370. TAG_TYPE pttTags[] = {
  1371. {TOKEN_NAME,FALSE,FALSE},
  1372. {TOKEN_ADDR,FALSE,FALSE}};
  1373. PDWORD pdwTagType;
  1374. DWORD dwNumOpt, dwBitVector=0;
  1375. DWORD dwNumArg, i, j;
  1376. PWCHAR pwszDelAddr=NULL;
  1377. // At least interface name/address should be specified.
  1378. if (dwCurrentIndex +1 >= dwArgCount)
  1379. {
  1380. return ERROR_SHOW_USAGE;
  1381. }
  1382. dwNumArg = dwArgCount - dwCurrentIndex;
  1383. pdwTagType = HeapAlloc(GetProcessHeap(),
  1384. 0,
  1385. dwNumArg * sizeof(DWORD));
  1386. if (pdwTagType is NULL)
  1387. {
  1388. return ERROR_NOT_ENOUGH_MEMORY;
  1389. }
  1390. dwErr = MatchTagsInCmdLine(g_hModule,
  1391. ppwcArguments,
  1392. dwCurrentIndex,
  1393. dwArgCount,
  1394. pttTags,
  1395. NUM_TAGS_IN_TABLE(pttTags),
  1396. pdwTagType);
  1397. if (dwErr isnot NO_ERROR)
  1398. {
  1399. IfutlFree(pdwTagType);
  1400. if (dwErr is ERROR_INVALID_OPTION_TAG)
  1401. {
  1402. return ERROR_INVALID_SYNTAX;
  1403. }
  1404. return dwErr;
  1405. }
  1406. for ( i = 0; i < dwNumArg; i++)
  1407. {
  1408. switch (pdwTagType[i])
  1409. {
  1410. case 0 :
  1411. {
  1412. // get IfName
  1413. dwErr = GetIfNameFromFriendlyName(ppwcArguments[i + dwCurrentIndex],
  1414. wszInterfaceName,&dwBufferSize);
  1415. if (dwErr isnot NO_ERROR)
  1416. {
  1417. DisplayMessage(g_hModule, EMSG_INVALID_INTERFACE,
  1418. ppwcArguments[i + dwCurrentIndex]);
  1419. dwErr = ERROR_SUPPRESS_OUTPUT;
  1420. break;
  1421. }
  1422. wszIfFriendlyName = ppwcArguments[i + dwCurrentIndex];
  1423. dwBitVector |= IFIP_IFNAME_MASK;
  1424. break;
  1425. }
  1426. case 1:
  1427. {
  1428. //
  1429. // address
  1430. //
  1431. ULONG dwDelAddr;
  1432. TOKEN_VALUE rgEnums[] =
  1433. {{TOKEN_VALUE_ALL, ALL}};
  1434. dwErr = MatchEnumTag(g_hModule,
  1435. ppwcArguments[i + dwCurrentIndex],
  1436. NUM_TOKENS_IN_TABLE(rgEnums),
  1437. rgEnums,
  1438. &dwRes);
  1439. if (dwErr == NO_ERROR) {
  1440. pwszDelAddr = NULL;
  1441. }
  1442. else {
  1443. dwErr = GetIpAddress(ppwcArguments[i + dwCurrentIndex], &dwDelAddr);
  1444. if((dwErr != NO_ERROR) or CHECK_UNICAST_IP_ADDR(dwDelAddr))
  1445. {
  1446. DispTokenErrMsg(g_hModule,
  1447. EMSG_BAD_OPTION_VALUE,
  1448. pttTags[pdwTagType[i]].pwszTag,
  1449. ppwcArguments[i + dwCurrentIndex]);
  1450. dwErr = ERROR_SUPPRESS_OUTPUT;
  1451. break;
  1452. }
  1453. pwszDelAddr = ppwcArguments[i + dwCurrentIndex];
  1454. }
  1455. dwBitVector |= IFIP_ADDR_MASK;
  1456. break;
  1457. }
  1458. default:
  1459. {
  1460. i = dwNumArg;
  1461. dwErr = ERROR_INVALID_PARAMETER;
  1462. break;
  1463. }
  1464. } //switch
  1465. if (dwErr != NO_ERROR)
  1466. break ;
  1467. }
  1468. switch(dwErr)
  1469. {
  1470. case NO_ERROR :
  1471. break;
  1472. case ERROR_INVALID_PARAMETER:
  1473. if (dwErrIndex != -1)
  1474. {
  1475. DispTokenErrMsg(g_hModule,
  1476. EMSG_BAD_OPTION_VALUE,
  1477. pttTags[pdwTagType[dwErrIndex]].pwszTag,
  1478. ppwcArguments[dwErrIndex + dwCurrentIndex]);
  1479. dwErr = ERROR_SUPPRESS_OUTPUT;
  1480. }
  1481. break;
  1482. default:
  1483. // error message already printed
  1484. break;
  1485. }
  1486. if (pdwTagType)
  1487. IfutlFree(pdwTagType);
  1488. if (dwErr != NO_ERROR)
  1489. return dwErr;
  1490. // interface name and address should be present
  1491. if ( !(dwBitVector & IFIP_IFNAME_MASK)
  1492. || !(dwBitVector & IFIP_ADDR_MASK)) {
  1493. return ERROR_INVALID_SYNTAX;
  1494. }
  1495. {
  1496. GUID guid;
  1497. CLSIDFromString(wszInterfaceName, &guid);
  1498. return IfIpAddSetDelMany(wszIfFriendlyName, &guid, pwszDelAddr, 0, REGISTER_UNCHANGED, Type, DEL_FLAG);
  1499. }
  1500. }
  1501. DWORD
  1502. IfIpHandleShowAddress(
  1503. IN LPCWSTR pwszMachine,
  1504. IN OUT LPWSTR *ppwcArguments,
  1505. IN DWORD dwCurrentIndex,
  1506. IN DWORD dwArgCount,
  1507. IN DWORD dwFlags,
  1508. IN LPCVOID pvData,
  1509. OUT BOOL *pbDone
  1510. )
  1511. /*++
  1512. Routine Description
  1513. Arguments
  1514. Return Value
  1515. --*/
  1516. {
  1517. return IfIpShowMany(
  1518. pwszMachine,
  1519. ppwcArguments,
  1520. dwCurrentIndex,
  1521. dwArgCount,
  1522. pbDone,
  1523. TYPE_IPADDR
  1524. );
  1525. }
  1526. DWORD
  1527. IfIpHandleShowConfig(
  1528. IN LPCWSTR pwszMachine,
  1529. IN OUT LPWSTR *ppwcArguments,
  1530. IN DWORD dwCurrentIndex,
  1531. IN DWORD dwArgCount,
  1532. IN DWORD dwFlags,
  1533. IN LPCVOID pvData,
  1534. OUT BOOL *pbDone
  1535. )
  1536. /*++
  1537. Routine Description
  1538. Arguments
  1539. Return Value
  1540. --*/
  1541. {
  1542. return IfIpShowMany(
  1543. pwszMachine,
  1544. ppwcArguments,
  1545. dwCurrentIndex,
  1546. dwArgCount,
  1547. pbDone,
  1548. TYPE_IP_ALL
  1549. );
  1550. }
  1551. DWORD
  1552. IfIpHandleShowOffload(
  1553. IN LPCWSTR pwszMachine,
  1554. IN OUT LPWSTR *ppwcArguments,
  1555. IN DWORD dwCurrentIndex,
  1556. IN DWORD dwArgCount,
  1557. IN DWORD dwFlags,
  1558. IN LPCVOID pvData,
  1559. OUT BOOL *pbDone
  1560. )
  1561. /*++
  1562. Routine Description
  1563. Arguments
  1564. Return Value
  1565. --*/
  1566. {
  1567. return IfIpShowMany(
  1568. pwszMachine,
  1569. ppwcArguments,
  1570. dwCurrentIndex,
  1571. dwArgCount,
  1572. pbDone,
  1573. TYPE_OFFLOAD
  1574. );
  1575. }
  1576. DWORD
  1577. IfIpHandleShowDns(
  1578. IN LPCWSTR pwszMachine,
  1579. IN OUT LPWSTR *ppwcArguments,
  1580. IN DWORD dwCurrentIndex,
  1581. IN DWORD dwArgCount,
  1582. IN DWORD dwFlags,
  1583. IN LPCVOID pvData,
  1584. OUT BOOL *pbDone
  1585. )
  1586. /*++
  1587. Routine Description
  1588. Arguments
  1589. Return Value
  1590. --*/
  1591. {
  1592. return IfIpShowMany(
  1593. pwszMachine,
  1594. ppwcArguments,
  1595. dwCurrentIndex,
  1596. dwArgCount,
  1597. pbDone,
  1598. TYPE_DNS
  1599. );
  1600. }
  1601. DWORD
  1602. IfIpHandleShowWins(
  1603. IN LPCWSTR pwszMachine,
  1604. IN OUT LPWSTR *ppwcArguments,
  1605. IN DWORD dwCurrentIndex,
  1606. IN DWORD dwArgCount,
  1607. IN DWORD dwFlags,
  1608. IN LPCVOID pvData,
  1609. OUT BOOL *pbDone
  1610. )
  1611. /*++
  1612. Routine Description
  1613. Arguments
  1614. Return Value
  1615. --*/
  1616. {
  1617. return IfIpShowMany(
  1618. pwszMachine,
  1619. ppwcArguments,
  1620. dwCurrentIndex,
  1621. dwArgCount,
  1622. pbDone,
  1623. TYPE_WINS
  1624. );
  1625. }
  1626. DWORD
  1627. IfIpShowMany(
  1628. IN LPCWSTR pwszMachineName,
  1629. IN PWCHAR *ppwcArguments,
  1630. IN DWORD dwCurrentIndex,
  1631. IN DWORD dwArgCount,
  1632. IN BOOL *pbDone,
  1633. IN DISPLAY_TYPE dtType
  1634. )
  1635. /*++
  1636. Routine Description
  1637. Arguments
  1638. Return Value
  1639. --*/
  1640. {
  1641. DWORD dwErr = NO_ERROR;
  1642. ULONG Flags = 0, IfIndex;
  1643. WCHAR wszInterfaceName[MAX_INTERFACE_NAME_LEN + 1] = L"\0";
  1644. PWCHAR wszIfFriendlyName = NULL;
  1645. DWORD dwBufferSize = sizeof(wszInterfaceName);
  1646. TAG_TYPE pttTags[] = {
  1647. {TOKEN_NAME,FALSE,FALSE}};
  1648. PDWORD pdwTagType;
  1649. DWORD dwNumOpt, dwBitVector=0;
  1650. DWORD dwNumArg, i;
  1651. BOOLEAN bAll = FALSE;
  1652. //
  1653. // get interface friendly name
  1654. //
  1655. if (dwCurrentIndex > dwArgCount)
  1656. {
  1657. // No arguments specified. At least interface name should be specified.
  1658. return ERROR_SHOW_USAGE;
  1659. }
  1660. else if (dwCurrentIndex == dwArgCount)
  1661. {
  1662. // show for all interfaces
  1663. bAll = TRUE;
  1664. }
  1665. else {
  1666. dwNumArg = dwArgCount - dwCurrentIndex;
  1667. pdwTagType = HeapAlloc(GetProcessHeap(),
  1668. 0,
  1669. dwNumArg * sizeof(DWORD));
  1670. if (pdwTagType is NULL)
  1671. {
  1672. return ERROR_NOT_ENOUGH_MEMORY;
  1673. }
  1674. dwErr = MatchTagsInCmdLine(g_hModule,
  1675. ppwcArguments,
  1676. dwCurrentIndex,
  1677. dwArgCount,
  1678. pttTags,
  1679. NUM_TAGS_IN_TABLE(pttTags),
  1680. pdwTagType);
  1681. if (dwErr isnot NO_ERROR)
  1682. {
  1683. IfutlFree(pdwTagType);
  1684. if (dwErr is ERROR_INVALID_OPTION_TAG)
  1685. {
  1686. return ERROR_INVALID_SYNTAX;
  1687. }
  1688. return dwErr;
  1689. }
  1690. for ( i = 0; i < dwNumArg; i++)
  1691. {
  1692. switch (pdwTagType[i])
  1693. {
  1694. case 0 :
  1695. {
  1696. dwErr = GetIfNameFromFriendlyName(ppwcArguments[i + dwCurrentIndex],
  1697. wszInterfaceName,&dwBufferSize);
  1698. if (dwErr isnot NO_ERROR)
  1699. {
  1700. DisplayMessage(g_hModule, EMSG_INVALID_INTERFACE,
  1701. ppwcArguments[i + dwCurrentIndex]);
  1702. dwErr = ERROR_SUPPRESS_OUTPUT;
  1703. break;
  1704. }
  1705. wszIfFriendlyName = ppwcArguments[i + dwCurrentIndex];
  1706. dwBitVector |= IFIP_IFNAME_MASK;
  1707. break;
  1708. }
  1709. default:
  1710. {
  1711. dwErr = ERROR_INVALID_PARAMETER;
  1712. break;
  1713. }
  1714. } //switch
  1715. if (dwErr != NO_ERROR)
  1716. break ;
  1717. }
  1718. // interface name should be present
  1719. if (!pttTags[0].bPresent)
  1720. {
  1721. dwErr = ERROR_INVALID_SYNTAX;
  1722. }
  1723. if (pdwTagType)
  1724. IfutlFree(pdwTagType);
  1725. }
  1726. if (dwErr != NO_ERROR)
  1727. return dwErr;
  1728. //
  1729. // show for all interfaces
  1730. //
  1731. if (bAll) {
  1732. dwErr = IfIpShowAllInterfaceInfo(pwszMachineName, dtType, NULL);
  1733. }
  1734. // show for specified interface
  1735. else {
  1736. GUID guid;
  1737. dwErr = IfutlGetIfIndexFromInterfaceName(
  1738. wszInterfaceName,
  1739. &IfIndex);
  1740. CLSIDFromString(wszInterfaceName, &guid);
  1741. dwErr = IfIpShowManyEx(pwszMachineName,
  1742. IfIndex, wszIfFriendlyName, &guid, dtType, NULL);
  1743. if (dwErr != NO_ERROR)
  1744. return dwErr;
  1745. }
  1746. return dwErr;
  1747. }
  1748. DWORD
  1749. IfIpShowAllInterfaceInfo(
  1750. LPCWSTR pwszMachineName,
  1751. DISPLAY_TYPE dtType,
  1752. HANDLE hFile
  1753. )
  1754. /*++
  1755. Routine Description
  1756. Arguments
  1757. Return Value
  1758. --*/
  1759. {
  1760. GUID TmpGuid;
  1761. PWCHAR TmpGuidStr;
  1762. WCHAR wszIfFriendlyName[MAX_INTERFACE_NAME_LEN + 1];
  1763. PIP_INTERFACE_NAME_INFO pTable;
  1764. DWORD dwErr, dwCount, i, dwBufferSize;
  1765. // get interface index
  1766. dwErr = NhpAllocateAndGetInterfaceInfoFromStack(
  1767. &pTable,
  1768. &dwCount,
  1769. FALSE,
  1770. GetProcessHeap(),
  1771. 0);
  1772. if (dwErr != NO_ERROR)
  1773. return dwErr;
  1774. for (i=0; i<dwCount; i++) {
  1775. // Don't dump the properties for
  1776. // Demand Dial (IF_CONNECTION_DEMAND),
  1777. // Dial Out (IF_CONNECTION_DEMAND),
  1778. // or Dial in (IF_CONNECTION_PASSIVE) interfaces
  1779. // i.e. dump properties for Dedicated connections only
  1780. if ( pTable[i].ConnectionType != IF_CONNECTION_DEDICATED )
  1781. continue;
  1782. // If InterfaceGuid is all Zeros we will use DeviceGuid to get the
  1783. // friendly name
  1784. if ( IsEqualCLSID(&(pTable[i].InterfaceGuid), &GUID_NULL) ) {
  1785. TmpGuid = pTable[i].DeviceGuid;
  1786. }
  1787. else {
  1788. TmpGuid = pTable[i].InterfaceGuid;
  1789. }
  1790. // get ifname as a string
  1791. dwErr = StringFromCLSID(&TmpGuid, &TmpGuidStr);
  1792. if (dwErr != S_OK)
  1793. return dwErr;
  1794. // get friendly name
  1795. dwBufferSize = sizeof(wszIfFriendlyName);
  1796. IfutlGetInterfaceDescription(TmpGuidStr, wszIfFriendlyName,
  1797. &dwBufferSize);
  1798. IfIpShowManyEx(pwszMachineName, pTable[i].Index, wszIfFriendlyName,
  1799. &TmpGuid, dtType, hFile);
  1800. CoTaskMemFree(TmpGuidStr);
  1801. }
  1802. return dwErr==S_OK ? NO_ERROR : dwErr;
  1803. }
  1804. DWORD
  1805. IfIpHandleDelArpCache(
  1806. IN LPCWSTR pwszMachine,
  1807. IN OUT LPWSTR *ppwcArguments,
  1808. IN DWORD dwCurrentIndex,
  1809. IN DWORD dwArgCount,
  1810. IN DWORD dwFlags,
  1811. IN LPCVOID pvData,
  1812. OUT BOOL *pbDone
  1813. )
  1814. /*++
  1815. Routine Description
  1816. Arguments
  1817. Return Value
  1818. --*/
  1819. {
  1820. DWORD dwErr, dwCount, i, j, dwNumArg;
  1821. TAG_TYPE Tags[] = {{TOKEN_NAME,FALSE,FALSE}};
  1822. PDWORD pdwTagType;
  1823. WCHAR wszInterfaceName[MAX_INTERFACE_NAME_LEN + 1] = L"\0";
  1824. DWORD dwBufferSize = sizeof(wszInterfaceName);
  1825. GUID Guid;
  1826. PIP_INTERFACE_NAME_INFO pTable;
  1827. dwErr = NhpAllocateAndGetInterfaceInfoFromStack(&pTable,
  1828. &dwCount,
  1829. FALSE,
  1830. GetProcessHeap(),
  1831. 0);
  1832. if (dwErr != NO_ERROR)
  1833. {
  1834. return dwErr;
  1835. }
  1836. dwNumArg = dwArgCount - dwCurrentIndex;
  1837. if(dwNumArg == 0)
  1838. {
  1839. for(i = 0 ; i < dwCount; i++)
  1840. {
  1841. dwErr = FlushIpNetTableFromStack(pTable[i].Index);
  1842. }
  1843. return ERROR_OKAY;
  1844. }
  1845. pdwTagType = HeapAlloc(GetProcessHeap(),
  1846. 0,
  1847. dwNumArg * sizeof(DWORD));
  1848. if (pdwTagType is NULL)
  1849. {
  1850. return ERROR_NOT_ENOUGH_MEMORY;
  1851. }
  1852. dwErr = MatchTagsInCmdLine(g_hModule,
  1853. ppwcArguments,
  1854. dwCurrentIndex,
  1855. dwArgCount,
  1856. Tags,
  1857. NUM_TAGS_IN_TABLE(Tags),
  1858. pdwTagType);
  1859. if(dwErr isnot NO_ERROR)
  1860. {
  1861. IfutlFree(pdwTagType);
  1862. if(dwErr is ERROR_INVALID_OPTION_TAG)
  1863. {
  1864. return ERROR_INVALID_SYNTAX;
  1865. }
  1866. return dwErr;
  1867. }
  1868. for(j = 0; j < dwNumArg; j++)
  1869. {
  1870. switch(pdwTagType[j])
  1871. {
  1872. case 0 :
  1873. {
  1874. dwErr = GetIfNameFromFriendlyName(
  1875. ppwcArguments[j + dwCurrentIndex],
  1876. wszInterfaceName,
  1877. &dwBufferSize);
  1878. if (dwErr isnot NO_ERROR)
  1879. {
  1880. j = dwNumArg;
  1881. break;
  1882. }
  1883. CLSIDFromString(wszInterfaceName, &Guid);
  1884. for(i = 0; i < dwCount; i ++)
  1885. {
  1886. if(IsEqualGUID(&Guid,
  1887. &(pTable[i].DeviceGuid)))
  1888. {
  1889. FlushIpNetTableFromStack(pTable[i].Index);
  1890. break;
  1891. }
  1892. }
  1893. if(i == dwCount)
  1894. {
  1895. DisplayMessage(g_hModule,
  1896. MSG_NO_SUCH_IF,
  1897. ppwcArguments[j + dwCurrentIndex]);
  1898. dwErr = ERROR_SUPPRESS_OUTPUT;
  1899. }
  1900. break;
  1901. }
  1902. default:
  1903. {
  1904. j = dwNumArg;
  1905. dwErr = ERROR_INVALID_SYNTAX;
  1906. break;
  1907. }
  1908. }
  1909. }
  1910. if(dwErr == NO_ERROR)
  1911. {
  1912. dwErr = ERROR_OKAY;
  1913. }
  1914. return dwErr;
  1915. }
  1916. DWORD
  1917. TrRepair(
  1918. FILE* LogFile
  1919. );
  1920. DWORD
  1921. IfIpHandleReset(
  1922. IN LPCWSTR pwszMachine,
  1923. IN OUT LPWSTR *ppwcArguments,
  1924. IN DWORD dwCurrentIndex,
  1925. IN DWORD dwArgCount,
  1926. IN DWORD dwFlags,
  1927. IN LPCVOID pvData,
  1928. OUT BOOL *pbDone
  1929. )
  1930. /*++
  1931. Routine Description
  1932. Arguments
  1933. Return Value
  1934. --*/
  1935. {
  1936. DWORD dwErr, i;
  1937. TAG_TYPE pttTags[] = {{TOKEN_NAME,TRUE,FALSE}};
  1938. DWORD rgdwTagType[sizeof(pttTags)/sizeof(TAG_TYPE)];
  1939. PCWSTR pwszLogFileName;
  1940. FILE *LogFile;
  1941. // Parse arguments
  1942. dwErr = PreprocessCommand(g_hModule,
  1943. ppwcArguments,
  1944. dwCurrentIndex,
  1945. dwArgCount,
  1946. pttTags,
  1947. sizeof(pttTags)/sizeof(TAG_TYPE),
  1948. 0,
  1949. sizeof(pttTags)/sizeof(TAG_TYPE),
  1950. rgdwTagType );
  1951. if (dwErr isnot NO_ERROR) {
  1952. return dwErr;
  1953. }
  1954. for (i=0; (dwErr == NO_ERROR) && (i<dwArgCount-dwCurrentIndex); i++) {
  1955. switch(rgdwTagType[i]) {
  1956. case 0: // NAME
  1957. pwszLogFileName = ppwcArguments[i + dwCurrentIndex];
  1958. break;
  1959. default:
  1960. dwErr = ERROR_INVALID_SYNTAX;
  1961. break;
  1962. }
  1963. }
  1964. if (dwErr isnot NO_ERROR) {
  1965. return dwErr;
  1966. }
  1967. // Open the log file for append.
  1968. //
  1969. LogFile = _wfopen(pwszLogFileName, L"a+");
  1970. if (LogFile == NULL) {
  1971. DisplayMessage(g_hModule, EMSG_OPEN_APPEND);
  1972. return ERROR_SUPPRESS_OUTPUT;
  1973. }
  1974. dwErr = TrRepair(LogFile);
  1975. fprintf(LogFile, "<completed>\n\n");
  1976. fclose(LogFile);
  1977. return dwErr;
  1978. }