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.

2263 lines
65 KiB

  1. //*****************************************************************************
  2. //
  3. // Name: netstat.c
  4. //
  5. // Description: Source code for netstat.exe.
  6. //
  7. // History:
  8. // 12/29/93 JayPh Created.
  9. // 12/01/94 MuraliK modified to use toupper instead of CharUpper
  10. //
  11. //*****************************************************************************
  12. //*****************************************************************************
  13. //
  14. // Copyright (c) 1993-2000 by Microsoft Corp. All rights reserved.
  15. //
  16. //*****************************************************************************
  17. //
  18. // Include Files
  19. //
  20. #include <stdio.h>
  21. #include <stdlib.h>
  22. #include <string.h>
  23. #include <ctype.h>
  24. #include <time.h>
  25. #include <nt.h>
  26. #include <ntrtl.h>
  27. #include <nturtl.h>
  28. #include <snmp.h>
  29. #include <winsock2.h>
  30. #include <ws2tcpip.h>
  31. #include <icmp6.h>
  32. #include <iphlpstk.h>
  33. #include <winnlsp.h>
  34. #include "common2.h"
  35. #include "tcpinfo.h"
  36. #include "ipinfo.h"
  37. #include "llinfo.h"
  38. #include "tcpcmd.h"
  39. #include "netstmsg.h"
  40. #include "mdebug.h"
  41. //
  42. // Definitions
  43. //
  44. #define PROTO_NONE 0
  45. #define PROTO_TCP 1
  46. #define PROTO_UDP 2
  47. #define PROTO_IP 4
  48. #define PROTO_ICMP 8
  49. #define PROTO_TCP6 0x10
  50. #define PROTO_UDP6 0x20
  51. #define PROTO_IP6 0x40
  52. #define PROTO_ICMP6 0x80
  53. #define MAX_ID_LENGTH 50
  54. #define MAX_RETRY_COUNT 10
  55. //
  56. // Presently FQDNs are of maximum of 255 characters. Be conservative,
  57. // and define the maximum size possible as 260
  58. // MuraliK ( 12/15/94)
  59. //
  60. #define MAX_HOST_NAME_SIZE ( 260)
  61. #define MAX_SERVICE_NAME_SIZE ( 200)
  62. //
  63. // Private ASSERT macro that doesn't depend on NTDLL (so this can run
  64. // under Windows 95) -- KeithMo 01/09/95
  65. //
  66. #if DBG
  67. #ifdef ASSERT
  68. #undef ASSERT
  69. #endif // ASSERT
  70. #define ASSERT(exp) if(!(exp)) MyAssert( #exp, __FILE__, (DWORD)__LINE__ )
  71. void MyAssert( void * exp, void * file, DWORD line )
  72. {
  73. char output[512];
  74. wsprintf( output,
  75. "\n*** Assertion failed: %s\n*** Source file: %s, line %lu\n\n",
  76. exp,
  77. file,
  78. line );
  79. OutputDebugString( output );
  80. DebugBreak();
  81. }
  82. #endif // DBG
  83. //
  84. // Structure Definitions
  85. //
  86. //
  87. // Function Prototypes
  88. //
  89. ulong DoInterface( ulong VerboseFlag );
  90. ulong DoIP( DWORD Type, ulong VerboseFlag );
  91. ulong DoTCP( DWORD Type, ulong VerboseFlag );
  92. ulong DoUDP( DWORD Type, ulong VerboseFlag );
  93. ulong DoICMP( DWORD Type, ulong VerboseFlag );
  94. ulong DoConnections( ulong ProtoFlag,
  95. ulong ProtoVal,
  96. ulong NumFlag,
  97. ulong AllFlag );
  98. ulong DoConnectionsWithOwner( ulong ProtoFlag,
  99. ulong ProtoVal,
  100. ulong NumFlag,
  101. ulong AllFlag );
  102. ulong DoRoutes( void );
  103. void DisplayInterface( IfEntry *pEntry, ulong VerboseFlag, IfEntry *ListHead );
  104. void DisplayIP( DWORD Type, IpEntry *pEntry, ulong VerboseFlag, IpEntry *ListHead );
  105. void DisplayTCP( DWORD Type, TcpEntry *pEntry, ulong VerboseFlag, TcpEntry *ListHead );
  106. void DisplayUDP( DWORD Type, UdpEntry *pEntry, ulong VerboseFlag, UdpEntry *ListHead );
  107. void DisplayICMP( IcmpEntry *pEntry, ulong VerboseFlag, IcmpEntry *ListHead );
  108. void DisplayICMP6( Icmp6Entry *pEntry, ulong VerboseFlag, IcmpEntry *ListHead );
  109. void DisplayTcpConnEntry( TCPConnTableEntry *pTcp, ulong InfoSize, ulong NumFlag );
  110. void DisplayTcp6ConnEntry( TCP6ConnTableEntry *pTcp, ulong NumFlag );
  111. void DisplayUdpConnEntry( UDPEntry *pUdp, ulong InfoSize, ulong NumFlag );
  112. void DisplayUdp6ListenerEntry( UDP6ListenerEntry *pUdp, BOOL WithOwner, ulong NumFlag );
  113. void Usage( void );
  114. //
  115. // Global Variables
  116. //
  117. char *PgmName;
  118. extern long verbose; // in ../common2/snmpinfo.c
  119. //*****************************************************************************
  120. //
  121. // Name: main
  122. //
  123. // Description: Entry point for netstat command.
  124. //
  125. // Parameters: int argc: count of command line tokens.
  126. // char argv[]: array of pointers to command line tokens.
  127. //
  128. // Returns: void.
  129. //
  130. // History:
  131. // 12/29/93 JayPh Created.
  132. //
  133. //*****************************************************************************
  134. void __cdecl main( int argc, char *argv[] )
  135. {
  136. ulong VerboseFlag = FALSE;
  137. ulong AllFlag = FALSE;
  138. ulong EtherFlag = FALSE;
  139. ulong NumFlag = FALSE;
  140. ulong StatFlag = FALSE;
  141. ulong ProtoFlag = FALSE;
  142. ulong ProtoVal = PROTO_TCP | PROTO_UDP | PROTO_IP | PROTO_ICMP |
  143. PROTO_TCP6 | PROTO_UDP6 | PROTO_IP6 | PROTO_ICMP6;
  144. ulong RouteFlag = FALSE;
  145. ulong OwnerFlag = FALSE;
  146. ulong IntervalVal = 0;
  147. ulong LastArgWasProtoFlag = FALSE;
  148. ulong ConnectionsShown = FALSE;
  149. ulong Result;
  150. long i;
  151. char *ptr;
  152. WSADATA WsaData;
  153. DEBUG_PRINT(( __FILE__ " built " __DATE__ " " __TIME__ "\n" ));
  154. verbose = 0; // Default for snmpinfo.c
  155. // Set language code page to system locale.
  156. SetThreadUILanguage(0);
  157. // Convert arguments to Oem strings (whatever that means)
  158. ConvertArgvToOem( argc, argv );
  159. // Save the name of this program for use in messages later.
  160. PgmName = argv[0];
  161. // Initialize the Winsock interface
  162. Result = WSAStartup( 0x0101, &WsaData );
  163. if ( Result == SOCKET_ERROR )
  164. {
  165. PutMsg( STDERR, MSG_WSASTARTUP, PgmName, GetLastError() );
  166. exit( 1 );
  167. }
  168. // Process command line arguments
  169. for ( i = 1; i < argc; i++ )
  170. {
  171. if ( LastArgWasProtoFlag )
  172. {
  173. // Process a protocol argument following the protocol flag
  174. _strupr( argv[i] );
  175. if ( strcmp( argv[i], "TCP" ) == 0 )
  176. {
  177. ProtoVal = PROTO_TCP;
  178. }
  179. else if ( strcmp( argv[i], "TCPV6" ) == 0 )
  180. {
  181. ProtoVal = PROTO_TCP6;
  182. }
  183. else if ( strcmp( argv[i], "UDP" ) == 0 )
  184. {
  185. ProtoVal = PROTO_UDP;
  186. }
  187. else if ( strcmp( argv[i], "UDPV6" ) == 0 )
  188. {
  189. ProtoVal = PROTO_UDP6;
  190. }
  191. else if ( strcmp( argv[i], "IP" ) == 0 )
  192. {
  193. ProtoVal = PROTO_IP;
  194. }
  195. else if ( strcmp( argv[i], "IPV6" ) == 0 )
  196. {
  197. ProtoVal = PROTO_IP6;
  198. }
  199. else if ( strcmp( argv[i], "ICMP" ) == 0 )
  200. {
  201. ProtoVal = PROTO_ICMP;
  202. }
  203. else if ( strcmp( argv[i], "ICMPV6" ) == 0 )
  204. {
  205. ProtoVal = PROTO_ICMP6;
  206. }
  207. else
  208. {
  209. Usage();
  210. }
  211. LastArgWasProtoFlag = FALSE;
  212. continue;
  213. }
  214. if ( ( argv[i][0] == '-' ) || ( argv[i][0] == '/' ) )
  215. {
  216. // Process flag arguments
  217. ptr = &argv[i][1];
  218. while ( *ptr )
  219. {
  220. if ( toupper( *ptr ) == 'A' )
  221. {
  222. AllFlag = TRUE;
  223. }
  224. else if ( toupper( *ptr ) == 'E' )
  225. {
  226. EtherFlag = TRUE;
  227. ProtoVal = PROTO_TCP | PROTO_UDP | PROTO_ICMP | PROTO_IP |
  228. PROTO_TCP6 | PROTO_UDP6 | PROTO_ICMP6 | PROTO_IP6;
  229. }
  230. else if ( toupper( *ptr ) == 'N' )
  231. {
  232. NumFlag = TRUE;
  233. }
  234. else if ( toupper( *ptr ) == 'O' )
  235. {
  236. OwnerFlag = TRUE;
  237. }
  238. else if ( toupper( *ptr ) == 'S' )
  239. {
  240. StatFlag = TRUE;
  241. ProtoVal = PROTO_TCP | PROTO_UDP | PROTO_IP | PROTO_ICMP |
  242. PROTO_TCP6 | PROTO_UDP6 | PROTO_IP6 | PROTO_ICMP6;
  243. }
  244. else if ( toupper( *ptr ) == 'P' )
  245. {
  246. ProtoFlag = TRUE;
  247. LastArgWasProtoFlag = TRUE;
  248. }
  249. else if ( toupper( *ptr ) == 'R' )
  250. {
  251. RouteFlag = TRUE;
  252. }
  253. else if ( toupper( *ptr ) == 'V' )
  254. {
  255. VerboseFlag = TRUE;
  256. #ifdef DBG
  257. verbose++;
  258. #endif
  259. }
  260. else
  261. {
  262. Usage();
  263. }
  264. ptr++;
  265. }
  266. }
  267. else if ( IntervalVal == 0 )
  268. {
  269. // This must be the interval parameter
  270. Result = sscanf( argv[i], "%d", &IntervalVal );
  271. if ( Result != 1 )
  272. {
  273. Usage();
  274. }
  275. }
  276. else
  277. {
  278. Usage();
  279. }
  280. }
  281. // Initialize the SNMP interface.
  282. Result = InitSnmp();
  283. if ( Result != NO_ERROR )
  284. {
  285. PutMsg( STDERR, MSG_SNMP_INIT_FAILED, Result );
  286. exit( 1 );
  287. }
  288. // This loop provides the 'repeat every <interval> seconds' functionality.
  289. // We break out of the loop after one pass if the interval was not
  290. // specified.
  291. for (;;)
  292. {
  293. // If interface statistics requested, give them
  294. if ( EtherFlag )
  295. {
  296. // Show ethernet statistics
  297. DoInterface( VerboseFlag );
  298. }
  299. // If a specific protocol is requested, provide info for only that
  300. // protocol. If no protocol specified, provide info for all protocols.
  301. // ProtoVal is initialized to all protocols.
  302. if ( StatFlag )
  303. {
  304. // Show protocol statistics
  305. if ( ProtoVal & PROTO_IP )
  306. {
  307. DoIP( TYPE_IP, VerboseFlag );
  308. }
  309. if ( ProtoVal & PROTO_IP6 )
  310. {
  311. DoIP( TYPE_IP6, VerboseFlag );
  312. }
  313. if ( ProtoVal & PROTO_ICMP )
  314. {
  315. DoICMP( TYPE_ICMP, VerboseFlag );
  316. }
  317. if ( ProtoVal & PROTO_ICMP6 )
  318. {
  319. DoICMP( TYPE_ICMP6, VerboseFlag );
  320. }
  321. if ( ProtoVal & PROTO_TCP )
  322. {
  323. DoTCP( TYPE_TCP, VerboseFlag );
  324. }
  325. if ( ProtoVal & PROTO_TCP6 )
  326. {
  327. DoTCP( TYPE_TCP6, VerboseFlag );
  328. }
  329. if ( ProtoVal & PROTO_UDP )
  330. {
  331. DoUDP( TYPE_UDP, VerboseFlag );
  332. }
  333. if ( ProtoVal & PROTO_UDP6 )
  334. {
  335. DoUDP( TYPE_UDP6, VerboseFlag );
  336. }
  337. }
  338. // If a protocol is specified and that protocol is either TCP or UDP,
  339. // OR none of (route, statistics, interface ) flags given (this is the
  340. // default, no flags, case )
  341. if ( ( ProtoFlag &&
  342. ( ( ProtoVal & PROTO_TCP ) || ( ProtoVal & PROTO_UDP ) ||
  343. ( ProtoVal & PROTO_TCP6 ) || ( ProtoVal & PROTO_UDP6 ) ) ) ||
  344. ( !EtherFlag && !StatFlag && !RouteFlag ) )
  345. {
  346. // Show active connections
  347. if (OwnerFlag)
  348. {
  349. DoConnectionsWithOwner( ProtoFlag, ProtoVal, NumFlag, AllFlag );
  350. }
  351. else
  352. {
  353. DoConnections( ProtoFlag, ProtoVal, NumFlag, AllFlag );
  354. }
  355. ConnectionsShown = TRUE;
  356. }
  357. // Provide route information if requested
  358. if ( RouteFlag )
  359. {
  360. // Show connections and the route table
  361. DoRoutes();
  362. }
  363. // If interval was not supplied on command line then we are done.
  364. // Otherwise wait for 'interval' seconds and do it again.
  365. if ( IntervalVal == 0 )
  366. {
  367. break;
  368. }
  369. else
  370. {
  371. DEBUG_PRINT(("Sleeping %d sec\n", IntervalVal ));
  372. Sleep( IntervalVal * 1000 );
  373. }
  374. }
  375. }
  376. //*****************************************************************************
  377. //
  378. // Name: DoInterface
  379. //
  380. // Description: Display ethernet statistics.
  381. //
  382. // Parameters: ulong VerboseFlag: indicates whether settings data should be
  383. // displayed.
  384. //
  385. // Returns: ulong: NO_ERROR or some error code.
  386. //
  387. // History:
  388. // 01/21/93 JayPh Created.
  389. //
  390. //*****************************************************************************
  391. ulong DoInterface( ulong VerboseFlag )
  392. {
  393. IfEntry *ListHead;
  394. IfEntry *pIfList;
  395. IfEntry SumOfEntries;
  396. ulong Result;
  397. // Get the statistics
  398. ListHead = (IfEntry *)GetTable( TYPE_IF, &Result );
  399. if ( ListHead == NULL )
  400. {
  401. return ( Result );
  402. }
  403. // Clear the summation structure
  404. ZeroMemory( &SumOfEntries, sizeof( IfEntry ) );
  405. // Traverse the list of interfaces, summing the different fields
  406. pIfList = CONTAINING_RECORD( ListHead->ListEntry.Flink,
  407. IfEntry,
  408. ListEntry );
  409. while (pIfList != ListHead)
  410. {
  411. SumOfEntries.Info.if_inoctets += pIfList->Info.if_inoctets;
  412. SumOfEntries.Info.if_inucastpkts += pIfList->Info.if_inucastpkts;
  413. SumOfEntries.Info.if_innucastpkts += pIfList->Info.if_innucastpkts;
  414. SumOfEntries.Info.if_indiscards += pIfList->Info.if_indiscards;
  415. SumOfEntries.Info.if_inerrors += pIfList->Info.if_inerrors;
  416. SumOfEntries.Info.if_inunknownprotos +=
  417. pIfList->Info.if_inunknownprotos;
  418. SumOfEntries.Info.if_outoctets += pIfList->Info.if_outoctets;
  419. SumOfEntries.Info.if_outucastpkts += pIfList->Info.if_outucastpkts;
  420. SumOfEntries.Info.if_outnucastpkts += pIfList->Info.if_outnucastpkts;
  421. SumOfEntries.Info.if_outdiscards += pIfList->Info.if_outdiscards;
  422. SumOfEntries.Info.if_outerrors += pIfList->Info.if_outerrors;
  423. // Get pointer to next entry in list
  424. pIfList = CONTAINING_RECORD( pIfList->ListEntry.Flink,
  425. IfEntry,
  426. ListEntry );
  427. }
  428. DisplayInterface( &SumOfEntries, VerboseFlag, ListHead );
  429. // All done with list, free it.
  430. FreeTable( (GenericTable *)ListHead );
  431. return ( NO_ERROR );
  432. }
  433. //*****************************************************************************
  434. //
  435. // Name: DoIP
  436. //
  437. // Description: Display IP statistics.
  438. //
  439. // Parameters: ulong VerboseFlag: indicates whether settings data should be
  440. // displayed.
  441. //
  442. // Returns: ulong: NO_ERROR or some error code.
  443. //
  444. // History:
  445. // 01/21/93 JayPh Created.
  446. //
  447. //*****************************************************************************
  448. ulong DoIP( DWORD Type, ulong VerboseFlag )
  449. {
  450. IpEntry *ListHead;
  451. IpEntry *pIpList;
  452. ulong Result;
  453. // Get the statistics
  454. ListHead = (IpEntry *)GetTable( Type, &Result );
  455. if ( ListHead == NULL )
  456. {
  457. return ( Result );
  458. }
  459. pIpList = CONTAINING_RECORD( ListHead->ListEntry.Flink,
  460. IpEntry,
  461. ListEntry );
  462. DisplayIP( Type, pIpList, VerboseFlag, ListHead );
  463. // All done with list, free it.
  464. FreeTable( (GenericTable *)ListHead );
  465. return ( NO_ERROR );
  466. }
  467. //*****************************************************************************
  468. //
  469. // Name: DoTCP
  470. //
  471. // Description: Display TCP statistics.
  472. //
  473. // Parameters: ulong VerboseFlag: indicates whether settings data should be
  474. // displayed.
  475. //
  476. // Returns: ulong: NO_ERROR or some error code.
  477. //
  478. // History:
  479. // 01/21/93 JayPh Created.
  480. //
  481. //*****************************************************************************
  482. ulong DoTCP( DWORD Type, ulong VerboseFlag )
  483. {
  484. TcpEntry *ListHead;
  485. TcpEntry *pTcpList;
  486. ulong Result;
  487. // Get the statistics
  488. ListHead = (TcpEntry *)GetTable( Type, &Result );
  489. if ( ListHead == NULL )
  490. {
  491. return ( Result );
  492. }
  493. pTcpList = CONTAINING_RECORD( ListHead->ListEntry.Flink,
  494. TcpEntry,
  495. ListEntry );
  496. DisplayTCP( Type, pTcpList, VerboseFlag, ListHead );
  497. // All done with list, free it.
  498. FreeTable( (GenericTable *)ListHead );
  499. return ( NO_ERROR );
  500. }
  501. //*****************************************************************************
  502. //
  503. // Name: DoUDP
  504. //
  505. // Description: Display UDP statistics.
  506. //
  507. // Parameters: ulong VerboseFlag: indicates whether settings data should be
  508. // displayed.
  509. //
  510. // Returns: ulong: NO_ERROR or some error code.
  511. //
  512. // History:
  513. // 01/21/93 JayPh Created.
  514. //
  515. //*****************************************************************************
  516. ulong DoUDP( DWORD Type, ulong VerboseFlag )
  517. {
  518. UdpEntry *ListHead;
  519. UdpEntry *pUdpList;
  520. ulong Result;
  521. // Get the statistics
  522. ListHead = (UdpEntry *)GetTable( Type, &Result );
  523. if ( ListHead == NULL )
  524. {
  525. return ( Result );
  526. }
  527. pUdpList = CONTAINING_RECORD( ListHead->ListEntry.Flink,
  528. UdpEntry,
  529. ListEntry );
  530. DisplayUDP( Type, pUdpList, VerboseFlag, ListHead );
  531. // All done with table, free it.
  532. FreeTable( (GenericTable *)ListHead );
  533. return ( NO_ERROR );
  534. }
  535. //*****************************************************************************
  536. //
  537. // Name: DoICMP
  538. //
  539. // Description: Display ICMP statistics.
  540. //
  541. // Parameters: ulong VerboseFlag: indicates whether settings data should be
  542. // displayed.
  543. //
  544. // Returns: ulong: NO_ERROR or some error code.
  545. //
  546. // History:
  547. // 01/21/93 JayPh Created.
  548. //
  549. //*****************************************************************************
  550. ulong DoICMP( DWORD Type, ulong VerboseFlag )
  551. {
  552. IcmpEntry *ListHead;
  553. IcmpEntry *pIcmpList;
  554. ulong Result;
  555. // Get the statistics
  556. ListHead = (IcmpEntry *)GetTable( Type, &Result );
  557. if ( ListHead == NULL )
  558. {
  559. return ( Result );
  560. }
  561. pIcmpList = CONTAINING_RECORD( ListHead->ListEntry.Flink,
  562. IcmpEntry,
  563. ListEntry );
  564. if (Type == TYPE_ICMP) {
  565. DisplayICMP( pIcmpList, VerboseFlag, ListHead );
  566. } else {
  567. DisplayICMP6((Icmp6Entry *)pIcmpList, VerboseFlag, ListHead );
  568. }
  569. // All done with list, free it.
  570. FreeTable( (GenericTable *)ListHead );
  571. return ( NO_ERROR );
  572. }
  573. //*****************************************************************************
  574. //
  575. // Name: DoConnections
  576. //
  577. // Description: List current connections.
  578. //
  579. // Parameters: BOOL ProtoFlag: TRUE if a protocol was specified.
  580. // ulong ProtoVal: which protocol(s) were specified.
  581. //
  582. // Returns: Win32 error code.
  583. //
  584. // History:
  585. // 01/04/93 JayPh Created.
  586. //
  587. //*****************************************************************************
  588. ulong DoConnections( ulong ProtoFlag,
  589. ulong ProtoVal,
  590. ulong NumFlag,
  591. ulong AllFlag )
  592. {
  593. ulong Result = NO_ERROR;
  594. PutMsg( STDOUT, MSG_CONN_HDR );
  595. if ( !ProtoFlag || ( ProtoFlag && ( ProtoVal == PROTO_TCP ) ) )
  596. {
  597. TcpConnEntry *pTcpHead, *pTcp;
  598. // Get TCP connection table
  599. pTcpHead = (TcpConnEntry *)GetTable( TYPE_TCPCONN, &Result );
  600. if ( pTcpHead == NULL )
  601. {
  602. return ( Result );
  603. }
  604. // Get pointer to first entry in list
  605. pTcp = CONTAINING_RECORD( pTcpHead->ListEntry.Flink,
  606. TcpConnEntry,
  607. ListEntry );
  608. while (pTcp != pTcpHead)
  609. {
  610. if ( ( pTcp->Info.tct_state != TCP_CONN_LISTEN ) ||
  611. (( pTcp->Info.tct_state == TCP_CONN_LISTEN ) && AllFlag) )
  612. {
  613. // Display the Tcp connection info
  614. DisplayTcpConnEntry( &pTcp->Info, sizeof(TCPConnTableEntry),
  615. NumFlag );
  616. }
  617. // Get the next entry in the table
  618. pTcp = CONTAINING_RECORD( pTcp->ListEntry.Flink,
  619. TcpConnEntry,
  620. ListEntry );
  621. }
  622. FreeTable( (GenericTable *)pTcpHead );
  623. }
  624. if ( !ProtoFlag || ( ProtoFlag && ( ProtoVal == PROTO_TCP6 ) ) )
  625. {
  626. Tcp6ConnEntry *pTcpHead, *pTcp;
  627. // Get TCP connection table
  628. pTcpHead = (Tcp6ConnEntry *)GetTable( TYPE_TCP6CONN, &Result );
  629. if ( pTcpHead == NULL )
  630. {
  631. return ( Result );
  632. }
  633. // Get pointer to first entry in list
  634. pTcp = CONTAINING_RECORD( pTcpHead->ListEntry.Flink,
  635. Tcp6ConnEntry,
  636. ListEntry );
  637. while (pTcp != pTcpHead)
  638. {
  639. if ( ( pTcp->Info.tct_state != TCP_CONN_LISTEN ) ||
  640. (( pTcp->Info.tct_state == TCP_CONN_LISTEN ) && AllFlag) )
  641. {
  642. // Display the Tcp connection info
  643. DisplayTcp6ConnEntry( &pTcp->Info, NumFlag );
  644. }
  645. // Get the next entry in the table
  646. pTcp = CONTAINING_RECORD( pTcp->ListEntry.Flink,
  647. Tcp6ConnEntry,
  648. ListEntry );
  649. }
  650. FreeTable( (GenericTable *)pTcpHead );
  651. }
  652. if ( !ProtoFlag || ( ProtoFlag && ( ProtoVal == PROTO_UDP ) ) )
  653. {
  654. UdpConnEntry *pUdpHead, *pUdp;
  655. // Get UDP connection table
  656. pUdpHead = (UdpConnEntry *)GetTable( TYPE_UDPCONN, &Result );
  657. if ( pUdpHead == NULL )
  658. {
  659. return ( Result );
  660. }
  661. // Get pointer to first entry in list
  662. pUdp = CONTAINING_RECORD( pUdpHead->ListEntry.Flink,
  663. UdpConnEntry,
  664. ListEntry );
  665. while (pUdp != pUdpHead)
  666. {
  667. // Display the Udp connection info
  668. if (AllFlag)
  669. {
  670. DisplayUdpConnEntry( &pUdp->Info, sizeof(UDPEntry), NumFlag );
  671. }
  672. // Get the next entry in the table
  673. pUdp = CONTAINING_RECORD( pUdp->ListEntry.Flink,
  674. UdpConnEntry,
  675. ListEntry );
  676. }
  677. FreeTable( (GenericTable *)pUdpHead );
  678. }
  679. if ( !ProtoFlag || ( ProtoFlag && ( ProtoVal == PROTO_UDP6 ) ) )
  680. {
  681. Udp6ListenerEntry *pUdpHead, *pUdp;
  682. // Get UDP listener table
  683. pUdpHead = (Udp6ListenerEntry *)GetTable( TYPE_UDP6LISTENER, &Result );
  684. if ( pUdpHead == NULL )
  685. {
  686. return ( Result );
  687. }
  688. // Get pointer to first entry in list
  689. pUdp = CONTAINING_RECORD( pUdpHead->ListEntry.Flink,
  690. Udp6ListenerEntry,
  691. ListEntry );
  692. while (pUdp != pUdpHead)
  693. {
  694. // Display the Udp connection info
  695. if (AllFlag)
  696. {
  697. DisplayUdp6ListenerEntry( &pUdp->Info, FALSE, NumFlag );
  698. }
  699. // Get the next entry in the table
  700. pUdp = CONTAINING_RECORD( pUdp->ListEntry.Flink,
  701. Udp6ListenerEntry,
  702. ListEntry );
  703. }
  704. FreeTable( (GenericTable *)pUdpHead );
  705. }
  706. return( Result );
  707. }
  708. //*****************************************************************************
  709. //
  710. // Name: DoConnectionsWithOwner
  711. //
  712. // Description: List current connections and the process id associated with
  713. // each.
  714. //
  715. // Parameters: same as for DoConnections.
  716. //
  717. // Returns: Win32 error code.
  718. //
  719. // History:
  720. // 02/11/00 ShaunCo Created.
  721. //
  722. //*****************************************************************************
  723. ulong DoConnectionsWithOwner( ulong ProtoFlag,
  724. ulong ProtoVal,
  725. ulong NumFlag,
  726. ulong AllFlag )
  727. {
  728. ulong Result = NO_ERROR;
  729. HANDLE hHeap = GetProcessHeap();
  730. ulong i;
  731. PutMsg( STDOUT, MSG_CONN_HDR_EX );
  732. if ( !ProtoFlag || ( ProtoFlag && ( ProtoVal == PROTO_TCP ) ) )
  733. {
  734. TCP_EX_TABLE *pTcpTable;
  735. TCPConnTableEntryEx *pTcp;
  736. // Get TCP connection table with onwer PID information
  737. Result = AllocateAndGetTcpExTableFromStack( &pTcpTable, TRUE,
  738. hHeap, 0, AF_INET );
  739. if ( NO_ERROR == Result )
  740. {
  741. for ( i = 0; i < pTcpTable->dwNumEntries; i++ )
  742. {
  743. pTcp = &pTcpTable->table[i];
  744. if ( ( pTcp->tcte_basic.tct_state != TCP_CONN_LISTEN ) ||
  745. (( pTcp->tcte_basic.tct_state == TCP_CONN_LISTEN ) && AllFlag) )
  746. {
  747. // DisplayTcpConnEntry needs the port info in host byte
  748. // order.
  749. pTcp->tcte_basic.tct_localport = (ulong)ntohs(
  750. (ushort)pTcp->tcte_basic.tct_localport);
  751. pTcp->tcte_basic.tct_remoteport = (ulong)ntohs(
  752. (ushort)pTcp->tcte_basic.tct_remoteport);
  753. // Display the Tcp connection info
  754. DisplayTcpConnEntry( (TCPConnTableEntry*)pTcp,
  755. sizeof(TCPConnTableEntryEx),
  756. NumFlag );
  757. }
  758. }
  759. HeapFree(hHeap, 0, pTcpTable);
  760. }
  761. }
  762. if ( !ProtoFlag || ( ProtoFlag && ( ProtoVal == PROTO_TCP6 ) ) )
  763. {
  764. TCP6_EX_TABLE *pTcpTable;
  765. TCP6ConnTableEntry *pTcp;
  766. // Get TCP connection table with onwer PID information
  767. Result = AllocateAndGetTcpExTableFromStack( &pTcpTable, TRUE,
  768. hHeap, 0, AF_INET6 );
  769. if ( NO_ERROR == Result )
  770. {
  771. for ( i = 0; i < pTcpTable->dwNumEntries; i++ )
  772. {
  773. pTcp = &pTcpTable->table[i];
  774. if ( ( pTcp->tct_state != TCP_CONN_LISTEN ) ||
  775. (( pTcp->tct_state == TCP_CONN_LISTEN ) && AllFlag) )
  776. {
  777. // DisplayTcpConnEntry needs the port info in host byte
  778. // order.
  779. pTcp->tct_localport = ntohs(
  780. (ushort)pTcp->tct_localport);
  781. pTcp->tct_remoteport = ntohs(
  782. (ushort)pTcp->tct_remoteport);
  783. // Display the Tcp connection info
  784. DisplayTcp6ConnEntry(pTcp, NumFlag);
  785. }
  786. }
  787. HeapFree(hHeap, 0, pTcpTable);
  788. }
  789. }
  790. if ( !ProtoFlag || ( ProtoFlag && ( ProtoVal == PROTO_UDP ) ) )
  791. {
  792. UDP_EX_TABLE *pUdpTable;
  793. UDPEntryEx *pUdp;
  794. // Get UDP connection table with owner PID information
  795. Result = AllocateAndGetUdpExTableFromStack ( &pUdpTable, TRUE,
  796. hHeap, 0, AF_INET );
  797. if (NO_ERROR == Result)
  798. {
  799. for ( i = 0; i < pUdpTable->dwNumEntries; i++ )
  800. {
  801. pUdp = &pUdpTable->table[i];
  802. if (AllFlag)
  803. {
  804. // DisplayUdpConnEntry needs the port info in host byte
  805. // order.
  806. pUdp->uee_basic.ue_localport = (ulong)ntohs(
  807. (ushort)pUdp->uee_basic.ue_localport);
  808. DisplayUdpConnEntry( (UDPEntry*)pUdp,
  809. sizeof(UDPEntryEx),
  810. NumFlag );
  811. }
  812. }
  813. HeapFree(hHeap, 0, pUdpTable);
  814. }
  815. }
  816. if ( !ProtoFlag || ( ProtoFlag && ( ProtoVal == PROTO_UDP6 ) ) )
  817. {
  818. UDP6_LISTENER_TABLE *pUdpTable;
  819. UDP6ListenerEntry *pUdp;
  820. // Get UDP connection table with owner PID information
  821. Result = AllocateAndGetUdpExTableFromStack ( &pUdpTable, TRUE,
  822. hHeap, 0, AF_INET6 );
  823. if (NO_ERROR == Result)
  824. {
  825. for ( i = 0; i < pUdpTable->dwNumEntries; i++ )
  826. {
  827. pUdp = &pUdpTable->table[i];
  828. if (AllFlag)
  829. {
  830. // DisplayUdp6ListenerEntry needs the port info in host byte
  831. // order.
  832. pUdp->ule_localport = (ulong)ntohs(
  833. (ushort)pUdp->ule_localport);
  834. DisplayUdp6ListenerEntry(pUdp,
  835. TRUE,
  836. NumFlag);
  837. }
  838. }
  839. HeapFree(hHeap, 0, pUdpTable);
  840. }
  841. }
  842. return( Result );
  843. }
  844. //*****************************************************************************
  845. //
  846. // Name: DoRoutes
  847. //
  848. // Description: Display the route table. Uses route.exe
  849. // to do the dirty work.
  850. //
  851. // Parameters: void.
  852. //
  853. // Returns: ulong: NO_ERROR or some error code.
  854. //
  855. // History:
  856. // 01/27/94 JayPh Created.
  857. //
  858. //*****************************************************************************
  859. ulong DoRoutes( void )
  860. {
  861. ulong Result;
  862. //
  863. // Space for 1 quote, a path, a 17-char command string, and a terminating
  864. // NULL.
  865. //
  866. char Buffer[1 + MAX_PATH + 17 + 1];
  867. //
  868. // Wrap full path name in quotes, since there may be spaces in the
  869. // directory path.
  870. //
  871. Buffer[0] = '"';
  872. if (GetSystemDirectory(Buffer+1, MAX_PATH+1) == 0) {
  873. return GetLastError();
  874. }
  875. strcat(Buffer, "\\route.exe\" print");
  876. Result = system(Buffer);
  877. return ( Result );
  878. }
  879. //*****************************************************************************
  880. //
  881. // Name: DisplayInterface
  882. //
  883. // Description: Display interface statistics.
  884. //
  885. // Parameters: IfEntry *pEntry: pointer to summary data entry.
  886. // ulong VerboseFlag: boolean indicating desire for verbosity.
  887. // IfEntry *ListHead: pointer to list of entries. Used if
  888. // verbosity desired.
  889. //
  890. // Returns: void.
  891. //
  892. // History:
  893. // 01/21/94 JayPh Created.
  894. //
  895. //*****************************************************************************
  896. void DisplayInterface( IfEntry *pEntry, ulong VerboseFlag, IfEntry *ListHead )
  897. {
  898. IfEntry *pIfList;
  899. char PhysAddrStr[32];
  900. PutMsg( STDOUT, MSG_IF_HDR );
  901. PutMsg( STDOUT,
  902. MSG_IF_OCTETS,
  903. pEntry->Info.if_inoctets,
  904. pEntry->Info.if_outoctets );
  905. PutMsg( STDOUT,
  906. MSG_IF_UCASTPKTS,
  907. pEntry->Info.if_inucastpkts,
  908. pEntry->Info.if_outucastpkts );
  909. PutMsg( STDOUT,
  910. MSG_IF_NUCASTPKTS,
  911. pEntry->Info.if_innucastpkts,
  912. pEntry->Info.if_outnucastpkts );
  913. PutMsg( STDOUT,
  914. MSG_IF_DISCARDS,
  915. pEntry->Info.if_indiscards,
  916. pEntry->Info.if_outdiscards );
  917. PutMsg( STDOUT,
  918. MSG_IF_ERRORS,
  919. pEntry->Info.if_inerrors,
  920. pEntry->Info.if_outerrors );
  921. PutMsg( STDOUT,
  922. MSG_IF_UNKNOWNPROTOS,
  923. pEntry->Info.if_inunknownprotos );
  924. if ( VerboseFlag )
  925. {
  926. // Also display configuration info
  927. // Traverse the list of interfaces, displaying config info
  928. pIfList = CONTAINING_RECORD( ListHead->ListEntry.Flink,
  929. IfEntry,
  930. ListEntry );
  931. while ( pIfList != ListHead )
  932. {
  933. PutMsg( STDOUT,
  934. MSG_IF_INDEX,
  935. pIfList->Info.if_index );
  936. PutMsg( STDOUT,
  937. MSG_IF_DESCR,
  938. pIfList->Info.if_descr );
  939. PutMsg( STDOUT,
  940. MSG_IF_TYPE,
  941. pIfList->Info.if_type );
  942. PutMsg( STDOUT,
  943. MSG_IF_MTU,
  944. pIfList->Info.if_mtu );
  945. PutMsg( STDOUT,
  946. MSG_IF_SPEED,
  947. pIfList->Info.if_speed );
  948. sprintf( PhysAddrStr,
  949. "%02x-%02X-%02X-%02X-%02X-%02X",
  950. pIfList->Info.if_physaddr[0],
  951. pIfList->Info.if_physaddr[1],
  952. pIfList->Info.if_physaddr[2],
  953. pIfList->Info.if_physaddr[3],
  954. pIfList->Info.if_physaddr[4],
  955. pIfList->Info.if_physaddr[5] );
  956. PutMsg( STDOUT,
  957. MSG_IF_PHYSADDR,
  958. PhysAddrStr );
  959. PutMsg( STDOUT,
  960. MSG_IF_ADMINSTATUS,
  961. pIfList->Info.if_adminstatus );
  962. PutMsg( STDOUT,
  963. MSG_IF_OPERSTATUS,
  964. pIfList->Info.if_operstatus );
  965. PutMsg( STDOUT,
  966. MSG_IF_LASTCHANGE,
  967. pIfList->Info.if_lastchange );
  968. PutMsg( STDOUT,
  969. MSG_IF_OUTQLEN,
  970. pIfList->Info.if_outqlen );
  971. // Get pointer to next entry in list
  972. pIfList = CONTAINING_RECORD( pIfList->ListEntry.Flink,
  973. IfEntry,
  974. ListEntry );
  975. }
  976. }
  977. }
  978. //*****************************************************************************
  979. //
  980. // Name: DisplayIP
  981. //
  982. // Description: Display IP statistics.
  983. //
  984. // Parameters: IpEntry *pEntry: pointer to summary data entry.
  985. // ulong VerboseFlag: boolean indicating desire for verbosity.
  986. // IpEntry *ListHead: pointer to list of entries. Used if
  987. // verbosity desired.
  988. //
  989. // Returns: void.
  990. //
  991. // History:
  992. // 01/21/94 JayPh Created.
  993. //
  994. //*****************************************************************************
  995. void DisplayIP( DWORD Type, IpEntry *pEntry, ulong VerboseFlag, IpEntry *ListHead )
  996. {
  997. uchar *TypeStr = LoadMsg( (Type==TYPE_IP)? MSG_IPV4 : MSG_IPV6 );
  998. UNREFERENCED_PARAMETER(ListHead);
  999. if (TypeStr) {
  1000. PutMsg( STDOUT, MSG_IP_HDR, TypeStr );
  1001. LocalFree(TypeStr);
  1002. }
  1003. PutMsg( STDOUT,
  1004. MSG_IP_INRECEIVES,
  1005. pEntry->Info.ipsi_inreceives );
  1006. PutMsg( STDOUT,
  1007. MSG_IP_INHDRERRORS,
  1008. pEntry->Info.ipsi_inhdrerrors );
  1009. PutMsg( STDOUT,
  1010. MSG_IP_INADDRERRORS,
  1011. pEntry->Info.ipsi_inaddrerrors );
  1012. PutMsg( STDOUT,
  1013. MSG_IP_FORWDATAGRAMS,
  1014. pEntry->Info.ipsi_forwdatagrams );
  1015. PutMsg( STDOUT,
  1016. MSG_IP_INUNKNOWNPROTOS,
  1017. pEntry->Info.ipsi_inunknownprotos );
  1018. PutMsg( STDOUT,
  1019. MSG_IP_INDISCARDS,
  1020. pEntry->Info.ipsi_indiscards );
  1021. PutMsg( STDOUT,
  1022. MSG_IP_INDELIVERS,
  1023. pEntry->Info.ipsi_indelivers );
  1024. PutMsg( STDOUT,
  1025. MSG_IP_OUTREQUESTS,
  1026. pEntry->Info.ipsi_outrequests );
  1027. PutMsg( STDOUT,
  1028. MSG_IP_ROUTINGDISCARDS,
  1029. pEntry->Info.ipsi_routingdiscards );
  1030. PutMsg( STDOUT,
  1031. MSG_IP_OUTDISCARDS,
  1032. pEntry->Info.ipsi_outdiscards );
  1033. PutMsg( STDOUT,
  1034. MSG_IP_OUTNOROUTES,
  1035. pEntry->Info.ipsi_outnoroutes );
  1036. PutMsg( STDOUT,
  1037. MSG_IP_REASMREQDS,
  1038. pEntry->Info.ipsi_reasmreqds );
  1039. PutMsg( STDOUT,
  1040. MSG_IP_REASMOKS,
  1041. pEntry->Info.ipsi_reasmoks );
  1042. PutMsg( STDOUT,
  1043. MSG_IP_REASMFAILS,
  1044. pEntry->Info.ipsi_reasmfails );
  1045. PutMsg( STDOUT,
  1046. MSG_IP_FRAGOKS,
  1047. pEntry->Info.ipsi_fragoks );
  1048. PutMsg( STDOUT,
  1049. MSG_IP_FRAGFAILS,
  1050. pEntry->Info.ipsi_fragfails );
  1051. PutMsg( STDOUT,
  1052. MSG_IP_FRAGCREATES,
  1053. pEntry->Info.ipsi_fragcreates );
  1054. if ( VerboseFlag )
  1055. {
  1056. PutMsg( STDOUT,
  1057. MSG_IP_FORWARDING,
  1058. pEntry->Info.ipsi_forwarding );
  1059. PutMsg( STDOUT,
  1060. MSG_IP_DEFAULTTTL,
  1061. pEntry->Info.ipsi_defaultttl );
  1062. PutMsg( STDOUT,
  1063. MSG_IP_REASMTIMEOUT,
  1064. pEntry->Info.ipsi_reasmtimeout );
  1065. }
  1066. }
  1067. //*****************************************************************************
  1068. //
  1069. // Name: DisplayTCP
  1070. //
  1071. // Description: Display TCP statistics.
  1072. //
  1073. // Parameters: TcpEntry *pEntry: pointer to data entry.
  1074. // ulong VerboseFlag: boolean indicating desire for verbosity.
  1075. // TcpEntry *ListHead: pointer to list of entries. Used if
  1076. // verbosity desired.
  1077. //
  1078. // Returns: void.
  1079. //
  1080. // History:
  1081. // 01/26/94 JayPh Created.
  1082. //
  1083. //*****************************************************************************
  1084. void DisplayTCP( DWORD Type, TcpEntry *pEntry, ulong VerboseFlag, TcpEntry *ListHead )
  1085. {
  1086. uchar *TypeStr = LoadMsg( (Type==TYPE_TCP)? MSG_IPV4 : MSG_IPV6 );
  1087. UNREFERENCED_PARAMETER(ListHead);
  1088. if (TypeStr) {
  1089. PutMsg( STDOUT, MSG_TCP_HDR, TypeStr );
  1090. LocalFree(TypeStr);
  1091. }
  1092. PutMsg( STDOUT,
  1093. MSG_TCP_ACTIVEOPENS,
  1094. pEntry->Info.ts_activeopens );
  1095. PutMsg( STDOUT,
  1096. MSG_TCP_PASSIVEOPENS,
  1097. pEntry->Info.ts_passiveopens );
  1098. PutMsg( STDOUT,
  1099. MSG_TCP_ATTEMPTFAILS,
  1100. pEntry->Info.ts_attemptfails );
  1101. PutMsg( STDOUT,
  1102. MSG_TCP_ESTABRESETS,
  1103. pEntry->Info.ts_estabresets );
  1104. PutMsg( STDOUT,
  1105. MSG_TCP_CURRESTAB,
  1106. pEntry->Info.ts_currestab );
  1107. PutMsg( STDOUT,
  1108. MSG_TCP_INSEGS,
  1109. pEntry->Info.ts_insegs );
  1110. PutMsg( STDOUT,
  1111. MSG_TCP_OUTSEGS,
  1112. pEntry->Info.ts_outsegs );
  1113. PutMsg( STDOUT,
  1114. MSG_TCP_RETRANSSEGS,
  1115. pEntry->Info.ts_retranssegs );
  1116. if ( VerboseFlag )
  1117. {
  1118. switch ( pEntry->Info.ts_rtoalgorithm )
  1119. {
  1120. case 1:
  1121. PutMsg( STDOUT, MSG_TCP_RTOALGORITHM1 );
  1122. break;
  1123. case 2:
  1124. PutMsg( STDOUT, MSG_TCP_RTOALGORITHM2 );
  1125. break;
  1126. case 3:
  1127. PutMsg( STDOUT, MSG_TCP_RTOALGORITHM3 );
  1128. break;
  1129. case 4:
  1130. PutMsg( STDOUT, MSG_TCP_RTOALGORITHM4 );
  1131. break;
  1132. default:
  1133. PutMsg( STDOUT,
  1134. MSG_TCP_RTOALGORITHMX,
  1135. pEntry->Info.ts_rtoalgorithm );
  1136. break;
  1137. }
  1138. PutMsg( STDOUT,
  1139. MSG_TCP_RTOMIN,
  1140. pEntry->Info.ts_rtomin );
  1141. PutMsg( STDOUT,
  1142. MSG_TCP_RTOMAX,
  1143. pEntry->Info.ts_rtomax );
  1144. PutMsg( STDOUT,
  1145. MSG_TCP_MAXCONN,
  1146. pEntry->Info.ts_maxconn );
  1147. }
  1148. }
  1149. //*****************************************************************************
  1150. //
  1151. // Name: DisplayUDP
  1152. //
  1153. // Description: Display UDP statistics.
  1154. //
  1155. // Parameters: UdpEntry *pEntry: pointer to summary data entry.
  1156. // ulong VerboseFlag: boolean indicating desire for verbosity.
  1157. // UdpEntry *ListHead: pointer to list of entries. Used if
  1158. // verbosity desired.
  1159. //
  1160. // Returns: void.
  1161. //
  1162. // History:
  1163. // 01/21/94 JayPh Created.
  1164. //
  1165. //*****************************************************************************
  1166. void DisplayUDP( DWORD Type, UdpEntry *pEntry, ulong VerboseFlag, UdpEntry *ListHead )
  1167. {
  1168. uchar *TypeStr = LoadMsg( (Type==TYPE_UDP)? MSG_IPV4 : MSG_IPV6 );
  1169. UNREFERENCED_PARAMETER(VerboseFlag);
  1170. UNREFERENCED_PARAMETER(ListHead);
  1171. if (TypeStr) {
  1172. PutMsg( STDOUT, MSG_UDP_HDR, TypeStr );
  1173. LocalFree(TypeStr);
  1174. }
  1175. PutMsg( STDOUT,
  1176. MSG_UDP_INDATAGRAMS,
  1177. pEntry->Info.us_indatagrams );
  1178. PutMsg( STDOUT,
  1179. MSG_UDP_NOPORTS,
  1180. pEntry->Info.us_noports );
  1181. PutMsg( STDOUT,
  1182. MSG_UDP_INERRORS,
  1183. pEntry->Info.us_inerrors );
  1184. PutMsg( STDOUT,
  1185. MSG_UDP_OUTDATAGRAMS,
  1186. pEntry->Info.us_outdatagrams );
  1187. }
  1188. //*****************************************************************************
  1189. //
  1190. // Name: DisplayICMP
  1191. //
  1192. // Description: Display ICMP statistics.
  1193. //
  1194. // Parameters: IcmpEntry *pEntry: pointer to summary data entry.
  1195. // ulong VerboseFlag: boolean indicating desire for verbosity.
  1196. // IcmpEntry *ListHead: pointer to list of entries. Used if
  1197. // verbosity desired.
  1198. //
  1199. // Returns: void.
  1200. //
  1201. // History:
  1202. // 01/21/94 JayPh Created.
  1203. //
  1204. //*****************************************************************************
  1205. void DisplayICMP( IcmpEntry *pEntry, ulong VerboseFlag, IcmpEntry *ListHead )
  1206. {
  1207. UNREFERENCED_PARAMETER(VerboseFlag);
  1208. UNREFERENCED_PARAMETER(ListHead);
  1209. PutMsg( STDOUT, MSG_ICMP_HDR );
  1210. PutMsg( STDOUT,
  1211. MSG_ICMP_MSGS,
  1212. pEntry->InInfo.icmps_msgs,
  1213. pEntry->OutInfo.icmps_msgs );
  1214. PutMsg( STDOUT,
  1215. MSG_ICMP_ERRORS,
  1216. pEntry->InInfo.icmps_errors,
  1217. pEntry->OutInfo.icmps_errors );
  1218. PutMsg( STDOUT,
  1219. MSG_ICMP_DESTUNREACHS,
  1220. pEntry->InInfo.icmps_destunreachs,
  1221. pEntry->OutInfo.icmps_destunreachs );
  1222. PutMsg( STDOUT,
  1223. MSG_ICMP_TIMEEXCDS,
  1224. pEntry->InInfo.icmps_timeexcds,
  1225. pEntry->OutInfo.icmps_timeexcds );
  1226. PutMsg( STDOUT,
  1227. MSG_ICMP_PARMPROBS,
  1228. pEntry->InInfo.icmps_parmprobs,
  1229. pEntry->OutInfo.icmps_parmprobs );
  1230. PutMsg( STDOUT,
  1231. MSG_ICMP_SRCQUENCHS,
  1232. pEntry->InInfo.icmps_srcquenchs,
  1233. pEntry->OutInfo.icmps_srcquenchs );
  1234. PutMsg( STDOUT,
  1235. MSG_ICMP_REDIRECTS,
  1236. pEntry->InInfo.icmps_redirects,
  1237. pEntry->OutInfo.icmps_redirects );
  1238. PutMsg( STDOUT,
  1239. MSG_ICMP_ECHOS,
  1240. pEntry->InInfo.icmps_echos,
  1241. pEntry->OutInfo.icmps_echos );
  1242. PutMsg( STDOUT,
  1243. MSG_ICMP_ECHOREPS,
  1244. pEntry->InInfo.icmps_echoreps,
  1245. pEntry->OutInfo.icmps_echoreps );
  1246. PutMsg( STDOUT,
  1247. MSG_ICMP_TIMESTAMPS,
  1248. pEntry->InInfo.icmps_timestamps,
  1249. pEntry->OutInfo.icmps_timestamps );
  1250. PutMsg( STDOUT,
  1251. MSG_ICMP_TIMESTAMPREPS,
  1252. pEntry->InInfo.icmps_timestampreps,
  1253. pEntry->OutInfo.icmps_timestampreps );
  1254. PutMsg( STDOUT,
  1255. MSG_ICMP_ADDRMASKS,
  1256. pEntry->InInfo.icmps_addrmasks,
  1257. pEntry->OutInfo.icmps_addrmasks );
  1258. PutMsg( STDOUT,
  1259. MSG_ICMP_ADDRMASKREPS,
  1260. pEntry->InInfo.icmps_addrmaskreps,
  1261. pEntry->OutInfo.icmps_addrmaskreps );
  1262. }
  1263. typedef struct {
  1264. uint Type;
  1265. uint Message;
  1266. } ICMP_TYPE_MESSAGE;
  1267. //
  1268. // List of messages for known ICMPv6 types. Entries in this list
  1269. // must be in order by Type.
  1270. //
  1271. ICMP_TYPE_MESSAGE Icmp6TypeMessage[] = {
  1272. { ICMPv6_DESTINATION_UNREACHABLE, MSG_ICMP_DESTUNREACHS },
  1273. { ICMPv6_PACKET_TOO_BIG, MSG_ICMP_PACKET_TOO_BIGS },
  1274. { ICMPv6_TIME_EXCEEDED, MSG_ICMP_TIMEEXCDS },
  1275. { ICMPv6_PARAMETER_PROBLEM, MSG_ICMP_PARMPROBS },
  1276. { ICMPv6_ECHO_REQUEST, MSG_ICMP_ECHOS },
  1277. { ICMPv6_ECHO_REPLY, MSG_ICMP_ECHOREPS },
  1278. { ICMPv6_MULTICAST_LISTENER_QUERY, MSG_ICMP_MLD_QUERY },
  1279. { ICMPv6_MULTICAST_LISTENER_REPORT, MSG_ICMP_MLD_REPORT },
  1280. { ICMPv6_MULTICAST_LISTENER_DONE, MSG_ICMP_MLD_DONE },
  1281. { ICMPv6_ROUTER_SOLICIT, MSG_ICMP_ROUTER_SOLICIT },
  1282. { ICMPv6_ROUTER_ADVERT, MSG_ICMP_ROUTER_ADVERT },
  1283. { ICMPv6_NEIGHBOR_SOLICIT, MSG_ICMP_NEIGHBOR_SOLICIT },
  1284. { ICMPv6_NEIGHBOR_ADVERT, MSG_ICMP_NEIGHBOR_ADVERT },
  1285. { ICMPv6_REDIRECT, MSG_ICMP_REDIRECTS },
  1286. { ICMPv6_ROUTER_RENUMBERING, MSG_ICMP_ROUTER_RENUMBERING },
  1287. { 0, 0 }
  1288. };
  1289. void DisplayICMP6( Icmp6Entry *pEntry, ulong VerboseFlag, IcmpEntry *ListHead )
  1290. {
  1291. uint i = 0, Type, Message;
  1292. UNREFERENCED_PARAMETER(VerboseFlag);
  1293. UNREFERENCED_PARAMETER(ListHead);
  1294. PutMsg( STDOUT, MSG_ICMP6_HDR );
  1295. PutMsg( STDOUT,
  1296. MSG_ICMP_MSGS,
  1297. pEntry->InInfo.icmps_msgs,
  1298. pEntry->OutInfo.icmps_msgs );
  1299. PutMsg( STDOUT,
  1300. MSG_ICMP_ERRORS,
  1301. pEntry->InInfo.icmps_errors,
  1302. pEntry->OutInfo.icmps_errors );
  1303. for (Type=0; Type<256; Type++) {
  1304. // Figure out message id
  1305. Message = 0;
  1306. if (Type == Icmp6TypeMessage[i].Type)
  1307. {
  1308. Message = Icmp6TypeMessage[i++].Message;
  1309. }
  1310. // Skip types with 0 packets in and out
  1311. if (!pEntry->InInfo.icmps_typecount[Type] &&
  1312. !pEntry->OutInfo.icmps_typecount[Type])
  1313. {
  1314. continue;
  1315. }
  1316. if (Message)
  1317. {
  1318. PutMsg( STDOUT,
  1319. Message,
  1320. pEntry->InInfo.icmps_typecount[Type],
  1321. pEntry->OutInfo.icmps_typecount[Type] );
  1322. }
  1323. else
  1324. {
  1325. PutMsg( STDOUT,
  1326. MSG_ICMP6_TYPECOUNT,
  1327. Type,
  1328. pEntry->InInfo.icmps_typecount[Type],
  1329. pEntry->OutInfo.icmps_typecount[Type] );
  1330. }
  1331. }
  1332. }
  1333. static DWORD
  1334. GenerateHostNameServiceString(
  1335. OUT char * pszBuffer,
  1336. IN OUT int * lpcbBufLen,
  1337. IN BOOL fNumFlag,
  1338. IN BOOL fLocalHost,
  1339. IN BOOL fDatagram,
  1340. IN LPSOCKADDR lpSockaddr,
  1341. IN ulong uSockaddrLen
  1342. )
  1343. /*++
  1344. Description:
  1345. Generates the <hostname>:<service-string> from the address and port
  1346. information supplied. The result is stored in the pszBuffer passed in.
  1347. If fLocalHost == TRUE, then the cached local host name is used to
  1348. improve performance.
  1349. Arguments:
  1350. pszBuffer Buffer to store the resulting string.
  1351. lpcbBufLen pointer to integer containing the count of bytes in Buffer
  1352. and on return contains the number of bytes written.
  1353. If the buffer is insufficient, then the required bytes is
  1354. stored here.
  1355. fNumFlag generates the output using numbers for host and port number.
  1356. fLocalHost indicates if we want the service string for local host or
  1357. remote host. Also for local host, this function generates
  1358. the local host name without FQDN.
  1359. pszProtocol specifies the protocol used for the service.
  1360. uAddress unisgned long address of the service.
  1361. uPort unsinged long port number.
  1362. Returns:
  1363. Win32 error codes. NO_ERROR on success.
  1364. History:
  1365. MuraliK 12/15/94
  1366. Added this function to avoid FQDNs for local name + abstract the common
  1367. code used multiple times in old code.
  1368. Also this function provides local host name caching.
  1369. --*/
  1370. {
  1371. char LocalBuffer[MAX_HOST_NAME_SIZE]; // to hold dummy output
  1372. char LocalServiceEntry[MAX_SERVICE_NAME_SIZE];
  1373. int BufferLen;
  1374. char * pszHostName = NULL; // init a pointer.
  1375. char * pszServiceName = NULL;
  1376. DWORD dwError = NO_ERROR;
  1377. int Result;
  1378. int Flags = 0;
  1379. // for caching local host name. getnameinfo doesn't seem to find the
  1380. // host name for a local address.
  1381. static char s_LocalHostName[MAX_HOST_NAME_SIZE];
  1382. static BOOL s_fLocalHostName = FALSE;
  1383. if ( pszBuffer == NULL) {
  1384. return ( ERROR_INSUFFICIENT_BUFFER);
  1385. }
  1386. *pszBuffer = '\0'; // initialize to null string
  1387. if (fNumFlag) {
  1388. Flags |= NI_NUMERICHOST | NI_NUMERICSERV;
  1389. }
  1390. if (fLocalHost) {
  1391. Flags |= NI_NOFQDN;
  1392. }
  1393. if (fDatagram) {
  1394. Flags |= NI_DGRAM;
  1395. }
  1396. //
  1397. // This complexity shouldn't be required but unlike the hostname string,
  1398. // getnameinfo doesn't automatically include the numeric form
  1399. // when a service name isn't found. Instead, it fails.
  1400. //
  1401. if (fLocalHost && !fNumFlag) {
  1402. if ( s_fLocalHostName) {
  1403. pszHostName = s_LocalHostName; // pull from the cache
  1404. } else {
  1405. Result = gethostname( s_LocalHostName,
  1406. sizeof( s_LocalHostName));
  1407. if ( Result == 0) {
  1408. char * pszFirstDot;
  1409. //
  1410. // Cache the copy of local host name now.
  1411. // Limit the host name to first part of host name.
  1412. // NO FQDN
  1413. //
  1414. s_fLocalHostName = TRUE;
  1415. pszFirstDot = strchr( s_LocalHostName, '.');
  1416. if ( pszFirstDot != NULL) {
  1417. *pszFirstDot = '\0'; // terminate string
  1418. }
  1419. pszHostName = s_LocalHostName;
  1420. }
  1421. } // if ( s_fLocalhost)
  1422. }
  1423. if (!pszHostName) {
  1424. Result = getnameinfo(lpSockaddr, uSockaddrLen,
  1425. LocalBuffer, sizeof(LocalBuffer),
  1426. NULL, 0,
  1427. Flags);
  1428. if ((Result != 0) && !fNumFlag) {
  1429. //
  1430. // A normal lookup failed. Fall back to using the string
  1431. // literal.
  1432. //
  1433. Result = getnameinfo(lpSockaddr, uSockaddrLen,
  1434. LocalBuffer, sizeof(LocalBuffer),
  1435. NULL, 0,
  1436. Flags | NI_NUMERICHOST);
  1437. }
  1438. if (Result != 0) {
  1439. return Result;
  1440. }
  1441. pszHostName = LocalBuffer;
  1442. }
  1443. Result = getnameinfo(lpSockaddr, uSockaddrLen,
  1444. NULL, 0,
  1445. LocalServiceEntry, sizeof(LocalServiceEntry),
  1446. Flags);
  1447. if ((Result == WSANO_DATA) && !fNumFlag) {
  1448. Result = getnameinfo(lpSockaddr, uSockaddrLen,
  1449. NULL, 0,
  1450. LocalServiceEntry, sizeof(LocalServiceEntry),
  1451. Flags | NI_NUMERICSERV);
  1452. }
  1453. if (Result != 0) {
  1454. return Result;
  1455. }
  1456. pszServiceName = LocalServiceEntry;
  1457. // Now pszServiceName has the service name/portnumber
  1458. BufferLen = (int)strlen( pszHostName) + (int)strlen( pszServiceName) + 4;
  1459. // 4 bytes extra for "[]:" and null-character.
  1460. if ( *lpcbBufLen < BufferLen ) {
  1461. dwError = ERROR_INSUFFICIENT_BUFFER;
  1462. } else if ((lpSockaddr->sa_family == AF_INET6) && strchr(pszHostName, ':')) {
  1463. sprintf( pszBuffer, "[%s]:%s", pszHostName, pszServiceName);
  1464. } else {
  1465. sprintf( pszBuffer, "%s:%s", pszHostName, pszServiceName);
  1466. }
  1467. *lpcbBufLen = BufferLen;
  1468. return ( dwError);
  1469. } // GenerateHostNameServiceString()
  1470. static DWORD
  1471. GenerateV4HostNameServiceString(
  1472. OUT char * pszBuffer,
  1473. IN OUT int * lpcbBufLen,
  1474. IN BOOL fNumFlag,
  1475. IN BOOL fLocalHost,
  1476. IN BOOL fDatagram,
  1477. IN ulong uAddress,
  1478. IN ulong uPort
  1479. )
  1480. {
  1481. SOCKADDR_IN sin;
  1482. ZeroMemory(&sin, sizeof(sin));
  1483. sin.sin_family = AF_INET;
  1484. sin.sin_addr.s_addr = uAddress;
  1485. sin.sin_port = htons((ushort)uPort);
  1486. return GenerateHostNameServiceString(pszBuffer,
  1487. lpcbBufLen,
  1488. fNumFlag,
  1489. fLocalHost,
  1490. fDatagram,
  1491. (LPSOCKADDR)&sin,
  1492. sizeof(sin));
  1493. }
  1494. static DWORD
  1495. GenerateV6HostNameServiceString(
  1496. OUT char * pszBuffer,
  1497. IN OUT int * lpcbBufLen,
  1498. IN BOOL fNumFlag,
  1499. IN BOOL fLocalHost,
  1500. IN BOOL fDatagram,
  1501. IN struct in6_addr *ipAddress,
  1502. IN ulong uScopeId,
  1503. IN ulong uPort
  1504. )
  1505. {
  1506. SOCKADDR_IN6 sin;
  1507. ZeroMemory(&sin, sizeof(sin));
  1508. sin.sin6_family = AF_INET6;
  1509. sin.sin6_addr = *ipAddress;
  1510. sin.sin6_scope_id = uScopeId;
  1511. sin.sin6_port = htons((ushort)uPort);
  1512. return GenerateHostNameServiceString(pszBuffer,
  1513. lpcbBufLen,
  1514. fNumFlag,
  1515. fLocalHost,
  1516. fDatagram,
  1517. (LPSOCKADDR)&sin,
  1518. sizeof(sin));
  1519. }
  1520. //*****************************************************************************
  1521. //
  1522. // Name: DisplayTcpConnEntry
  1523. //
  1524. // Description: Display information about 1 tcp connection.
  1525. //
  1526. // Parameters: TcpConnTableEntry *pTcp: pointer to a tcp connection structure.
  1527. // InfoSize: indicates whether the data is a TCPConnTableEntry or
  1528. // TCPConnTableEntryEx.
  1529. //
  1530. // Returns: void.
  1531. //
  1532. // History:
  1533. // 12/31/93 JayPh Created.
  1534. // 02/01/94 JayPh Use symbolic names for addresses and ports if available
  1535. // 12/15/94 MuraliK Avoid printing FQDNs for local host.
  1536. //
  1537. //*****************************************************************************
  1538. void DisplayTcpConnEntry( TCPConnTableEntry *pTcp, ulong InfoSize, ulong NumFlag )
  1539. {
  1540. uchar *TypeStr;
  1541. uchar *StateStr;
  1542. char LocalStr[MAX_HOST_NAME_SIZE + MAX_SERVICE_NAME_SIZE];
  1543. char RemoteStr[MAX_HOST_NAME_SIZE + MAX_SERVICE_NAME_SIZE];
  1544. DWORD dwErr;
  1545. int BufLen;
  1546. TypeStr = LoadMsg( MSG_CONN_TYPE_TCP );
  1547. if ( TypeStr == NULL )
  1548. {
  1549. return;
  1550. }
  1551. BufLen = sizeof( LocalStr);
  1552. dwErr = GenerateV4HostNameServiceString( LocalStr,
  1553. &BufLen,
  1554. NumFlag != 0, TRUE, FALSE,
  1555. pTcp->tct_localaddr,
  1556. pTcp->tct_localport);
  1557. ASSERT( dwErr == NO_ERROR);
  1558. switch ( pTcp->tct_state )
  1559. {
  1560. case TCP_CONN_CLOSED:
  1561. StateStr = LoadMsg( MSG_CONN_STATE_CLOSED );
  1562. break;
  1563. case TCP_CONN_LISTEN:
  1564. // Tcpip generates dummy sequential remote ports for
  1565. // listening connections to avoid getting stuck in snmp.
  1566. // MohsinA, 12-Feb-97.
  1567. pTcp->tct_remoteport = 0;
  1568. StateStr = LoadMsg( MSG_CONN_STATE_LISTENING );
  1569. break;
  1570. case TCP_CONN_SYN_SENT:
  1571. StateStr = LoadMsg( MSG_CONN_STATE_SYNSENT );
  1572. break;
  1573. case TCP_CONN_SYN_RCVD:
  1574. StateStr = LoadMsg( MSG_CONN_STATE_SYNRECV );
  1575. break;
  1576. case TCP_CONN_ESTAB:
  1577. StateStr = LoadMsg( MSG_CONN_STATE_ESTABLISHED );
  1578. break;
  1579. case TCP_CONN_FIN_WAIT1:
  1580. StateStr = LoadMsg( MSG_CONN_STATE_FIN_WAIT_1 );
  1581. break;
  1582. case TCP_CONN_FIN_WAIT2:
  1583. StateStr = LoadMsg( MSG_CONN_STATE_FIN_WAIT_2 );
  1584. break;
  1585. case TCP_CONN_CLOSE_WAIT:
  1586. StateStr = LoadMsg( MSG_CONN_STATE_CLOSE_WAIT );
  1587. break;
  1588. case TCP_CONN_CLOSING:
  1589. StateStr = LoadMsg( MSG_CONN_STATE_CLOSING );
  1590. break;
  1591. case TCP_CONN_LAST_ACK:
  1592. StateStr = LoadMsg( MSG_CONN_STATE_LAST_ACK );
  1593. break;
  1594. case TCP_CONN_TIME_WAIT:
  1595. StateStr = LoadMsg( MSG_CONN_STATE_TIME_WAIT );
  1596. break;
  1597. default:
  1598. StateStr = NULL;
  1599. DEBUG_PRINT(("DisplayTcpConnEntry: State=%d?\n ",
  1600. pTcp->tct_state ));
  1601. }
  1602. BufLen = sizeof( RemoteStr);
  1603. dwErr = GenerateV4HostNameServiceString( RemoteStr,
  1604. &BufLen,
  1605. NumFlag != 0, FALSE, FALSE,
  1606. pTcp->tct_remoteaddr,
  1607. pTcp->tct_remoteport );
  1608. ASSERT( dwErr == NO_ERROR);
  1609. if ( StateStr == NULL )
  1610. {
  1611. DEBUG_PRINT(("DisplayTcpConnEntry: Problem with the message file\n"));
  1612. LocalFree(TypeStr);
  1613. return;
  1614. }
  1615. if (sizeof(TCPConnTableEntryEx) == InfoSize)
  1616. {
  1617. ulong Pid = ((TCPConnTableEntryEx*)pTcp)->tcte_owningpid;
  1618. PutMsg( STDOUT, MSG_CONN_ENTRY_EX, TypeStr, LocalStr, RemoteStr, StateStr, Pid );
  1619. }
  1620. else
  1621. {
  1622. PutMsg( STDOUT, MSG_CONN_ENTRY, TypeStr, LocalStr, RemoteStr, StateStr );
  1623. }
  1624. LocalFree(TypeStr);
  1625. LocalFree(StateStr);
  1626. }
  1627. //*****************************************************************************
  1628. //
  1629. // Name: DisplayTcp6ConnEntry
  1630. //
  1631. // Description: Display information about 1 tcp connection over IPv6.
  1632. //
  1633. // Parameters: TCP6ConnTableEntry *pTcp: pointer to a tcp connection structure.
  1634. //
  1635. // Returns: void.
  1636. //
  1637. // History:
  1638. // 24/04/01 DThaler Created.
  1639. //
  1640. //*****************************************************************************
  1641. void DisplayTcp6ConnEntry( TCP6ConnTableEntry *pTcp, ulong NumFlag )
  1642. {
  1643. uchar *TypeStr;
  1644. uchar *StateStr;
  1645. char LocalStr[MAX_HOST_NAME_SIZE + MAX_SERVICE_NAME_SIZE];
  1646. char RemoteStr[MAX_HOST_NAME_SIZE + MAX_SERVICE_NAME_SIZE];
  1647. DWORD dwErr;
  1648. int BufLen;
  1649. TypeStr = LoadMsg( MSG_CONN_TYPE_TCP );
  1650. if ( TypeStr == NULL )
  1651. {
  1652. return;
  1653. }
  1654. BufLen = sizeof( LocalStr);
  1655. dwErr = GenerateV6HostNameServiceString( LocalStr,
  1656. &BufLen,
  1657. NumFlag != 0, TRUE, FALSE,
  1658. &pTcp->tct_localaddr,
  1659. pTcp->tct_localscopeid,
  1660. pTcp->tct_localport);
  1661. ASSERT( dwErr == NO_ERROR);
  1662. switch ( pTcp->tct_state )
  1663. {
  1664. case TCP_CONN_CLOSED:
  1665. StateStr = LoadMsg( MSG_CONN_STATE_CLOSED );
  1666. break;
  1667. case TCP_CONN_LISTEN:
  1668. // Tcpip generates dummy sequential remote ports for
  1669. // listening connections to avoid getting stuck in snmp.
  1670. // MohsinA, 12-Feb-97.
  1671. pTcp->tct_remoteport = 0;
  1672. StateStr = LoadMsg( MSG_CONN_STATE_LISTENING );
  1673. break;
  1674. case TCP_CONN_SYN_SENT:
  1675. StateStr = LoadMsg( MSG_CONN_STATE_SYNSENT );
  1676. break;
  1677. case TCP_CONN_SYN_RCVD:
  1678. StateStr = LoadMsg( MSG_CONN_STATE_SYNRECV );
  1679. break;
  1680. case TCP_CONN_ESTAB:
  1681. StateStr = LoadMsg( MSG_CONN_STATE_ESTABLISHED );
  1682. break;
  1683. case TCP_CONN_FIN_WAIT1:
  1684. StateStr = LoadMsg( MSG_CONN_STATE_FIN_WAIT_1 );
  1685. break;
  1686. case TCP_CONN_FIN_WAIT2:
  1687. StateStr = LoadMsg( MSG_CONN_STATE_FIN_WAIT_2 );
  1688. break;
  1689. case TCP_CONN_CLOSE_WAIT:
  1690. StateStr = LoadMsg( MSG_CONN_STATE_CLOSE_WAIT );
  1691. break;
  1692. case TCP_CONN_CLOSING:
  1693. StateStr = LoadMsg( MSG_CONN_STATE_CLOSING );
  1694. break;
  1695. case TCP_CONN_LAST_ACK:
  1696. StateStr = LoadMsg( MSG_CONN_STATE_LAST_ACK );
  1697. break;
  1698. case TCP_CONN_TIME_WAIT:
  1699. StateStr = LoadMsg( MSG_CONN_STATE_TIME_WAIT );
  1700. break;
  1701. default:
  1702. StateStr = NULL;
  1703. DEBUG_PRINT(("DisplayTcp6ConnEntry: State=%d?\n ",
  1704. pTcp->tct_state ));
  1705. }
  1706. BufLen = sizeof( RemoteStr);
  1707. dwErr = GenerateV6HostNameServiceString( RemoteStr,
  1708. &BufLen,
  1709. NumFlag != 0, FALSE, FALSE,
  1710. &pTcp->tct_remoteaddr,
  1711. pTcp->tct_remotescopeid,
  1712. pTcp->tct_remoteport );
  1713. ASSERT( dwErr == NO_ERROR);
  1714. if ( StateStr == NULL )
  1715. {
  1716. DEBUG_PRINT(("DisplayTcp6ConnEntry: Problem with the message file\n"));
  1717. LocalFree(TypeStr);
  1718. return;
  1719. }
  1720. PutMsg( STDOUT, MSG_CONN_ENTRY_EX, TypeStr, LocalStr, RemoteStr, StateStr, pTcp->tct_owningpid );
  1721. LocalFree(TypeStr);
  1722. LocalFree(StateStr);
  1723. }
  1724. //*****************************************************************************
  1725. //
  1726. // Name: DisplayUdpConnEntry
  1727. //
  1728. // Description: Display information on 1 udp connection
  1729. //
  1730. // Parameters: UDPEntry *pUdp: pointer to udp connection structure.
  1731. // InfoSize: indicates whether the data is a UDPEntry or
  1732. // UDPEntryEx.
  1733. //
  1734. // Returns: void.
  1735. //
  1736. // History:
  1737. // 12/31/93 JayPh Created.
  1738. // 02/01/94 JayPh Use symbolic names for addresses and ports if available
  1739. //
  1740. //*****************************************************************************
  1741. void DisplayUdpConnEntry( UDPEntry *pUdp, ulong InfoSize, ulong NumFlag )
  1742. {
  1743. uchar *TypeStr;
  1744. char LocalStr[MAX_HOST_NAME_SIZE + MAX_SERVICE_NAME_SIZE];
  1745. uchar *RemoteStr;
  1746. int BufLen;
  1747. DWORD dwErr;
  1748. TypeStr = LoadMsg( MSG_CONN_TYPE_UDP );
  1749. if ( TypeStr == NULL )
  1750. {
  1751. return;
  1752. }
  1753. BufLen = sizeof( LocalStr);
  1754. dwErr = GenerateV4HostNameServiceString( LocalStr,
  1755. &BufLen,
  1756. NumFlag != 0, TRUE, TRUE,
  1757. pUdp->ue_localaddr,
  1758. pUdp->ue_localport);
  1759. ASSERT( dwErr == NO_ERROR);
  1760. RemoteStr = LoadMsg( MSG_CONN_UDP_FORADDR );
  1761. if ( RemoteStr == NULL )
  1762. {
  1763. DEBUG_PRINT(("DisplayUdpConnEntry: no message?\n"));
  1764. LocalFree(TypeStr);
  1765. return;
  1766. }
  1767. if (sizeof(UDPEntryEx) == InfoSize)
  1768. {
  1769. ulong Pid = ((UDPEntryEx*)pUdp)->uee_owningpid;
  1770. PutMsg( STDOUT, MSG_CONN_ENTRY_EX, TypeStr, LocalStr, RemoteStr, "", Pid );
  1771. }
  1772. else
  1773. {
  1774. PutMsg( STDOUT, MSG_CONN_ENTRY, TypeStr, LocalStr, RemoteStr, "" );
  1775. }
  1776. LocalFree(TypeStr);
  1777. LocalFree(RemoteStr);
  1778. }
  1779. void DisplayUdp6ListenerEntry( UDP6ListenerEntry *pUdp, BOOL WithOwner, ulong NumFlag )
  1780. {
  1781. uchar *TypeStr;
  1782. char LocalStr[MAX_HOST_NAME_SIZE + MAX_SERVICE_NAME_SIZE];
  1783. uchar *RemoteStr;
  1784. int BufLen;
  1785. DWORD dwErr;
  1786. TypeStr = LoadMsg( MSG_CONN_TYPE_UDP );
  1787. if ( TypeStr == NULL )
  1788. {
  1789. return;
  1790. }
  1791. BufLen = sizeof( LocalStr);
  1792. dwErr = GenerateV6HostNameServiceString( LocalStr,
  1793. &BufLen,
  1794. NumFlag != 0, TRUE, TRUE,
  1795. &pUdp->ule_localaddr,
  1796. pUdp->ule_localscopeid,
  1797. pUdp->ule_localport);
  1798. ASSERT( dwErr == NO_ERROR);
  1799. RemoteStr = LoadMsg( MSG_CONN_UDP_FORADDR );
  1800. if ( RemoteStr == NULL )
  1801. {
  1802. DEBUG_PRINT(("DisplayUdpConnEntry: no message?\n"));
  1803. LocalFree(TypeStr);
  1804. return;
  1805. }
  1806. if (WithOwner)
  1807. {
  1808. ulong Pid = pUdp->ule_owningpid;
  1809. PutMsg( STDOUT, MSG_CONN_ENTRY_EX, TypeStr, LocalStr, RemoteStr, "", Pid );
  1810. }
  1811. else
  1812. {
  1813. PutMsg( STDOUT, MSG_CONN_ENTRY, TypeStr, LocalStr, RemoteStr, "" );
  1814. }
  1815. LocalFree(TypeStr);
  1816. LocalFree(RemoteStr);
  1817. }
  1818. //*****************************************************************************
  1819. //
  1820. // Name: Usage
  1821. //
  1822. // Description: Called when a command line parameter problem is detected, it
  1823. // displays a proper command usage message and exits.
  1824. //
  1825. // WARNING: This routine does not return.
  1826. //
  1827. // Parameters: char *PgmName: pointer to string contain name of program.
  1828. //
  1829. // Returns: Doesn't return.
  1830. //
  1831. // History:
  1832. // 01/04/93 JayPh Created.
  1833. //
  1834. //*****************************************************************************
  1835. void Usage( void )
  1836. {
  1837. PutMsg( STDERR, MSG_USAGE, PgmName );
  1838. exit( 1 );
  1839. }