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.

1170 lines
25 KiB

  1. #include "precomp.h"
  2. BOOL g_bRouterRunning;
  3. ULONG g_ulNumChecks;
  4. VOID
  5. IfutlGetInterfaceName(
  6. IN PWCHAR pwszIfDesc,
  7. OUT PWCHAR pwszIfName,
  8. IN PDWORD pdwSize
  9. )
  10. /*++
  11. Routine Description:
  12. Gets Guid Interface Name from Friendly Interface Name
  13. Arguments:
  14. pwszIfDesc - Buffer holding Friendly Interace Name
  15. pwszIfName - Buffer to hold the Guid Interface Name
  16. pdwSize - Pointer to the size (in Bytes) of pwszIfName buffer
  17. --*/
  18. {
  19. DWORD dwErr;
  20. dwErr = GetIfNameFromFriendlyName(pwszIfDesc,
  21. pwszIfName,
  22. pdwSize);
  23. if(dwErr isnot NO_ERROR)
  24. {
  25. wcsncpy(pwszIfName,
  26. pwszIfDesc,
  27. (*pdwSize)/sizeof(WCHAR));
  28. }
  29. }
  30. VOID
  31. IfutlGetInterfaceDescription(
  32. IN PWCHAR pwszIfName,
  33. OUT PWCHAR pwszIfDesc,
  34. IN PDWORD pdwSize
  35. )
  36. /*++
  37. Routine Description:
  38. Gets Friendly Interface Name from Guid Interface Name
  39. Arguments:
  40. pwszIfName - Buffer holding Guid Interace Name
  41. pwszIfDesc - Buffer to hold the Friendly Interface Name
  42. pdwSize - Pointer to the size (in Bytes) of pwszIfDesc buffer
  43. --*/
  44. {
  45. DWORD dwErr;
  46. DWORD dwLen = (*pdwSize)/sizeof(WCHAR) - 1;
  47. dwErr = GetFriendlyNameFromIfName(pwszIfName,
  48. pwszIfDesc,
  49. pdwSize);
  50. if(dwErr isnot NO_ERROR)
  51. {
  52. wcsncpy(pwszIfDesc,
  53. pwszIfName,
  54. dwLen);
  55. pwszIfDesc[dwLen] = 0;
  56. }
  57. }
  58. DWORD
  59. IfutlGetTagToken(
  60. IN HANDLE hModule,
  61. IN PWCHAR *ppwcArguments,
  62. IN DWORD dwCurrentIndex,
  63. IN DWORD dwArgCount,
  64. IN PTAG_TYPE pttTagToken,
  65. IN DWORD dwNumTags,
  66. OUT PDWORD pdwOut
  67. )
  68. /*++
  69. Routine Description:
  70. Identifies each argument based on its tag. It assumes that each argument
  71. has a tag. It also removes tag= from each argument.
  72. Arguments:
  73. ppwcArguments - The argument array. Each argument has tag=value form
  74. dwCurrentIndex - ppwcArguments[dwCurrentIndex] is first arg.
  75. dwArgCount - ppwcArguments[dwArgCount - 1] is last arg.
  76. pttTagToken - Array of tag token ids that are allowed in the args
  77. dwNumTags - Size of pttTagToken
  78. pdwOut - Array identifying the type of each argument.
  79. Return Value:
  80. NO_ERROR, ERROR_INVALID_PARAMETER, ERROR_INVALID_OPTION_TAG
  81. --*/
  82. {
  83. DWORD i,j,len;
  84. PWCHAR pwcTag,pwcTagVal,pwszArg;
  85. BOOL bFound = FALSE;
  86. //
  87. // This function assumes that every argument has a tag
  88. // It goes ahead and removes the tag.
  89. //
  90. for (i = dwCurrentIndex; i < dwArgCount; i++)
  91. {
  92. len = wcslen(ppwcArguments[i]);
  93. if (len is 0)
  94. {
  95. //
  96. // something wrong with arg
  97. //
  98. pdwOut[i] = (DWORD) -1;
  99. continue;
  100. }
  101. pwszArg = HeapAlloc(GetProcessHeap(),0,(len + 1) * sizeof(WCHAR));
  102. if (pwszArg is NULL)
  103. {
  104. DisplayError(NULL,
  105. ERROR_NOT_ENOUGH_MEMORY);
  106. return ERROR_NOT_ENOUGH_MEMORY;
  107. }
  108. wcscpy(pwszArg, ppwcArguments[i]);
  109. pwcTag = wcstok(pwszArg, NETSH_ARG_DELIMITER);
  110. //
  111. // Got the first part
  112. // Now if next call returns NULL then there was no tag
  113. //
  114. pwcTagVal = wcstok((PWCHAR)NULL, NETSH_ARG_DELIMITER);
  115. if (pwcTagVal is NULL)
  116. {
  117. DisplayMessage(g_hModule,
  118. ERROR_NO_TAG,
  119. ppwcArguments[i]);
  120. HeapFree(GetProcessHeap(),0,pwszArg);
  121. return ERROR_INVALID_PARAMETER;
  122. }
  123. //
  124. // Got the tag. Now try to match it
  125. //
  126. bFound = FALSE;
  127. pdwOut[i - dwCurrentIndex] = (DWORD) -1;
  128. for ( j = 0; j < dwNumTags; j++)
  129. {
  130. if (MatchToken(pwcTag, pttTagToken[j].pwszTag))
  131. {
  132. //
  133. // Tag matched
  134. //
  135. bFound = TRUE;
  136. pdwOut[i - dwCurrentIndex] = j;
  137. break;
  138. }
  139. }
  140. if (bFound)
  141. {
  142. //
  143. // Remove tag from the argument
  144. //
  145. wcscpy(ppwcArguments[i], pwcTagVal);
  146. }
  147. else
  148. {
  149. DisplayError(NULL,
  150. ERROR_INVALID_OPTION_TAG,
  151. pwcTag);
  152. HeapFree(GetProcessHeap(),0,pwszArg);
  153. return ERROR_INVALID_OPTION_TAG;
  154. }
  155. HeapFree(GetProcessHeap(),0,pwszArg);
  156. }
  157. return NO_ERROR;
  158. }
  159. //
  160. // Helper to IfutlParse that parses options
  161. //
  162. DWORD
  163. WINAPI
  164. IfutlParseOptions(
  165. IN PWCHAR* ppwcArguments,
  166. IN DWORD dwCurrentIndex,
  167. IN DWORD dwArgCount,
  168. IN DWORD dwNumArgs,
  169. IN TAG_TYPE* rgTags,
  170. IN DWORD dwTagCount,
  171. OUT LPDWORD* ppdwTagTypes)
  172. /*++
  173. Routine Description:
  174. Based on an array of tag types returns which options are
  175. included in the given command line.
  176. Arguments:
  177. ppwcArguments - Argument array
  178. dwCurrentIndex - ppwcArguments[dwCurrentIndex] is the first arg
  179. dwArgCount - ppwcArguments[dwArgCount - 1] is the last arg
  180. Return Value:
  181. NO_ERROR
  182. --*/
  183. {
  184. LPDWORD pdwTagType;
  185. DWORD i, dwErr = NO_ERROR;
  186. // If there are no arguments, there's nothing to to
  187. //
  188. if ( dwNumArgs == 0 )
  189. {
  190. return NO_ERROR;
  191. }
  192. // Set up the table of present options
  193. pdwTagType = (LPDWORD) IfutlAlloc(dwArgCount * sizeof(DWORD), TRUE);
  194. if(pdwTagType is NULL)
  195. {
  196. DisplayError(NULL, ERROR_NOT_ENOUGH_MEMORY);
  197. return ERROR_NOT_ENOUGH_MEMORY;
  198. }
  199. do {
  200. //
  201. // The argument has a tag. Assume all of them have tags
  202. //
  203. if(wcsstr(ppwcArguments[dwCurrentIndex], NETSH_ARG_DELIMITER))
  204. {
  205. dwErr = IfutlGetTagToken(
  206. g_hModule,
  207. ppwcArguments,
  208. dwCurrentIndex,
  209. dwArgCount,
  210. rgTags,
  211. dwTagCount,
  212. pdwTagType);
  213. if(dwErr isnot NO_ERROR)
  214. {
  215. if(dwErr is ERROR_INVALID_OPTION_TAG)
  216. {
  217. dwErr = ERROR_INVALID_SYNTAX;
  218. break;
  219. }
  220. }
  221. }
  222. else
  223. {
  224. //
  225. // No tags - all args must be in order
  226. //
  227. for(i = 0; i < dwNumArgs; i++)
  228. {
  229. pdwTagType[i] = i;
  230. }
  231. }
  232. } while (FALSE);
  233. // Cleanup
  234. {
  235. if (dwErr is NO_ERROR)
  236. {
  237. *ppdwTagTypes = pdwTagType;
  238. }
  239. else
  240. {
  241. IfutlFree(pdwTagType);
  242. }
  243. }
  244. return dwErr;
  245. }
  246. //
  247. // Generic parse
  248. //
  249. DWORD
  250. IfutlParse(
  251. IN PWCHAR* ppwcArguments,
  252. IN DWORD dwCurrentIndex,
  253. IN DWORD dwArgCount,
  254. IN BOOL* pbDone,
  255. OUT IFMON_CMD_ARG* pIfArgs,
  256. IN DWORD dwIfArgCount)
  257. {
  258. DWORD i, dwNumArgs, dwErr, dwLevel = 0;
  259. LPDWORD pdwTagType = NULL;
  260. TAG_TYPE* pTags = NULL;
  261. IFMON_CMD_ARG* pArg = NULL;
  262. if (dwIfArgCount == 0)
  263. {
  264. return ERROR_INVALID_PARAMETER;
  265. }
  266. do {
  267. // Initialize
  268. dwNumArgs = dwArgCount - dwCurrentIndex;
  269. // Generate a list of the tags
  270. //
  271. pTags = (TAG_TYPE*)
  272. IfutlAlloc(dwIfArgCount * sizeof(TAG_TYPE), TRUE);
  273. if (pTags == NULL)
  274. {
  275. dwErr = ERROR_NOT_ENOUGH_MEMORY;
  276. break;
  277. }
  278. for (i = 0; i < dwIfArgCount; i++)
  279. {
  280. CopyMemory(&pTags[i], &pIfArgs[i].rgTag, sizeof(TAG_TYPE));
  281. }
  282. // Get the list of present options
  283. //
  284. dwErr = IfutlParseOptions(
  285. ppwcArguments,
  286. dwCurrentIndex,
  287. dwArgCount,
  288. dwNumArgs,
  289. pTags,
  290. dwIfArgCount,
  291. &pdwTagType);
  292. if (dwErr isnot NO_ERROR)
  293. {
  294. break;
  295. }
  296. // Copy the tag info back
  297. //
  298. for (i = 0; i < dwIfArgCount; i++)
  299. {
  300. CopyMemory(&pIfArgs[i].rgTag, &pTags[i], sizeof(TAG_TYPE));
  301. }
  302. for(i = 0; i < dwNumArgs; i++)
  303. {
  304. // Validate the current argument
  305. //
  306. if (pdwTagType[i] >= dwIfArgCount)
  307. {
  308. i = dwNumArgs;
  309. dwErr = ERROR_INVALID_SYNTAX;
  310. break;
  311. }
  312. pArg = &pIfArgs[pdwTagType[i]];
  313. // Get the value of the argument
  314. //
  315. switch (pArg->dwType)
  316. {
  317. case IFMON_CMD_TYPE_STRING:
  318. pArg->Val.pszValue =
  319. IfutlStrDup(ppwcArguments[i + dwCurrentIndex]);
  320. break;
  321. case IFMON_CMD_TYPE_ENUM:
  322. dwErr = MatchEnumTag(g_hModule,
  323. ppwcArguments[i + dwCurrentIndex],
  324. pArg->dwEnumCount,
  325. pArg->rgEnums,
  326. &(pArg->Val.dwValue));
  327. if(dwErr != NO_ERROR)
  328. {
  329. IfutlDispTokenErrMsg(
  330. g_hModule,
  331. EMSG_BAD_OPTION_VALUE,
  332. pArg->rgTag.pwszTag,
  333. ppwcArguments[i + dwCurrentIndex]);
  334. i = dwNumArgs;
  335. dwErr = ERROR_INVALID_PARAMETER;
  336. }
  337. break;
  338. }
  339. if (dwErr != NO_ERROR)
  340. {
  341. break;
  342. }
  343. // Mark the argument as present if needed
  344. //
  345. if (pArg->rgTag.bPresent)
  346. {
  347. dwErr = ERROR_TAG_ALREADY_PRESENT;
  348. i = dwNumArgs;
  349. break;
  350. }
  351. pArg->rgTag.bPresent = TRUE;
  352. }
  353. if(dwErr isnot NO_ERROR)
  354. {
  355. break;
  356. }
  357. // Make sure that all of the required parameters have
  358. // been included.
  359. //
  360. for (i = 0; i < dwIfArgCount; i++)
  361. {
  362. if ((pIfArgs[i].rgTag.dwRequired & NS_REQ_PRESENT)
  363. && !pIfArgs[i].rgTag.bPresent)
  364. {
  365. DisplayMessage(g_hModule, EMSG_CANT_FIND_EOPT);
  366. dwErr = ERROR_INVALID_SYNTAX;
  367. break;
  368. }
  369. }
  370. if(dwErr isnot NO_ERROR)
  371. {
  372. break;
  373. }
  374. } while (FALSE);
  375. // Cleanup
  376. {
  377. if (pTags)
  378. {
  379. IfutlFree(pTags);
  380. }
  381. if (pdwTagType)
  382. {
  383. IfutlFree(pdwTagType);
  384. }
  385. }
  386. return dwErr;
  387. }
  388. //
  389. // Returns an allocated block of memory conditionally
  390. // zeroed of the given size.
  391. //
  392. PVOID
  393. WINAPI
  394. IfutlAlloc(
  395. IN DWORD dwBytes,
  396. IN BOOL bZero
  397. )
  398. {
  399. PVOID pvRet;
  400. DWORD dwFlags = 0;
  401. if (bZero)
  402. {
  403. dwFlags |= HEAP_ZERO_MEMORY;
  404. }
  405. return HeapAlloc(GetProcessHeap(), dwFlags, dwBytes);
  406. }
  407. //
  408. // Conditionally free's a pointer if it is non-null
  409. //
  410. VOID
  411. WINAPI
  412. IfutlFree(
  413. IN PVOID pvData
  414. )
  415. {
  416. if (pvData)
  417. {
  418. HeapFree(GetProcessHeap(), 0, pvData);
  419. }
  420. }
  421. //
  422. // Uses IfutlAlloc to copy a string
  423. //
  424. PWCHAR
  425. WINAPI
  426. IfutlStrDup(
  427. IN LPCWSTR pwszSrc
  428. )
  429. {
  430. PWCHAR pszRet = NULL;
  431. DWORD dwLen;
  432. if ((pwszSrc is NULL) or
  433. ((dwLen = wcslen(pwszSrc)) == 0)
  434. )
  435. {
  436. return NULL;
  437. }
  438. pszRet = (PWCHAR) IfutlAlloc((dwLen + 1) * sizeof(WCHAR), FALSE);
  439. if (pszRet isnot NULL)
  440. {
  441. wcscpy(pszRet, pwszSrc);
  442. }
  443. return pszRet;
  444. }
  445. BOOL
  446. IfutlIsRouterRunning(
  447. VOID
  448. )
  449. /*++
  450. Routine Description:
  451. Gets the status of the router
  452. Arguments:
  453. Return Value:
  454. --*/
  455. {
  456. DWORD dwErr;
  457. //
  458. // Check every 5th call
  459. //
  460. if(g_ulNumChecks isnot 0)
  461. {
  462. return g_bRouterRunning;
  463. }
  464. g_ulNumChecks++;
  465. g_ulNumChecks %= 5;
  466. if(MprAdminIsServiceRunning(g_pwszRouter))
  467. {
  468. if(g_bRouterRunning)
  469. {
  470. return TRUE;
  471. }
  472. dwErr = MprAdminServerConnect(g_pwszRouter,
  473. &g_hMprAdmin);
  474. if(dwErr isnot NO_ERROR)
  475. {
  476. DisplayError(NULL,
  477. dwErr);
  478. DisplayMessage(g_hModule,
  479. EMSG_CAN_NOT_CONNECT_DIM,
  480. dwErr);
  481. return FALSE;
  482. }
  483. dwErr = MprAdminMIBServerConnect(g_pwszRouter,
  484. &g_hMIBServer);
  485. if(dwErr isnot NO_ERROR)
  486. {
  487. DisplayError(NULL,
  488. dwErr);
  489. DisplayMessage(g_hModule,
  490. EMSG_CAN_NOT_CONNECT_DIM,
  491. dwErr);
  492. MprAdminServerDisconnect(g_hMprAdmin);
  493. g_hMprAdmin = NULL;
  494. return FALSE;
  495. }
  496. g_bRouterRunning = TRUE;
  497. }
  498. else
  499. {
  500. if(g_bRouterRunning)
  501. {
  502. g_bRouterRunning = FALSE;
  503. g_hMprAdmin = NULL;
  504. g_hMIBServer = NULL;
  505. }
  506. }
  507. return g_bRouterRunning;
  508. }
  509. DWORD
  510. GetIpAddress(
  511. IN PWCHAR ppwcArg,
  512. OUT PIPV4_ADDRESS pipAddress
  513. )
  514. /*++
  515. Routine Description:
  516. Gets the ip address from the string.
  517. Arguments:
  518. pwszIpAddr - Ip address string
  519. pipAddress - IP address
  520. Return Value:
  521. NO_ERROR, ERROR_INVALID_PARAMETER
  522. --*/
  523. {
  524. CHAR pszIpAddr[ADDR_LENGTH+1];
  525. // Make sure all characters are legal [0-9.]
  526. if (ppwcArg[ wcsspn(ppwcArg, L"0123456789.") ])
  527. {
  528. return ERROR_INVALID_PARAMETER;
  529. }
  530. // make sure there are 3 "." (periods)
  531. {
  532. DWORD i;
  533. PWCHAR TmpPtr;
  534. for (i=0,TmpPtr=ppwcArg; ; i++) {
  535. TmpPtr = wcschr(TmpPtr, L'.');
  536. if (TmpPtr)
  537. TmpPtr++;
  538. else
  539. break;
  540. }
  541. if (i!=3)
  542. return ERROR_INVALID_PARAMETER;
  543. }
  544. WideCharToMultiByte(GetConsoleOutputCP(),
  545. 0,
  546. ppwcArg,
  547. -1,
  548. pszIpAddr,
  549. ADDR_LENGTH,
  550. NULL,
  551. NULL);
  552. pszIpAddr[ADDR_LENGTH] = '\0';
  553. *pipAddress = (DWORD) inet_addr(pszIpAddr);
  554. // if there was an error, make sure that the address
  555. // specified was not 255.255.255.255
  556. if (*pipAddress == INADDR_NONE
  557. && wcscmp(ppwcArg,L"255.255.255.255"))
  558. {
  559. return ERROR_INVALID_PARAMETER;
  560. }
  561. if ((*pipAddress&0x000000FF) == 0)
  562. return ERROR_INVALID_PARAMETER;
  563. return NO_ERROR;
  564. }
  565. // NOTE: CheckMask fails when IpAddr is 0xffffffff!
  566. BOOL
  567. CheckMask(
  568. DWORD IpAddr
  569. )
  570. {
  571. DWORD i,Mask;
  572. IpAddr = htonl(IpAddr);
  573. for (i=0,Mask=0; i<32; (Mask = ((Mask>>1) + 0x80000000)), i++ ) {
  574. if (IpAddr == Mask)
  575. return FALSE;
  576. }
  577. return TRUE;
  578. }
  579. DWORD
  580. IfutlGetIfIndexFromFriendlyName(
  581. PWCHAR IfFriendlyName,
  582. PULONG pdwIfIndex
  583. )
  584. {
  585. WCHAR wszGuid[200];
  586. DWORD dwSize = sizeof(wszGuid);
  587. IfutlGetInterfaceName(
  588. IfFriendlyName,
  589. wszGuid,
  590. &dwSize
  591. );
  592. return IfutlGetIfIndexFromInterfaceName(
  593. wszGuid,
  594. pdwIfIndex);
  595. }
  596. DWORD
  597. IfutlGetIfIndexFromInterfaceName(
  598. IN PWCHAR pwszGuid,
  599. OUT PDWORD pdwIfIndex
  600. )
  601. {
  602. GUID guid;
  603. DWORD dwErr, i, dwCount;
  604. PIP_INTERFACE_NAME_INFO pTable;
  605. BOOL bFound = FALSE;
  606. PWCHAR TmpGuid;
  607. *pdwIfIndex = 0;
  608. dwErr = NhpAllocateAndGetInterfaceInfoFromStack(
  609. &pTable,
  610. &dwCount,
  611. FALSE,
  612. GetProcessHeap(),
  613. 0);
  614. if (dwErr != NO_ERROR)
  615. return dwErr;
  616. for (i=0; i<dwCount; i++) {
  617. dwErr = StringFromCLSID(&pTable[i].DeviceGuid, &TmpGuid);
  618. if (dwErr != S_OK)
  619. return dwErr;
  620. if (wcscmp(TmpGuid, pwszGuid) == 0) {
  621. bFound = TRUE;
  622. *pdwIfIndex = pTable[i].Index;
  623. break;
  624. }
  625. CoTaskMemFree(TmpGuid);
  626. }
  627. if (!bFound)
  628. return ERROR_CAN_NOT_COMPLETE;
  629. return NO_ERROR;
  630. }
  631. DWORD
  632. WINAPI
  633. InterfaceEnum(
  634. OUT PBYTE *ppb,
  635. OUT PDWORD pdwCount,
  636. OUT PDWORD pdwTotal
  637. )
  638. {
  639. DWORD dwRes;
  640. PMPR_INTERFACE_0 pmi0;
  641. /*if(!IsRouterRunning())*/
  642. {
  643. dwRes = MprConfigInterfaceEnum(g_hMprConfig,
  644. 0,
  645. (LPBYTE*) &pmi0,
  646. (DWORD) -1,
  647. pdwCount,
  648. pdwTotal,
  649. NULL);
  650. if(dwRes == NO_ERROR)
  651. {
  652. *ppb = (PBYTE)pmi0;
  653. }
  654. }
  655. /*else
  656. {
  657. dwRes = MprAdminInterfaceEnum(g_hMprAdmin,
  658. 0,
  659. (LPBYTE*) &pmi0,
  660. (DWORD) -1,
  661. pdwCount,
  662. pdwTotal,
  663. NULL);
  664. if(dwRes == NO_ERROR)
  665. {
  666. *ppb = HeapAlloc(GetProcessHeap(),
  667. 0,
  668. sizeof(MPR_INTERFACE_0) * (*pdwCount));
  669. if(*ppb == NULL)
  670. {
  671. DisplayMessage(g_hModule, MSG_IP_NOT_ENOUGH_MEMORY);
  672. return ERROR_NOT_ENOUGH_MEMORY;
  673. }
  674. CopyMemory(*ppb, pmi0, sizeof(MPR_INTERFACE_0) * (*pdwCount));
  675. MprAdminBufferFree(pmi0);
  676. }
  677. }*/
  678. return dwRes;
  679. }
  680. VOID
  681. MakeAddressStringW(
  682. OUT PWCHAR pwcPrefixStr,
  683. IN IPV4_ADDRESS ipAddr
  684. )
  685. {
  686. swprintf( pwcPrefixStr,
  687. L"%d.%d.%d.%d",
  688. PRINT_IPADDR(ipAddr) );
  689. }
  690. DWORD
  691. GetGuidFromIfIndex(
  692. IN MIB_SERVER_HANDLE hMibServer,
  693. IN DWORD dwIfIndex,
  694. OUT PWCHAR pwszBuffer,
  695. IN DWORD dwBufferSize
  696. )
  697. {
  698. MIB_OPAQUE_QUERY Query;
  699. PMIB_IFROW pIfRow;
  700. DWORD dwErr, dwOutEntrySize;
  701. PMIB_OPAQUE_INFO pRpcInfo;
  702. Query.dwVarId = IF_ROW;
  703. Query.rgdwVarIndex[0] = dwIfIndex;
  704. dwErr = MibGet( PID_IP,
  705. IPRTRMGR_PID,
  706. (PVOID) &Query,
  707. sizeof(Query),
  708. (PVOID *) &pRpcInfo,
  709. &dwOutEntrySize );
  710. if (dwErr isnot NO_ERROR)
  711. {
  712. return dwErr;
  713. }
  714. pIfRow = (PMIB_IFROW)(pRpcInfo->rgbyData);
  715. wcscpy( pwszBuffer, pIfRow->wszName );
  716. MprAdminMIBBufferFree( (PVOID) pRpcInfo );
  717. return NO_ERROR;
  718. }
  719. DWORD
  720. IfutlGetFriendlyNameFromIfIndex(
  721. IN MIB_SERVER_HANDLE hMibServer,
  722. IN DWORD dwIfIndex,
  723. OUT PWCHAR pwszBuffer,
  724. IN DWORD dwBufferSize
  725. )
  726. /*++
  727. Routine Description:
  728. Gets Friendly Interface Name from Interface Index
  729. Arguments:
  730. hMibServer - Handle to the MIB server
  731. dwIfIndex - Interface index
  732. pwszBuffer - Buffer to hold the Friendly Interface Name
  733. dwBufferSize - Size (in Bytes) of pwszBuffer buffer
  734. --*/
  735. {
  736. WCHAR wszGuid[MAX_INTERFACE_NAME_LEN + 1];
  737. DWORD dwErr;
  738. dwErr = GetGuidFromIfIndex(hMibServer, dwIfIndex, wszGuid, sizeof(wszGuid));
  739. if (dwErr isnot NO_ERROR)
  740. {
  741. return dwErr;
  742. }
  743. IfutlGetInterfaceDescription(wszGuid, pwszBuffer, &dwBufferSize);
  744. return NO_ERROR;
  745. }
  746. DWORD
  747. GetMibTagToken(
  748. IN PWCHAR *ppwcArguments,
  749. IN DWORD dwArgCount,
  750. IN DWORD dwNumIndices,
  751. OUT PDWORD pdwRR,
  752. OUT PBOOL pbIndex,
  753. OUT PDWORD pdwIndex
  754. )
  755. /*++
  756. Routine Description:
  757. Looks for indices and refresh rate arguments in the command. If index
  758. tag is present, it would be of the form index= index1 index2 ....
  759. The index= is removed by this function. So is rr= if it is there in
  760. the command. If pdwRR is 0 then, no refresh sought.
  761. Arguments:
  762. ppwcArguments - The argument array. Each argument has tag=value form
  763. dwCurrentIndex - ppwcArguments[dwCurrentIndex] is first arg.
  764. dwArgCount - ppwcArguments[dwArgCount - 1] is last arg.
  765. pttTagToken - Array of tag token ids that are allowed in the args
  766. dwNumTags - Size of pttTagToken
  767. pdwOut - Array identifying the type of each argument.
  768. Return Value:
  769. NO_ERROR, ERROR_INVALID_PARAMETER, ERROR_INVALID_OPTION_TAG
  770. --*/
  771. {
  772. DWORD i;
  773. BOOL bTag;
  774. if (dwArgCount is 0)
  775. {
  776. *pdwRR = 0;
  777. *pbIndex = FALSE;
  778. return NO_ERROR;
  779. }
  780. if (dwArgCount < dwNumIndices)
  781. {
  782. //
  783. // No index
  784. //
  785. *pbIndex = FALSE;
  786. if (dwArgCount > 1)
  787. {
  788. *pdwRR = 0;
  789. return ERROR_INVALID_PARAMETER;
  790. }
  791. //
  792. // No Index specified. Make sure refresh rate is specified
  793. // with tag.
  794. //
  795. if (_wcsnicmp(ppwcArguments[0],L"RR=",3) == 0)
  796. {
  797. //
  798. // get the refresh rate
  799. //
  800. *pdwRR = wcstoul(&ppwcArguments[0][3], NULL, 10);
  801. }
  802. else
  803. {
  804. return ERROR_INVALID_PARAMETER;
  805. }
  806. }
  807. else
  808. {
  809. //
  810. // Check for index tag
  811. //
  812. if (_wcsnicmp(ppwcArguments[0],L"INDEX=",6) == 0)
  813. {
  814. *pbIndex = TRUE;
  815. *pdwIndex = 0;
  816. //
  817. // remove tag and see if refresh rate is specified
  818. //
  819. wcscpy(ppwcArguments[0], &ppwcArguments[0][6]);
  820. if (dwArgCount > dwNumIndices)
  821. {
  822. //
  823. // Make sure that argument has RR tag
  824. //
  825. if (_wcsnicmp(ppwcArguments[dwNumIndices],L"RR=",3) == 0)
  826. {
  827. //
  828. // get the refresh rate
  829. //
  830. *pdwRR = wcstoul(&ppwcArguments[dwNumIndices][3], NULL , 10);
  831. }
  832. else
  833. {
  834. return ERROR_INVALID_PARAMETER;
  835. }
  836. }
  837. else
  838. {
  839. //
  840. // No refresh rate specified
  841. //
  842. *pdwRR = 0;
  843. return NO_ERROR;
  844. }
  845. }
  846. else
  847. {
  848. //
  849. // Not index tag, See if it has an RR tag
  850. //
  851. if (_wcsnicmp(ppwcArguments[0],L"RR=",3) == 0)
  852. {
  853. //
  854. // get the refresh rate
  855. //
  856. *pdwRR = wcstoul(&ppwcArguments[0][3], NULL , 10);
  857. //
  858. // See if the index follows
  859. //
  860. if (dwArgCount > dwNumIndices)
  861. {
  862. if (dwArgCount > 1)
  863. {
  864. if (_wcsnicmp(ppwcArguments[1],L"INDEX=",6) == 0)
  865. {
  866. wcscpy(ppwcArguments[1], &ppwcArguments[1][6]);
  867. *pbIndex = TRUE;
  868. *pdwIndex = 1;
  869. return NO_ERROR;
  870. }
  871. else
  872. {
  873. *pdwRR = 0;
  874. return ERROR_INVALID_PARAMETER;
  875. }
  876. }
  877. else
  878. {
  879. return NO_ERROR;
  880. }
  881. }
  882. }
  883. //
  884. // No RR Tag either
  885. //
  886. else if (dwArgCount > dwNumIndices)
  887. {
  888. //
  889. // Assume ppwcArguments[dwNumIndices] is the refresh rate
  890. //
  891. *pdwRR = wcstoul(ppwcArguments[dwNumIndices], NULL , 10);
  892. if (dwNumIndices != 0)
  893. {
  894. *pbIndex = TRUE;
  895. *pdwIndex = 0;
  896. }
  897. }
  898. else
  899. {
  900. //
  901. // only index present with no tag
  902. //
  903. *pbIndex = TRUE;
  904. *pdwIndex = 0;
  905. }
  906. }
  907. }
  908. return NO_ERROR;
  909. }
  910. DWORD
  911. MibGet(
  912. DWORD dwTransportId,
  913. DWORD dwRoutingPid,
  914. LPVOID lpInEntry,
  915. DWORD dwInEntrySize,
  916. LPVOID *lplpOutEntry,
  917. LPDWORD lpdwOutEntrySize
  918. )
  919. {
  920. DWORD dwErr;
  921. dwErr = MprAdminMIBEntryGet( g_hMIBServer,
  922. dwTransportId,
  923. dwRoutingPid,
  924. lpInEntry,
  925. dwInEntrySize,
  926. lplpOutEntry,
  927. lpdwOutEntrySize );
  928. if (dwErr is RPC_S_INVALID_BINDING)
  929. {
  930. g_bRouterRunning = FALSE;
  931. g_hMprAdmin = NULL;
  932. g_hMIBServer = NULL;
  933. }
  934. return dwErr;
  935. }