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.

1861 lines
50 KiB

  1. /*++
  2. Copyright (c) 1999 Microsoft Corporation
  3. Module Name:
  4. net\routing\netsh\if\showmib.c
  5. Abstract:
  6. Fns to parse and show MIB information
  7. Author:
  8. v raman
  9. Revision History:
  10. Anand Mahalingam
  11. Dave Thaler
  12. --*/
  13. #include "precomp.h"
  14. #pragma hdrstop
  15. #include <time.h>
  16. #define MALLOC(x) HeapAlloc(GetProcessHeap(), 0, (x))
  17. #define FREE(x) HeapFree(GetProcessHeap(), 0, (x))
  18. HANDLE g_hConsole, g_hStdOut;
  19. MIB_OBJECT_PARSER MIBObjectMap[] =
  20. {
  21. {TOKEN_MIB_OBJECT_INTERFACE,1,GetMIBIfIndex},
  22. {TOKEN_MIB_OBJECT_IPSTATS, 0,NULL},
  23. {TOKEN_MIB_OBJECT_IPADDRESS,1,GetMIBIpAddress},
  24. {TOKEN_MIB_OBJECT_IPNET, 2,GetMIBIpNetIndex},
  25. {TOKEN_MIB_OBJECT_ICMP, 0,NULL},
  26. {TOKEN_MIB_OBJECT_TCPSTATS, 0,NULL},
  27. {TOKEN_MIB_OBJECT_TCPCONN, 4,GetMIBTcpConnIndex},
  28. {TOKEN_MIB_OBJECT_UDPSTATS, 0,NULL},
  29. {TOKEN_MIB_OBJECT_UDPCONN, 2,GetMIBUdpConnIndex},
  30. };
  31. ULONG g_ulNumMibObjects = sizeof(MIBObjectMap)/sizeof(MIB_OBJECT_PARSER);
  32. MAGIC_TABLE MIBVar[] = {
  33. {IF_ROW, PrintIfRow},
  34. {IF_TABLE, PrintIfTable},
  35. {IP_STATS, PrintIpStats},
  36. {IP_STATS, PrintIpStats},
  37. {IP_ADDRROW, PrintIpAddrRow},
  38. {IP_ADDRTABLE, PrintIpAddrTable},
  39. {IP_NETROW, PrintIpNetRow},
  40. {IP_NETTABLE, PrintIpNetTable},
  41. {ICMP_STATS, PrintIcmp},
  42. {ICMP_STATS, PrintIcmp},
  43. {TCP_STATS, PrintTcpStats},
  44. {TCP_STATS, PrintTcpStats},
  45. {TCP_ROW, PrintTcpRow},
  46. {TCP_TABLE, PrintTcpTable},
  47. {UDP_STATS, PrintUdpStats},
  48. {UDP_STATS, PrintUdpStats},
  49. {UDP_ROW, PrintUdpRow},
  50. {UDP_TABLE, PrintUdpTable},
  51. };
  52. DWORD
  53. GetMIBIfIndex(
  54. IN PTCHAR *pptcArguments,
  55. IN DWORD dwCurrentIndex,
  56. OUT PDWORD pdwIndices,
  57. OUT PDWORD pdwNumParsed
  58. )
  59. /*++
  60. Routine Description:
  61. Gets the interface index.
  62. Arguments:
  63. pptcArguments - Argument array
  64. dwCurrentIndex - Index of the first argument in array
  65. pdwIndices - Indices specified in command
  66. pdwNumParsed - Number of indices in command
  67. Return Value:
  68. NO_ERROR, ERROR_INVALID_PARAMETER
  69. --*/
  70. {
  71. DWORD dwErr = NO_ERROR;
  72. *pdwNumParsed = 1;
  73. // If index was specified just use it
  74. if (iswdigit(pptcArguments[dwCurrentIndex][0]))
  75. {
  76. pdwIndices[0] = _tcstoul(pptcArguments[dwCurrentIndex],NULL,10);
  77. return NO_ERROR;
  78. }
  79. // Try converting a friendly name to an ifindex
  80. return IfutlGetIfIndexFromFriendlyName( pptcArguments[dwCurrentIndex],
  81. &pdwIndices[0] );
  82. }
  83. DWORD
  84. GetMIBIpAddress(
  85. IN PTCHAR *pptcArguments,
  86. IN DWORD dwCurrentIndex,
  87. OUT PDWORD pdwIndices,
  88. OUT PDWORD pdwNumParsed
  89. )
  90. /*++
  91. Routine Description:
  92. Gets the IP address.
  93. Arguments:
  94. pptcArguments - Argument array
  95. dwCurrentIndex - Index of the first argument in array
  96. pdwIndices - Indices specified in command
  97. pdwNumParsed - Number of indices in command
  98. Return Value:
  99. NO_ERROR
  100. --*/
  101. {
  102. DWORD dwErr = GetIpAddress(pptcArguments[dwCurrentIndex], &pdwIndices[0]);
  103. *pdwNumParsed = 1;
  104. return dwErr;
  105. }
  106. DWORD
  107. GetMIBIpNetIndex(
  108. IN PTCHAR *pptcArguments,
  109. IN DWORD dwCurrentIndex,
  110. OUT PDWORD pdwIndices,
  111. OUT PDWORD pdwNumParsed
  112. )
  113. /*++
  114. Routine Description:
  115. Gets the IP net index
  116. Arguments:
  117. pptcArguments - Argument array
  118. dwCurrentIndex - Index of the first argument in array
  119. pdwIndices - Indices specified in command
  120. pdwNumParsed - Number of indices in command
  121. Return Value:
  122. NO_ERROR
  123. --*/
  124. {
  125. DWORD dwErr;
  126. pdwIndices[0] = _tcstoul(pptcArguments[dwCurrentIndex],NULL,10);
  127. dwErr = GetIpAddress(pptcArguments[dwCurrentIndex + 1], &pdwIndices[1]);
  128. *pdwNumParsed = 2;
  129. return dwErr;
  130. }
  131. DWORD
  132. GetMIBTcpConnIndex(
  133. IN PTCHAR *pptcArguments,
  134. IN DWORD dwCurrentIndex,
  135. OUT PDWORD pdwIndices,
  136. OUT PDWORD pdwNumParsed
  137. )
  138. /*++
  139. Routine Description:
  140. Gets the tco conn index
  141. Arguments:
  142. pptcArguments - Argument array
  143. dwCurrentIndex - Index of the first argument in array
  144. pdwIndices - Indices specified in command
  145. pdwNumParsed - Number of indices in command
  146. Return Value:
  147. NO_ERROR
  148. --*/
  149. {
  150. DWORD dwErr = GetIpAddress(pptcArguments[dwCurrentIndex], &pdwIndices[0]);
  151. if (dwErr isnot NO_ERROR)
  152. {
  153. return dwErr;
  154. }
  155. pdwIndices[1] = htons((WORD)(_tcstoul(pptcArguments[dwCurrentIndex + 1],NULL,10)));
  156. dwErr = GetIpAddress(pptcArguments[dwCurrentIndex + 2], &pdwIndices[2]);
  157. pdwIndices[3] = htons((WORD)(_tcstoul(pptcArguments[dwCurrentIndex + 3],
  158. NULL,10)));
  159. *pdwNumParsed = 4;
  160. return dwErr;
  161. }
  162. DWORD
  163. GetMIBUdpConnIndex(
  164. IN PTCHAR *pptcArguments,
  165. IN DWORD dwCurrentIndex,
  166. OUT PDWORD pdwIndices,
  167. OUT PDWORD pdwNumParsed
  168. )
  169. /*++
  170. Routine Description:
  171. Gets the udp conn index
  172. Arguments:
  173. pptcArguments - Argument array
  174. dwCurrentIndex - Index of the first argument in array
  175. pdwIndices - Indices specified in command
  176. pdwNumParsed - Number of indices in command
  177. Return Value:
  178. NO_ERROR
  179. --*/
  180. {
  181. DWORD dwErr = GetIpAddress(pptcArguments[dwCurrentIndex], &pdwIndices[0]);
  182. pdwIndices[1] = htons((WORD)(_tcstoul(pptcArguments[dwCurrentIndex + 1],
  183. NULL,10)));
  184. *pdwNumParsed = 2;
  185. return dwErr;
  186. }
  187. DWORD
  188. GetIgmpList(IN IPV4_ADDRESS NTEAddr,
  189. OUT IPV4_ADDRESS *pIgmpList,
  190. OUT PULONG dwOutBufLen
  191. );
  192. DWORD
  193. GetPrintJoinRow(
  194. IPV4_ADDRESS ipAddr
  195. )
  196. {
  197. DWORD dwOutBufLen = 0;
  198. IPV4_ADDRESS *pIgmpList = NULL;
  199. DWORD dwStatus;
  200. DWORD i;
  201. dwStatus = GetIgmpList( ipAddr,
  202. pIgmpList,
  203. &dwOutBufLen );
  204. if (dwStatus == ERROR_INSUFFICIENT_BUFFER)
  205. {
  206. pIgmpList = HeapAlloc(GetProcessHeap(), 0, dwOutBufLen);
  207. if (!pIgmpList)
  208. return ERROR_NOT_ENOUGH_MEMORY;
  209. dwStatus = GetIgmpList( ipAddr,
  210. pIgmpList,
  211. &dwOutBufLen );
  212. }
  213. if (dwStatus == STATUS_SUCCESS)
  214. {
  215. WCHAR pwszIfAddr[20], pwszGrAddr[20];
  216. DWORD dwTotal = dwOutBufLen/sizeof(ipAddr);
  217. MakeAddressStringW(pwszIfAddr, ipAddr);
  218. if (!pwszIfAddr)
  219. return ERROR_NOT_ENOUGH_MEMORY;
  220. for (i=0; i<dwTotal; i++)
  221. {
  222. MakeAddressStringW(pwszGrAddr, pIgmpList[i]);
  223. if (!pwszGrAddr)
  224. return ERROR_NOT_ENOUGH_MEMORY;
  225. DisplayMessage( g_hModule,
  226. MSG_MIB_JOIN_ROW,
  227. pwszIfAddr,
  228. pwszGrAddr );
  229. }
  230. }
  231. if (pIgmpList)
  232. HeapFree(GetProcessHeap(), 0, pIgmpList);
  233. return dwStatus;
  234. }
  235. DWORD
  236. GetIPv4Addresses(
  237. IN LPSOCKET_ADDRESS_LIST *ppList)
  238. {
  239. LPSOCKET_ADDRESS_LIST pList = NULL;
  240. ULONG ulSize = 0;
  241. DWORD dwErr;
  242. DWORD dwBytesReturned;
  243. SOCKET s;
  244. *ppList = NULL;
  245. s = socket(AF_INET, SOCK_DGRAM, 0);
  246. if (s == INVALID_SOCKET)
  247. return WSAGetLastError();
  248. for (;;) {
  249. dwErr = WSAIoctl(s, SIO_ADDRESS_LIST_QUERY, NULL, 0, pList, ulSize,
  250. &dwBytesReturned, NULL, NULL);
  251. if (!dwErr) {
  252. break;
  253. }
  254. if (pList) {
  255. FREE(pList);
  256. pList = NULL;
  257. }
  258. dwErr = WSAGetLastError();
  259. if (dwErr != WSAEFAULT)
  260. break;
  261. pList = MALLOC(dwBytesReturned);
  262. if (!pList) {
  263. dwErr = ERROR_NOT_ENOUGH_MEMORY;
  264. break;
  265. }
  266. ulSize = dwBytesReturned;
  267. }
  268. closesocket(s);
  269. *ppList = pList;
  270. return dwErr;
  271. }
  272. DWORD
  273. HandleIpShowJoins(
  274. IN LPCWSTR pwszMachine,
  275. IN OUT LPWSTR *ppwcArguments,
  276. IN DWORD dwCurrentIndex,
  277. IN DWORD dwArgCount,
  278. IN DWORD dwFlags,
  279. IN LPCVOID pvData,
  280. OUT BOOL *pbDone
  281. )
  282. {
  283. MIB_OPAQUE_QUERY Query;
  284. PMIB_IPADDRTABLE lprpcTable;
  285. DWORD dwOutBufLen = 0 ,
  286. dwNumParsed;
  287. IPV4_ADDRESS *pIgmpList = NULL,
  288. ipAddr;
  289. DWORD dwResult = NO_ERROR,
  290. dwOutEntrySize;
  291. DWORD i;
  292. PMIB_OPAQUE_INFO pRpcInfo;
  293. PWCHAR pszIfAddr;
  294. IFMON_CMD_ARG pArgs[] =
  295. {
  296. {
  297. IFMON_CMD_TYPE_STRING,
  298. {TOKEN_ADDR, FALSE, FALSE},
  299. NULL,
  300. 0,
  301. NULL
  302. }
  303. };
  304. do
  305. {
  306. dwResult = IfutlParse( ppwcArguments,
  307. dwCurrentIndex,
  308. dwArgCount,
  309. NULL,
  310. pArgs,
  311. sizeof(pArgs) / sizeof(*pArgs));
  312. if (dwResult)
  313. {
  314. break;
  315. }
  316. DisplayMessage(g_hModule, MSG_MIB_JOIN_HDR);
  317. if (pArgs[0].rgTag.bPresent)
  318. {
  319. // address specified
  320. pszIfAddr = IFMON_CMD_ARG_GetPsz(&pArgs[0]);
  321. dwResult = GetIpAddress( pszIfAddr, &ipAddr );
  322. if (dwResult)
  323. {
  324. break;
  325. }
  326. GetPrintJoinRow(ipAddr);
  327. }
  328. else
  329. {
  330. SOCKET_ADDRESS_LIST *pList;
  331. INT j;
  332. // Get all IPv4 addresses
  333. dwResult = GetIPv4Addresses(&pList);
  334. if (dwResult != NO_ERROR)
  335. break;
  336. // For each IPv4 address
  337. for (j=0; j<pList->iAddressCount; j++)
  338. {
  339. GetPrintJoinRow( ((LPSOCKADDR_IN)pList->Address[j].lpSockaddr)->sin_addr.s_addr );
  340. }
  341. FREE(pList);
  342. }
  343. } while (FALSE);
  344. return dwResult;
  345. }
  346. DWORD
  347. HandleIpMibShowObject(
  348. IN LPCWSTR pwszMachine,
  349. IN OUT LPWSTR *ppwcArguments,
  350. IN DWORD dwCurrentIndex,
  351. IN DWORD dwArgCount,
  352. IN DWORD dwFlags,
  353. IN LPCVOID pvData,
  354. OUT BOOL *pbDone
  355. )
  356. /*++
  357. Routine Description:
  358. Parses command to get MIB object and optional parameters
  359. Arguments:
  360. Return Value:
  361. --*/
  362. {
  363. DWORD dwIndices[MAX_NUM_INDICES];
  364. DWORD dwNumParsed = 0;
  365. PMIB_OPAQUE_QUERY pQuery = NULL;
  366. PMIB_OPAQUE_INFO pRpcInfo;
  367. DWORD dwQuerySize;
  368. BOOL bFound = FALSE,bOptPresent = FALSE;
  369. DWORD dwRefreshRate;
  370. DWORD dwOutEntrySize;
  371. DWORD i,dwResult,dwErr;
  372. DWORD dwMIBIndex, dwIndex;
  373. BOOL bIndex = FALSE, dwType;
  374. DWORD dwRR = 0, dwInd = 0;
  375. HANDLE hMib;
  376. #if 0
  377. TOKEN_VALUE tvMfeTypes[] =
  378. {
  379. { TOKEN_VALUE_POSITIVE, PositiveMfe },
  380. { TOKEN_VALUE_NEGATIVE, NegativeMfe },
  381. { TOKEN_VALUE_BOTH, Both }
  382. };
  383. #endif
  384. if ( ! IfutlIsRouterRunning() )
  385. {
  386. if (g_pwszRouter)
  387. {
  388. DisplayMessage(g_hModule,
  389. MSG_IP_REMOTE_ROUTER_NOT_RUNNING,
  390. g_pwszRouter);
  391. }
  392. else
  393. {
  394. DisplayMessage(g_hModule,
  395. MSG_IP_LOCAL_ROUTER_NOT_RUNNING);
  396. }
  397. return NO_ERROR;
  398. }
  399. //
  400. // Match MIB object
  401. //
  402. ppwcArguments += (dwCurrentIndex-1);
  403. dwArgCount -= (dwCurrentIndex-1);
  404. dwCurrentIndex = 1;
  405. //DEBUG2("In IP MIB Show : %s\n",pptcArguments[0]);
  406. for (i = 0; i < sizeof(MIBObjectMap)/sizeof(MIB_OBJECT_PARSER); i++)
  407. {
  408. if (MatchToken(ppwcArguments[0],MIBObjectMap[i].pwszMIBObj))
  409. {
  410. dwIndex = i;
  411. bFound = TRUE;
  412. break;
  413. }
  414. }
  415. if (!bFound)
  416. {
  417. return ERROR_CMD_NOT_FOUND;
  418. }
  419. #if 0
  420. //
  421. // Special case for MFEs where MFE type is specified
  422. // before index option
  423. //
  424. if ( ( MIBVar[ 2 * dwIndex ].dwId is MCAST_MFE ) ||
  425. ( MIBVar[ 2 * dwIndex ].dwId is MCAST_MFE_STATS ) )
  426. {
  427. if ( dwArgCount > 1 )
  428. {
  429. if ( !_wcsnicmp( ppwcArguments[ 1 ], L"TYPE=", 5 ) )
  430. {
  431. wcscpy( ppwcArguments[ 1 ], &ppwcArguments[ 1 ][ 5 ] );
  432. }
  433. dwErr = MatchEnumTag(
  434. g_hModule, ppwcArguments[ 1 ],
  435. NUM_TOKENS_IN_TABLE( tvMfeTypes ), tvMfeTypes,
  436. &dwType
  437. );
  438. }
  439. else
  440. {
  441. dwErr = ERROR_INVALID_PARAMETER;
  442. }
  443. if (dwErr isnot NO_ERROR)
  444. {
  445. return ERROR_INVALID_SYNTAX;
  446. }
  447. dwErr = GetMibTagToken(&ppwcArguments[2],
  448. dwArgCount - 2,
  449. MIBObjectMap[dwIndex].dwMinOptArg,
  450. &dwRR,
  451. &bIndex,
  452. &dwInd);
  453. }
  454. else
  455. #endif
  456. {
  457. dwErr = GetMibTagToken(&ppwcArguments[1],
  458. dwArgCount - 1,
  459. MIBObjectMap[dwIndex].dwMinOptArg,
  460. &dwRR,
  461. &bIndex,
  462. &dwInd);
  463. }
  464. if (dwErr isnot NO_ERROR)
  465. {
  466. return ERROR_INVALID_SYNTAX;
  467. }
  468. if (bIndex)
  469. {
  470. dwMIBIndex = dwIndex * 2;
  471. bOptPresent = TRUE;
  472. }
  473. else
  474. {
  475. dwMIBIndex = dwIndex * 2 + 1;
  476. }
  477. //
  478. // Convert refresh rate to msec
  479. //
  480. dwRR *= 1000;
  481. if (!InitializeConsole(&dwRR, &hMib, &g_hConsole))
  482. {
  483. return ERROR_INIT_DISPLAY;
  484. }
  485. //
  486. // Query the MIB
  487. //
  488. pQuery = NULL;
  489. for ( ; ; )
  490. {
  491. if(dwRR)
  492. {
  493. DisplayMessageToConsole(g_hModule,
  494. g_hConsole,
  495. MSG_CTRL_C_TO_QUIT);
  496. }
  497. // always...
  498. {
  499. if (!(dwMIBIndex % 2))
  500. {
  501. (*MIBObjectMap[dwIndex].pfnMIBObjParser)(ppwcArguments,
  502. 1,
  503. dwIndices,
  504. &dwNumParsed);
  505. }
  506. dwQuerySize = ( sizeof( MIB_OPAQUE_QUERY ) - sizeof( DWORD ) ) +
  507. (dwNumParsed) * sizeof(DWORD);
  508. pQuery = (PMIB_OPAQUE_QUERY)HeapAlloc(GetProcessHeap(),
  509. 0,
  510. dwQuerySize);
  511. if (pQuery is NULL)
  512. {
  513. dwErr = ERROR_NOT_ENOUGH_MEMORY;
  514. DisplayMessage(g_hModule, MSG_IP_NOT_ENOUGH_MEMORY);
  515. return dwErr;
  516. }
  517. pQuery->dwVarId = MIBVar[dwMIBIndex].dwId;
  518. for( i = 0; i < dwNumParsed; i++ )
  519. {
  520. pQuery->rgdwVarIndex[i] = dwIndices[i];
  521. }
  522. dwResult = MibGet( PID_IP,
  523. IPRTRMGR_PID,
  524. (PVOID) pQuery,
  525. dwQuerySize,
  526. (PVOID *) &pRpcInfo,
  527. &dwOutEntrySize );
  528. if ( dwResult isnot NO_ERROR )
  529. {
  530. DisplayMessage(g_hModule, MSG_IP_DIM_ERROR, dwResult );
  531. return dwResult;
  532. }
  533. if ( pRpcInfo is NULL )
  534. {
  535. DisplayMessage(g_hModule, MSG_IP_NO_ENTRIES );
  536. return dwResult;
  537. }
  538. (*MIBVar[dwMIBIndex].pfnPrintFunction)(g_hMIBServer, pRpcInfo);
  539. MprAdminMIBBufferFree( (PVOID) pRpcInfo );
  540. }
  541. if(pQuery != NULL )
  542. {
  543. HeapFree(GetProcessHeap(),0,pQuery);
  544. }
  545. if (!RefreshConsole(hMib, g_hConsole, dwRR))
  546. {
  547. break;
  548. }
  549. }
  550. return dwResult;
  551. }
  552. VOID
  553. PrintIfTable(
  554. MIB_SERVER_HANDLE hMibServer,
  555. PMIB_OPAQUE_INFO prpcInfo
  556. )
  557. /*++
  558. Routine Description:
  559. Prints interface table information
  560. Arguments:
  561. Return Value:
  562. --*/
  563. {
  564. PMIB_IFTABLE lprpcTable = (PMIB_IFTABLE)(prpcInfo->rgbyData);
  565. PTCHAR ptszIfType, ptszOper, ptszAdmin;
  566. TCHAR tszDescr[MAXLEN_IFDESCR + 1], tszIfName[MAX_INTERFACE_NAME_LEN + 1];
  567. TCHAR tszPhysAddr[DISPLAYLEN_PHYSADDR + 1];
  568. WCHAR wszBuffer[MAX_INTERFACE_NAME_LEN+1];
  569. DWORD dwSize;
  570. DWORD dwCount = lprpcTable->dwNumEntries;
  571. DWORD i;
  572. DisplayMessageToConsole(g_hModule,
  573. g_hConsole,
  574. MSG_MIB_IF_HDR);
  575. if ( dwCount is 0 )
  576. {
  577. DisplayMessageToConsole(g_hModule, g_hConsole, MSG_IP_NO_ENTRIES);
  578. return;
  579. }
  580. for(i = 0; i < dwCount; i++)
  581. {
  582. switch(lprpcTable->table[i].dwType)
  583. {
  584. case IF_TYPE_ETHERNET_CSMACD:
  585. {
  586. ptszIfType = MakeString(g_hModule, STRING_ETHERNET);
  587. break;
  588. }
  589. case IF_TYPE_ISO88025_TOKENRING:
  590. {
  591. ptszIfType = MakeString(g_hModule, STRING_TOKENRING);
  592. break;
  593. }
  594. case IF_TYPE_FDDI:
  595. {
  596. ptszIfType = MakeString(g_hModule, STRING_FDDI);
  597. break;
  598. }
  599. case IF_TYPE_PPP:
  600. {
  601. ptszIfType = MakeString(g_hModule, STRING_PPP);
  602. break;
  603. }
  604. case IF_TYPE_SOFTWARE_LOOPBACK:
  605. {
  606. ptszIfType = MakeString(g_hModule, STRING_LOOPBACK);
  607. break;
  608. }
  609. case IF_TYPE_SLIP:
  610. {
  611. ptszIfType = MakeString(g_hModule, STRING_SLIP);
  612. break;
  613. }
  614. case IF_TYPE_OTHER:
  615. default:
  616. {
  617. ptszIfType = MakeString(g_hModule, STRING_OTHER);
  618. break;
  619. }
  620. }
  621. switch(lprpcTable->table[i].dwAdminStatus)
  622. {
  623. case IF_ADMIN_STATUS_UP:
  624. {
  625. ptszAdmin = MakeString(g_hModule, STRING_UP);
  626. break;
  627. }
  628. case IF_ADMIN_STATUS_TESTING:
  629. {
  630. ptszAdmin = MakeString(g_hModule, STRING_TESTING);
  631. break;
  632. }
  633. case IF_ADMIN_STATUS_DOWN:
  634. default:
  635. {
  636. ptszAdmin = MakeString(g_hModule, STRING_DOWN);
  637. break;
  638. }
  639. }
  640. switch(lprpcTable->table[i].dwOperStatus)
  641. {
  642. case IF_OPER_STATUS_UNREACHABLE:
  643. {
  644. ptszOper = MakeString(g_hModule, STRING_UNREACHABLE);
  645. break;
  646. }
  647. case IF_OPER_STATUS_DISCONNECTED:
  648. {
  649. ptszOper = MakeString(g_hModule, STRING_DISCONNECTED);
  650. break;
  651. }
  652. case IF_OPER_STATUS_CONNECTING:
  653. {
  654. ptszOper = MakeString(g_hModule, STRING_CONNECTING);
  655. break;
  656. }
  657. case IF_OPER_STATUS_CONNECTED:
  658. {
  659. ptszOper = MakeString(g_hModule, STRING_CONNECTED);
  660. break;
  661. }
  662. case IF_OPER_STATUS_OPERATIONAL:
  663. {
  664. ptszOper = MakeString(g_hModule, STRING_OPERATIONAL);
  665. break;
  666. }
  667. case IF_OPER_STATUS_NON_OPERATIONAL:
  668. default:
  669. {
  670. ptszOper = MakeString(g_hModule, STRING_NON_OPERATIONAL);
  671. break;
  672. }
  673. }
  674. #ifdef UNICODE
  675. wcscpy(tszIfName, lprpcTable->table[i].wszName);
  676. MultiByteToWideChar(GetConsoleOutputCP(),
  677. 0,
  678. lprpcTable->table[i].bDescr,
  679. -1,
  680. tszDescr,
  681. MAXLEN_IFDESCR);
  682. #else
  683. WideCharToMultiByte(GetConsoleOutputCP(),
  684. 0,
  685. lprpcTable->table[i].wszName,
  686. -1,
  687. tszIfName,
  688. MAX_INTERFACE_NAME_LEN,
  689. NULL,
  690. NULL);
  691. strcpy(tszDescr,lprpcTable->table[i].bDescr);
  692. #endif
  693. if (lprpcTable->table[i].dwPhysAddrLen == 0)
  694. {
  695. tszPhysAddr[0] = TEXT('\0');
  696. }
  697. else
  698. {
  699. MakeUnicodePhysAddr(tszPhysAddr,
  700. lprpcTable->table[i].bPhysAddr,
  701. lprpcTable->table[i].dwPhysAddrLen);
  702. }
  703. dwSize = sizeof(wszBuffer);
  704. IfutlGetInterfaceDescription( tszIfName, wszBuffer, &dwSize );
  705. DisplayMessageToConsole(g_hModule, g_hConsole,MSG_MIB_INTERFACE,
  706. lprpcTable->table[i].dwIndex,
  707. wszBuffer,
  708. tszIfName,
  709. ptszIfType,
  710. lprpcTable->table[i].dwMtu,
  711. lprpcTable->table[i].dwSpeed,
  712. tszPhysAddr,
  713. ptszAdmin,
  714. ptszOper,
  715. lprpcTable->table[i].dwLastChange,
  716. lprpcTable->table[i].dwInOctets,
  717. lprpcTable->table[i].dwInUcastPkts,
  718. lprpcTable->table[i].dwInNUcastPkts,
  719. lprpcTable->table[i].dwInDiscards,
  720. lprpcTable->table[i].dwInErrors,
  721. lprpcTable->table[i].dwInUnknownProtos,
  722. lprpcTable->table[i].dwOutOctets,
  723. lprpcTable->table[i].dwOutUcastPkts,
  724. lprpcTable->table[i].dwOutNUcastPkts,
  725. lprpcTable->table[i].dwOutDiscards,
  726. lprpcTable->table[i].dwOutErrors,
  727. lprpcTable->table[i].dwOutQLen,
  728. tszDescr);
  729. FreeString(ptszIfType);
  730. FreeString(ptszAdmin);
  731. FreeString(ptszOper);
  732. }
  733. }
  734. VOID
  735. PrintIfRow(
  736. MIB_SERVER_HANDLE hMibServer,
  737. PMIB_OPAQUE_INFO prpcInfo
  738. )
  739. /*++
  740. Routine Description:
  741. Prints interface row information
  742. Arguments:
  743. Return Value:
  744. --*/
  745. {
  746. PMIB_IFROW ieRow = (PMIB_IFROW)(prpcInfo->rgbyData);
  747. PTCHAR ptszIfType, ptszOper, ptszAdmin;
  748. TCHAR tszDescr[MAXLEN_IFDESCR + 1], tszIfName[MAX_INTERFACE_NAME_LEN + 1];
  749. TCHAR tszPhysAddr[DISPLAYLEN_PHYSADDR + 1];
  750. WCHAR wszBuffer[MAX_INTERFACE_NAME_LEN+1];
  751. DWORD dwSize;
  752. DisplayMessageToConsole(g_hModule,
  753. g_hConsole,
  754. MSG_MIB_IF_HDR);
  755. switch(ieRow->dwType)
  756. {
  757. case IF_TYPE_ETHERNET_CSMACD:
  758. {
  759. ptszIfType = MakeString(g_hModule, STRING_ETHERNET);
  760. break;
  761. }
  762. case IF_TYPE_ISO88025_TOKENRING:
  763. {
  764. ptszIfType = MakeString(g_hModule, STRING_TOKENRING);
  765. break;
  766. }
  767. case IF_TYPE_FDDI:
  768. {
  769. ptszIfType = MakeString(g_hModule, STRING_FDDI);
  770. break;
  771. }
  772. case IF_TYPE_PPP:
  773. {
  774. ptszIfType = MakeString(g_hModule, STRING_PPP);
  775. break;
  776. }
  777. case IF_TYPE_SOFTWARE_LOOPBACK:
  778. {
  779. ptszIfType = MakeString(g_hModule, STRING_LOOPBACK);
  780. break;
  781. }
  782. case IF_TYPE_SLIP:
  783. {
  784. ptszIfType = MakeString(g_hModule, STRING_SLIP);
  785. break;
  786. }
  787. case IF_TYPE_OTHER:
  788. default:
  789. {
  790. ptszIfType = MakeString(g_hModule, STRING_OTHER);
  791. break;
  792. }
  793. }
  794. switch(ieRow->dwAdminStatus)
  795. {
  796. case IF_ADMIN_STATUS_UP:
  797. {
  798. ptszAdmin = MakeString(g_hModule, STRING_UP);
  799. break;
  800. }
  801. case IF_ADMIN_STATUS_TESTING:
  802. {
  803. ptszAdmin = MakeString(g_hModule, STRING_TESTING);
  804. break;
  805. }
  806. case IF_ADMIN_STATUS_DOWN:
  807. default:
  808. {
  809. ptszAdmin = MakeString(g_hModule, STRING_DOWN);
  810. break;
  811. }
  812. }
  813. switch(ieRow->dwOperStatus)
  814. {
  815. case IF_OPER_STATUS_UNREACHABLE:
  816. {
  817. ptszOper = MakeString(g_hModule, STRING_UNREACHABLE);
  818. break;
  819. }
  820. case IF_OPER_STATUS_DISCONNECTED:
  821. {
  822. ptszOper = MakeString(g_hModule, STRING_DISCONNECTED);
  823. break;
  824. }
  825. case IF_OPER_STATUS_CONNECTING:
  826. {
  827. ptszOper = MakeString(g_hModule, STRING_CONNECTING);
  828. break;
  829. }
  830. case IF_OPER_STATUS_CONNECTED:
  831. {
  832. ptszOper = MakeString(g_hModule, STRING_CONNECTED);
  833. break;
  834. }
  835. case IF_OPER_STATUS_OPERATIONAL:
  836. {
  837. ptszOper = MakeString(g_hModule, STRING_OPERATIONAL);
  838. break;
  839. }
  840. case IF_OPER_STATUS_NON_OPERATIONAL:
  841. default:
  842. {
  843. ptszOper = MakeString(g_hModule, STRING_NON_OPERATIONAL);
  844. break;
  845. }
  846. }
  847. #ifdef UNICODE
  848. wcscpy(tszIfName, ieRow->wszName);
  849. MultiByteToWideChar(GetConsoleOutputCP(),
  850. 0,
  851. ieRow->bDescr,
  852. -1,
  853. tszDescr,
  854. MAXLEN_IFDESCR);
  855. #else
  856. WideCharToMultiByte(GetConsoleOutputCP(),
  857. 0,
  858. ieRow->wszName,
  859. -1,
  860. tszIfName,
  861. MAX_INTERFACE_NAME_LEN,
  862. NULL,
  863. NULL);
  864. strcpy(tszDescr,ieRow->bDescr);
  865. #endif
  866. if (ieRow->dwPhysAddrLen == 0)
  867. {
  868. tszPhysAddr[0] = TEXT('\0');
  869. }
  870. else
  871. {
  872. MakeUnicodePhysAddr(tszPhysAddr,ieRow->bPhysAddr,ieRow->dwPhysAddrLen);
  873. }
  874. dwSize = sizeof(wszBuffer);
  875. IfutlGetInterfaceDescription( tszIfName, wszBuffer, &dwSize );
  876. DisplayMessageToConsole(g_hModule, g_hConsole,MSG_MIB_INTERFACE,
  877. ieRow->dwIndex,
  878. wszBuffer,
  879. tszIfName,
  880. ptszIfType,
  881. ieRow->dwMtu,
  882. ieRow->dwSpeed,
  883. tszPhysAddr,
  884. ptszAdmin,
  885. ptszOper,
  886. ieRow->dwLastChange,
  887. ieRow->dwInOctets,
  888. ieRow->dwInUcastPkts,
  889. ieRow->dwInNUcastPkts,
  890. ieRow->dwInDiscards,
  891. ieRow->dwInErrors,
  892. ieRow->dwInUnknownProtos,
  893. ieRow->dwOutOctets,
  894. ieRow->dwOutUcastPkts,
  895. ieRow->dwOutNUcastPkts,
  896. ieRow->dwOutDiscards,
  897. ieRow->dwOutErrors,
  898. ieRow->dwOutQLen,
  899. tszDescr);
  900. FreeString(ptszIfType);
  901. FreeString(ptszAdmin);
  902. FreeString(ptszOper);
  903. }
  904. VOID
  905. PrintIcmp(
  906. MIB_SERVER_HANDLE hMibServer,
  907. PMIB_OPAQUE_INFO prpcInfo
  908. )
  909. /*++
  910. Routine Description:
  911. Prints ICMP information.
  912. Arguments:
  913. Return Value:
  914. --*/
  915. {
  916. PMIB_ICMP lprpcIcmp = (PMIB_ICMP)(prpcInfo->rgbyData);
  917. DisplayMessageToConsole(g_hModule, g_hConsole,MSG_MIB_ICMP,
  918. lprpcIcmp->stats.icmpInStats.dwMsgs,
  919. lprpcIcmp->stats.icmpInStats.dwErrors,
  920. lprpcIcmp->stats.icmpInStats.dwDestUnreachs,
  921. lprpcIcmp->stats.icmpInStats.dwTimeExcds,
  922. lprpcIcmp->stats.icmpInStats.dwParmProbs,
  923. lprpcIcmp->stats.icmpInStats.dwSrcQuenchs,
  924. lprpcIcmp->stats.icmpInStats.dwRedirects,
  925. lprpcIcmp->stats.icmpInStats.dwEchos,
  926. lprpcIcmp->stats.icmpInStats.dwEchoReps,
  927. lprpcIcmp->stats.icmpInStats.dwTimestamps,
  928. lprpcIcmp->stats.icmpInStats.dwTimestampReps,
  929. lprpcIcmp->stats.icmpInStats.dwAddrMasks,
  930. lprpcIcmp->stats.icmpInStats.dwAddrMaskReps,
  931. lprpcIcmp->stats.icmpOutStats.dwMsgs,
  932. lprpcIcmp->stats.icmpOutStats.dwErrors,
  933. lprpcIcmp->stats.icmpOutStats.dwDestUnreachs,
  934. lprpcIcmp->stats.icmpOutStats.dwTimeExcds,
  935. lprpcIcmp->stats.icmpOutStats.dwParmProbs,
  936. lprpcIcmp->stats.icmpOutStats.dwSrcQuenchs,
  937. lprpcIcmp->stats.icmpOutStats.dwRedirects,
  938. lprpcIcmp->stats.icmpOutStats.dwEchos,
  939. lprpcIcmp->stats.icmpOutStats.dwEchoReps,
  940. lprpcIcmp->stats.icmpOutStats.dwTimestamps,
  941. lprpcIcmp->stats.icmpOutStats.dwTimestampReps,
  942. lprpcIcmp->stats.icmpOutStats.dwAddrMasks,
  943. lprpcIcmp->stats.icmpOutStats.dwAddrMaskReps);
  944. }
  945. VOID
  946. PrintUdpStats(
  947. MIB_SERVER_HANDLE hMibServer,
  948. PMIB_OPAQUE_INFO prpcInfo
  949. )
  950. /*++
  951. Routine Description:
  952. Prints UDP statistics.
  953. Arguments:
  954. Return Value:
  955. --*/
  956. {
  957. PMIB_UDPSTATS lprpcUdp = (PMIB_UDPSTATS)(prpcInfo->rgbyData);
  958. DisplayMessageToConsole(g_hModule, g_hConsole,MSG_MIB_UDP_STATS,
  959. lprpcUdp->dwInDatagrams,
  960. lprpcUdp->dwNoPorts,
  961. lprpcUdp->dwInErrors,
  962. lprpcUdp->dwOutDatagrams);
  963. }
  964. VOID
  965. PrintUdpTable(
  966. MIB_SERVER_HANDLE hMibServer,
  967. PMIB_OPAQUE_INFO prpcInfo
  968. )
  969. /*++
  970. Routine Description:
  971. Prints UDP table information.
  972. Arguments:
  973. Return Value:
  974. --*/
  975. {
  976. PMIB_UDPTABLE lprpcTable = (PMIB_UDPTABLE)(prpcInfo->rgbyData);
  977. TCHAR tszAddr[ADDR_LENGTH + 1];
  978. DWORD i;
  979. DisplayMessageToConsole(g_hModule, g_hConsole,MSG_MIB_UDP_ENTRY_HDR);
  980. if(lprpcTable->dwNumEntries is 0)
  981. {
  982. DisplayMessageToConsole(g_hModule, g_hConsole,MSG_IP_NO_ENTRIES);
  983. return;
  984. }
  985. for(i = 0; i < lprpcTable->dwNumEntries; i++)
  986. {
  987. MakeUnicodeIpAddr(tszAddr,
  988. inet_ntoa(*((struct in_addr *)(&lprpcTable->table[i].dwLocalAddr))));
  989. DisplayMessageToConsole(g_hModule, g_hConsole,MSG_MIB_UDP_ENTRY,
  990. tszAddr,
  991. ntohs((WORD)lprpcTable->table[i].dwLocalPort));
  992. }
  993. }
  994. VOID
  995. PrintUdpRow(
  996. MIB_SERVER_HANDLE hMibServer,
  997. PMIB_OPAQUE_INFO prpcInfo
  998. )
  999. /*++
  1000. Routine Description:
  1001. Prints UDP row information.
  1002. Arguments:
  1003. Return Value:
  1004. --*/
  1005. {
  1006. PMIB_UDPROW ueRow = (PMIB_UDPROW)(prpcInfo->rgbyData);
  1007. TCHAR tszAddr[ADDR_LENGTH + 1];
  1008. DisplayMessageToConsole(g_hModule, g_hConsole,MSG_MIB_UDP_ENTRY_HDR);
  1009. MakeUnicodeIpAddr(tszAddr,inet_ntoa(*((struct in_addr *)
  1010. (&ueRow->dwLocalAddr))));
  1011. DisplayMessageToConsole(g_hModule, g_hConsole,MSG_MIB_UDP_ENTRY,
  1012. tszAddr,
  1013. ntohs((WORD)ueRow->dwLocalPort));
  1014. }
  1015. VOID
  1016. PrintTcpStats(
  1017. MIB_SERVER_HANDLE hMibServer,
  1018. PMIB_OPAQUE_INFO prpcInfo
  1019. )
  1020. /*++
  1021. Routine Description:
  1022. Prints TCP Statistics
  1023. Arguments:
  1024. Return Value:
  1025. --*/
  1026. {
  1027. PMIB_TCPSTATS lprpcTcp = (PMIB_TCPSTATS)(prpcInfo->rgbyData);
  1028. PTCHAR ptszMaxConn, ptszAlgo;
  1029. switch(lprpcTcp->dwRtoAlgorithm)
  1030. {
  1031. case MIB_TCP_RTO_CONSTANT:
  1032. {
  1033. ptszAlgo = MakeString(g_hModule, STRING_CONSTANT);
  1034. break;
  1035. }
  1036. case MIB_TCP_RTO_RSRE:
  1037. {
  1038. ptszAlgo = MakeString(g_hModule, STRING_RSRE);
  1039. break;
  1040. }
  1041. case MIB_TCP_RTO_VANJ:
  1042. {
  1043. ptszAlgo = MakeString(g_hModule, STRING_VANJ);
  1044. break;
  1045. }
  1046. case MIB_TCP_RTO_OTHER:
  1047. default:
  1048. {
  1049. ptszAlgo = MakeString(g_hModule, STRING_OTHER);
  1050. break;
  1051. }
  1052. }
  1053. if(lprpcTcp->dwMaxConn is MIB_TCP_MAXCONN_DYNAMIC)
  1054. {
  1055. ptszMaxConn = MakeString(g_hModule, STRING_DYNAMIC);
  1056. }
  1057. else
  1058. {
  1059. ptszMaxConn = HeapAlloc(GetProcessHeap(),0,20);
  1060. if(ptszMaxConn is NULL)
  1061. {
  1062. return;
  1063. }
  1064. _stprintf(ptszMaxConn,TEXT("%d"),lprpcTcp->dwMaxConn);
  1065. }
  1066. DisplayMessageToConsole(g_hModule, g_hConsole,MSG_MIB_TCP_STATS,
  1067. ptszAlgo,
  1068. lprpcTcp->dwRtoMin,
  1069. lprpcTcp->dwRtoMax,
  1070. ptszMaxConn,
  1071. lprpcTcp->dwActiveOpens,
  1072. lprpcTcp->dwPassiveOpens,
  1073. lprpcTcp->dwAttemptFails,
  1074. lprpcTcp->dwEstabResets,
  1075. lprpcTcp->dwCurrEstab,
  1076. lprpcTcp->dwInSegs,
  1077. lprpcTcp->dwOutSegs,
  1078. lprpcTcp->dwRetransSegs,
  1079. lprpcTcp->dwInErrs,
  1080. lprpcTcp->dwOutRsts);
  1081. FreeString(ptszAlgo);
  1082. if(lprpcTcp->dwMaxConn is MIB_TCP_MAXCONN_DYNAMIC)
  1083. {
  1084. FreeString(ptszMaxConn);
  1085. }
  1086. else
  1087. {
  1088. HeapFree(GetProcessHeap,0,ptszMaxConn);
  1089. }
  1090. }
  1091. VOID
  1092. PrintTcpTable(
  1093. MIB_SERVER_HANDLE hMibServer,
  1094. PMIB_OPAQUE_INFO prpcInfo
  1095. )
  1096. /*++
  1097. Routine Description:
  1098. Prints TCP table information.
  1099. Arguments:
  1100. Return Value:
  1101. --*/
  1102. {
  1103. PMIB_TCPTABLE lprpcTable = (PMIB_TCPTABLE)(prpcInfo->rgbyData);
  1104. TCHAR tszLAddr[ADDR_LENGTH + 1], tszRAddr[ADDR_LENGTH + 1];
  1105. PTCHAR ptszState;
  1106. DWORD i;
  1107. DisplayMessageToConsole(g_hModule, g_hConsole,MSG_MIB_TCP_ENTRY_HDR);
  1108. if(lprpcTable->dwNumEntries is 0)
  1109. {
  1110. DisplayMessageToConsole(g_hModule, g_hConsole,MSG_IP_NO_ENTRIES);
  1111. return;
  1112. }
  1113. for(i = 0; i < lprpcTable->dwNumEntries; i++)
  1114. {
  1115. switch(lprpcTable->table[i].dwState)
  1116. {
  1117. case MIB_TCP_STATE_CLOSED:
  1118. {
  1119. ptszState = MakeString(g_hModule, STRING_CLOSED);
  1120. break;
  1121. }
  1122. case MIB_TCP_STATE_LISTEN:
  1123. {
  1124. ptszState = MakeString(g_hModule, STRING_LISTEN);
  1125. break;
  1126. }
  1127. case MIB_TCP_STATE_SYN_SENT:
  1128. {
  1129. ptszState = MakeString(g_hModule, STRING_SYN_SENT);
  1130. break;
  1131. }
  1132. case MIB_TCP_STATE_SYN_RCVD:
  1133. {
  1134. ptszState = MakeString(g_hModule, STRING_SYN_RCVD);
  1135. break;
  1136. }
  1137. case MIB_TCP_STATE_ESTAB:
  1138. {
  1139. ptszState = MakeString(g_hModule, STRING_ESTAB);
  1140. break;
  1141. }
  1142. case MIB_TCP_STATE_FIN_WAIT1:
  1143. {
  1144. ptszState = MakeString(g_hModule, STRING_FIN_WAIT1);
  1145. break;
  1146. }
  1147. case MIB_TCP_STATE_FIN_WAIT2:
  1148. {
  1149. ptszState = MakeString(g_hModule, STRING_FIN_WAIT2);
  1150. break;
  1151. }
  1152. case MIB_TCP_STATE_CLOSE_WAIT:
  1153. {
  1154. ptszState = MakeString(g_hModule, STRING_CLOSE_WAIT);
  1155. break;
  1156. }
  1157. case MIB_TCP_STATE_CLOSING:
  1158. {
  1159. ptszState = MakeString(g_hModule, STRING_CLOSING);
  1160. break;
  1161. }
  1162. case MIB_TCP_STATE_LAST_ACK:
  1163. {
  1164. ptszState = MakeString(g_hModule, STRING_LAST_ACK);
  1165. break;
  1166. }
  1167. case MIB_TCP_STATE_TIME_WAIT:
  1168. {
  1169. ptszState = MakeString(g_hModule, STRING_TIME_WAIT);
  1170. break;
  1171. }
  1172. case MIB_TCP_STATE_DELETE_TCB :
  1173. {
  1174. ptszState = MakeString(g_hModule, STRING_DELETE_TCB);
  1175. break;
  1176. }
  1177. }
  1178. MakeUnicodeIpAddr(tszLAddr,
  1179. inet_ntoa(*((struct in_addr *)
  1180. (&lprpcTable->table[i].dwLocalAddr))));
  1181. MakeUnicodeIpAddr(tszRAddr,
  1182. inet_ntoa(*((struct in_addr *)
  1183. (&lprpcTable->table[i].dwRemoteAddr))));
  1184. DisplayMessageToConsole(g_hModule, g_hConsole,MSG_MIB_TCP_ENTRY,
  1185. tszLAddr,
  1186. ntohs((WORD)lprpcTable->table[i].dwLocalPort),
  1187. tszRAddr,
  1188. ntohs((WORD)lprpcTable->table[i].dwRemotePort),
  1189. ptszState);
  1190. FreeString(ptszState);
  1191. }
  1192. }
  1193. VOID
  1194. PrintTcpRow(
  1195. MIB_SERVER_HANDLE hMibServer,
  1196. PMIB_OPAQUE_INFO prpcInfo
  1197. )
  1198. /*++
  1199. Routine Description:
  1200. Prints TCP row information.
  1201. Arguments:
  1202. Return Value:
  1203. --*/
  1204. {
  1205. PMIB_TCPROW tcteRow = (PMIB_TCPROW)(prpcInfo->rgbyData);
  1206. TCHAR tszLAddr[ADDR_LENGTH + 1], tszRAddr[ADDR_LENGTH + 1];
  1207. PTCHAR ptszState;
  1208. DisplayMessageToConsole(g_hModule, g_hConsole,MSG_MIB_TCP_ENTRY_HDR);
  1209. switch(tcteRow->dwState)
  1210. {
  1211. case MIB_TCP_STATE_CLOSED:
  1212. {
  1213. ptszState = MakeString(g_hModule, STRING_CLOSED);
  1214. break;
  1215. }
  1216. case MIB_TCP_STATE_LISTEN:
  1217. {
  1218. ptszState = MakeString(g_hModule, STRING_LISTEN);
  1219. break;
  1220. }
  1221. case MIB_TCP_STATE_SYN_SENT:
  1222. {
  1223. ptszState = MakeString(g_hModule, STRING_SYN_SENT);
  1224. break;
  1225. }
  1226. case MIB_TCP_STATE_SYN_RCVD:
  1227. {
  1228. ptszState = MakeString(g_hModule, STRING_SYN_RCVD);
  1229. break;
  1230. }
  1231. case MIB_TCP_STATE_ESTAB:
  1232. {
  1233. ptszState = MakeString(g_hModule, STRING_ESTAB);
  1234. break;
  1235. }
  1236. case MIB_TCP_STATE_FIN_WAIT1:
  1237. {
  1238. ptszState = MakeString(g_hModule, STRING_FIN_WAIT1);
  1239. break;
  1240. }
  1241. case MIB_TCP_STATE_FIN_WAIT2:
  1242. {
  1243. ptszState = MakeString(g_hModule, STRING_FIN_WAIT2);
  1244. break;
  1245. }
  1246. case MIB_TCP_STATE_CLOSE_WAIT:
  1247. {
  1248. ptszState = MakeString(g_hModule, STRING_CLOSE_WAIT);
  1249. break;
  1250. }
  1251. case MIB_TCP_STATE_CLOSING:
  1252. {
  1253. ptszState = MakeString(g_hModule, STRING_CLOSING);
  1254. break;
  1255. }
  1256. case MIB_TCP_STATE_LAST_ACK:
  1257. {
  1258. ptszState = MakeString(g_hModule, STRING_LAST_ACK);
  1259. break;
  1260. }
  1261. case MIB_TCP_STATE_TIME_WAIT:
  1262. {
  1263. ptszState = MakeString(g_hModule, STRING_TIME_WAIT);
  1264. break;
  1265. }
  1266. case MIB_TCP_STATE_DELETE_TCB :
  1267. {
  1268. ptszState = MakeString(g_hModule, STRING_DELETE_TCB);
  1269. break;
  1270. }
  1271. }
  1272. MakeUnicodeIpAddr(tszLAddr, inet_ntoa(*((struct in_addr *)
  1273. (&tcteRow->dwLocalAddr))));
  1274. MakeUnicodeIpAddr(tszRAddr, inet_ntoa(*((struct in_addr *)
  1275. (&tcteRow->dwRemoteAddr))));
  1276. DisplayMessageToConsole(g_hModule, g_hConsole,MSG_MIB_TCP_ENTRY,
  1277. tszLAddr,
  1278. ntohs((WORD)tcteRow->dwLocalPort),
  1279. tszRAddr,
  1280. ntohs((WORD)tcteRow->dwRemotePort),
  1281. ptszState);
  1282. FreeString(ptszState);
  1283. }
  1284. VOID
  1285. PrintIpStats(
  1286. MIB_SERVER_HANDLE hMibServer,
  1287. PMIB_OPAQUE_INFO prpcInfo
  1288. )
  1289. {
  1290. PMIB_IPSTATS lprpcIp = (PMIB_IPSTATS)(prpcInfo->rgbyData);
  1291. PTCHAR ptszForw;
  1292. if(lprpcIp->dwForwarding is MIB_IP_FORWARDING)
  1293. {
  1294. ptszForw = MakeString(g_hModule, STRING_ENABLED);
  1295. }
  1296. else
  1297. {
  1298. ptszForw = MakeString(g_hModule, STRING_DISABLED);
  1299. }
  1300. DisplayMessageToConsole(g_hModule, g_hConsole,MSG_MIB_IP_STATS,
  1301. ptszForw,
  1302. lprpcIp->dwDefaultTTL,
  1303. lprpcIp->dwInReceives,
  1304. lprpcIp->dwInHdrErrors,
  1305. lprpcIp->dwInAddrErrors,
  1306. lprpcIp->dwForwDatagrams,
  1307. lprpcIp->dwInUnknownProtos,
  1308. lprpcIp->dwInDiscards,
  1309. lprpcIp->dwInDelivers,
  1310. lprpcIp->dwOutRequests,
  1311. lprpcIp->dwRoutingDiscards,
  1312. lprpcIp->dwOutDiscards,
  1313. lprpcIp->dwOutNoRoutes,
  1314. lprpcIp->dwReasmTimeout,
  1315. lprpcIp->dwReasmReqds,
  1316. lprpcIp->dwReasmOks,
  1317. lprpcIp->dwReasmFails,
  1318. lprpcIp->dwFragOks,
  1319. lprpcIp->dwFragFails,
  1320. lprpcIp->dwFragCreates);
  1321. FreeString(ptszForw);
  1322. }
  1323. VOID
  1324. PrintIpAddrTable(
  1325. MIB_SERVER_HANDLE hMibServer,
  1326. PMIB_OPAQUE_INFO prpcInfo
  1327. )
  1328. /*++
  1329. Routine Description:
  1330. Prints IP address table.
  1331. Arguments:
  1332. Return Value:
  1333. --*/
  1334. {
  1335. WCHAR wszFriendlyName[MAX_INTERFACE_NAME_LEN + 1];
  1336. PMIB_IPADDRTABLE lprpcTable;
  1337. TCHAR tszAddr[ADDR_LENGTH + 1], tszMask[ADDR_LENGTH + 1];
  1338. DWORD i, dwErr = NO_ERROR;
  1339. lprpcTable = (PMIB_IPADDRTABLE)(prpcInfo->rgbyData);
  1340. DisplayMessageToConsole(g_hModule, g_hConsole,MSG_MIB_IP_ADDR_HDR);
  1341. if(lprpcTable->dwNumEntries is 0)
  1342. {
  1343. DisplayMessageToConsole(g_hModule, g_hConsole,MSG_IP_NO_ENTRIES);
  1344. return;
  1345. }
  1346. for(i = 0; i < lprpcTable->dwNumEntries; i++)
  1347. {
  1348. DWORD BufLen;
  1349. MakeUnicodeIpAddr(tszAddr,
  1350. inet_ntoa(*((struct in_addr *)
  1351. (&lprpcTable->table[i].dwAddr))));
  1352. MakeUnicodeIpAddr(tszMask,
  1353. inet_ntoa(*((struct in_addr *)
  1354. (&lprpcTable->table[i].dwMask))));
  1355. BufLen = sizeof(wszFriendlyName);
  1356. dwErr = IfutlGetFriendlyNameFromIfIndex( hMibServer,
  1357. lprpcTable->table[i].dwIndex,
  1358. wszFriendlyName,//in bytes. not chars
  1359. BufLen );
  1360. DisplayMessageToConsole(g_hModule, g_hConsole,MSG_MIB_IP_ADDR_ENTRY,
  1361. tszAddr,
  1362. tszMask,
  1363. lprpcTable->table[i].dwBCastAddr,
  1364. lprpcTable->table[i].dwReasmSize,
  1365. wszFriendlyName
  1366. );
  1367. }
  1368. }
  1369. VOID
  1370. PrintIpAddrRow(
  1371. MIB_SERVER_HANDLE hMibServer,
  1372. PMIB_OPAQUE_INFO prpcInfo
  1373. )
  1374. /*++
  1375. Routine Description:
  1376. Prints IP address table row.
  1377. Arguments:
  1378. Return Value:
  1379. --*/
  1380. {
  1381. WCHAR wszFriendlyName[MAX_INTERFACE_NAME_LEN + 1];
  1382. PMIB_IPADDRROW iaeRow = (PMIB_IPADDRROW)(prpcInfo->rgbyData);
  1383. DWORD dwErr = NO_ERROR;
  1384. TCHAR tszAddr[ADDR_LENGTH + 1], tszMask[ADDR_LENGTH + 1];
  1385. DWORD BufLen;
  1386. MakeUnicodeIpAddr(tszAddr,
  1387. inet_ntoa(*((struct in_addr *)(&iaeRow->dwAddr))));
  1388. MakeUnicodeIpAddr(tszMask,
  1389. inet_ntoa(*((struct in_addr *)(&iaeRow->dwMask))));
  1390. BufLen = sizeof(wszFriendlyName);
  1391. dwErr = IfutlGetFriendlyNameFromIfIndex( hMibServer,
  1392. iaeRow->dwIndex,
  1393. wszFriendlyName,//in bytes. not chars
  1394. BufLen );
  1395. DisplayMessageToConsole(g_hModule, g_hConsole,MSG_MIB_IP_ADDR_HDR);
  1396. DisplayMessageToConsole(g_hModule, g_hConsole,MSG_MIB_IP_ADDR_ENTRY,
  1397. tszAddr,
  1398. tszMask,
  1399. iaeRow->dwBCastAddr,
  1400. iaeRow->dwReasmSize,
  1401. wszFriendlyName );
  1402. }
  1403. VOID
  1404. PrintIpNetTable(
  1405. MIB_SERVER_HANDLE hMibServer,
  1406. PMIB_OPAQUE_INFO prpcInfo
  1407. )
  1408. /*++
  1409. Routine Description:
  1410. Prints IP net table information.
  1411. Arguments:
  1412. Return Value:
  1413. --*/
  1414. {
  1415. WCHAR wszFriendlyName[MAX_INTERFACE_NAME_LEN + 1];
  1416. PMIB_IPNETTABLE lprpcTable = (PMIB_IPNETTABLE)(prpcInfo->rgbyData);
  1417. TCHAR tszPhysAddr[DISPLAYLEN_PHYSADDR + 1],
  1418. tszIpAddr[ADDR_LENGTH + 1];
  1419. PTCHAR ptszType;
  1420. DWORD i, dwErr = NO_ERROR;
  1421. DisplayMessageToConsole(g_hModule, g_hConsole,MSG_MIB_IP_NET_HDR);
  1422. if(lprpcTable->dwNumEntries is 0)
  1423. {
  1424. DisplayMessageToConsole(g_hModule, g_hConsole,MSG_IP_NO_ENTRIES);
  1425. return;
  1426. }
  1427. for(i = 0; i < lprpcTable->dwNumEntries; i++)
  1428. {
  1429. DWORD BufLen;
  1430. switch(lprpcTable->table[i].dwType)
  1431. {
  1432. case MIB_IPNET_TYPE_INVALID:
  1433. {
  1434. ptszType = MakeString(g_hModule, STRING_INVALID);
  1435. break;
  1436. }
  1437. case MIB_IPNET_TYPE_DYNAMIC:
  1438. {
  1439. ptszType = MakeString(g_hModule, STRING_DYNAMIC);
  1440. break;
  1441. }
  1442. case MIB_IPNET_TYPE_STATIC:
  1443. {
  1444. ptszType = MakeString(g_hModule, STRING_STATIC);
  1445. break;
  1446. }
  1447. case MIB_IPNET_TYPE_OTHER:
  1448. default:
  1449. {
  1450. ptszType = MakeString(g_hModule, STRING_OTHER);
  1451. break;
  1452. }
  1453. }
  1454. MakeUnicodeIpAddr(tszIpAddr,
  1455. inet_ntoa(*((struct in_addr *)
  1456. (&lprpcTable->table[i].dwAddr))));
  1457. MakeUnicodePhysAddr(tszPhysAddr,
  1458. lprpcTable->table[i].bPhysAddr,
  1459. lprpcTable->table[i].dwPhysAddrLen);
  1460. BufLen = sizeof(wszFriendlyName);
  1461. dwErr = IfutlGetFriendlyNameFromIfIndex( hMibServer,
  1462. lprpcTable->table[i].dwIndex,
  1463. wszFriendlyName,//in bytes. not chars
  1464. BufLen);
  1465. if (dwErr != NO_ERROR) {
  1466. wcscpy(wszFriendlyName, L"?");
  1467. }
  1468. DisplayMessageToConsole(g_hModule, g_hConsole,MSG_MIB_IP_NET_ENTRY,
  1469. wszFriendlyName,
  1470. tszPhysAddr,
  1471. tszIpAddr,
  1472. ptszType);
  1473. FreeString(ptszType);
  1474. }
  1475. }
  1476. VOID
  1477. PrintIpNetRow(
  1478. MIB_SERVER_HANDLE hMibServer,
  1479. PMIB_OPAQUE_INFO prpcInfo
  1480. )
  1481. /*++
  1482. Routine Description:
  1483. Prints IP net row information.
  1484. Arguments:
  1485. Return Value:
  1486. --*/
  1487. {
  1488. WCHAR wszFriendlyName[MAX_INTERFACE_NAME_LEN + 1];
  1489. PMIB_IPNETROW inmeRow = (PMIB_IPNETROW)(prpcInfo->rgbyData);
  1490. TCHAR tszPhysAddr[DISPLAYLEN_PHYSADDR + 1],
  1491. tszIpAddr[ADDR_LENGTH + 1];
  1492. PTCHAR ptszType;
  1493. DWORD dwErr = NO_ERROR;
  1494. DWORD BufLen;
  1495. switch(inmeRow->dwType)
  1496. {
  1497. case MIB_IPNET_TYPE_INVALID:
  1498. {
  1499. ptszType = MakeString(g_hModule, STRING_INVALID);
  1500. break;
  1501. }
  1502. case MIB_IPNET_TYPE_DYNAMIC:
  1503. {
  1504. ptszType = MakeString(g_hModule, STRING_DYNAMIC);
  1505. break;
  1506. }
  1507. case MIB_IPNET_TYPE_STATIC:
  1508. {
  1509. ptszType = MakeString(g_hModule, STRING_STATIC);
  1510. break;
  1511. }
  1512. case MIB_IPNET_TYPE_OTHER:
  1513. default:
  1514. {
  1515. ptszType = MakeString(g_hModule, STRING_OTHER);
  1516. break;
  1517. }
  1518. }
  1519. MakeUnicodeIpAddr(tszIpAddr,
  1520. inet_ntoa(*((struct in_addr *)(&inmeRow->dwAddr))));
  1521. MakeUnicodePhysAddr(tszPhysAddr,inmeRow->bPhysAddr,inmeRow->dwPhysAddrLen);
  1522. BufLen = sizeof(wszFriendlyName);
  1523. dwErr = IfutlGetFriendlyNameFromIfIndex( hMibServer,
  1524. inmeRow->dwIndex,
  1525. wszFriendlyName,
  1526. BufLen);//in bytes. not chars
  1527. DisplayMessageToConsole(g_hModule, g_hConsole,MSG_MIB_IP_NET_HDR);
  1528. DisplayMessageToConsole(g_hModule, g_hConsole,MSG_MIB_IP_NET_ENTRY,
  1529. wszFriendlyName,
  1530. tszPhysAddr,
  1531. tszIpAddr,
  1532. ptszType);
  1533. FreeString(ptszType);
  1534. }