mirror of
https://github.com/reactos/reactos.git
synced 2025-08-06 16:22:58 +00:00
[0.4.13][NETSTAT] Picky Backports up to master-state 2023-07-06
0.4.15-dev-6256-g8ef47d2e5e
[NETSTAT] Optimize a bit (#5405) partially 0.4.15-dev-6245-g5ee97b9537
[NETSTAT] -b flag implies -o flag on Windows XP/2003. CORE-19006 (#5377) partially 0.4.15-dev-6211-g40864bc15c
[NETSTAT] Fix crash when parsing the protocol CORE-19005 (#5363) partially 0.4.14-dev-479-g1fa2780796
[NETSTAT] Fix output formats
This commit is contained in:
parent
7d4c736506
commit
f074f61f65
3 changed files with 47 additions and 63 deletions
|
@ -6,7 +6,7 @@ BEGIN
|
|||
NETSTAT [-a] [-e] [-n] [-o] [-p proto] [-r] [-s] [interval]\n\n\
|
||||
-a Displays all connections and listening ports.\n\
|
||||
-e Displays Ethernet statistics. May be combined with -s\n\
|
||||
option\n\
|
||||
option.\n\
|
||||
-n Displays address and port numbers in numeric form.\n\
|
||||
-o Displays the process ID for each connection.\n\
|
||||
-p proto Shows connections for protocol 'proto' TCP or UDP.\n\
|
||||
|
@ -18,7 +18,7 @@ NETSTAT [-a] [-e] [-n] [-o] [-p proto] [-r] [-s] [interval]\n\n\
|
|||
the -p option may be used to specify a subset of the default.\n\
|
||||
interval Redisplays selected statistics every 'interval' seconds.\n\
|
||||
Press CTRL+C to stop redisplaying. By default netstat will\n\
|
||||
print the current information only once.\n\n"
|
||||
print the current information only once.\n"
|
||||
IDS_DISPLAY_THEADER "\n Proto Local Address Foreign Address State"
|
||||
IDS_DISPLAY_PROCESS " Process\n"
|
||||
IDS_ACTIVE_CONNECT "\nActive Connections\n"
|
||||
|
@ -37,9 +37,9 @@ BEGIN
|
|||
IDS_IP_OUT_REQUEST " Output Requests = %lu\n"
|
||||
IDS_IP_ROUTE_DISCARD " Routing Discards = %lu\n"
|
||||
IDS_IP_DISCARD_OUT_PACK " Discarded Output Packets = %lu\n"
|
||||
IDS_IP_OUT_PACKET_NO_ROUTE " Output Packets No Route = %lu\n"
|
||||
IDS_IP_OUT_PACKET_NO_ROUTE " Output Packet No Route = %lu\n"
|
||||
IDS_IP_REASSEMBLE_REQUIRED " Reassembly Required = %lu\n"
|
||||
IDS_IP_REASSEMBLE_SUCCESS " Reassembly Succesful = %lu\n"
|
||||
IDS_IP_REASSEMBLE_SUCCESS " Reassembly Successful = %lu\n"
|
||||
IDS_IP_REASSEMBLE_FAILURE " Reassembly Failures = %lu\n"
|
||||
IDS_IP_DATAG_FRAG_SUCCESS " Datagrams Successfully Fragmented = %lu\n"
|
||||
IDS_IP_DATAG_FRAG_FAILURE " Datagrams Failing Fragmentation = %lu\n"
|
||||
|
@ -96,7 +96,7 @@ BEGIN
|
|||
IDS_ETHERNET_NON_UNICAST_PACKET "Non-unicast packets %14lu %15lu\n"
|
||||
IDS_ETHERNET_DISCARD "Discards %14lu %15lu\n"
|
||||
IDS_ETHERNET_ERROR "Errors %14lu %15lu\n"
|
||||
IDS_ETHERNET_UNKNOWN " Unknown Protocols %14lu\n"
|
||||
IDS_ETHERNET_UNKNOWN "Unknown protocols %14lu\n"
|
||||
END
|
||||
|
||||
STRINGTABLE
|
||||
|
|
|
@ -1,16 +1,13 @@
|
|||
/*
|
||||
* PROJECT: ReactOS netstat utility
|
||||
* LICENSE: GPL - See COPYING in the top level directory
|
||||
* FILE: base/applications/network/netstat/netstat.c
|
||||
* PURPOSE: display IP stack statistics
|
||||
* COPYRIGHT: Copyright 2005 Ged Murphy <gedmurphy@gmail.com>
|
||||
*/
|
||||
/*
|
||||
* TODO:
|
||||
* sort function return values.
|
||||
* implement -b, -o and -v
|
||||
* implement -b, -t and -v
|
||||
* clean up GetIpHostName
|
||||
* command line parser needs more work
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
@ -61,10 +58,18 @@ VOID DoFormatMessage(DWORD ErrorCode)
|
|||
NULL, ErrorCode, LANG_USER_DEFAULT);
|
||||
}
|
||||
|
||||
VOID DisplayTableHeader(VOID)
|
||||
{
|
||||
ConResPuts(StdOut, IDS_ACTIVE_CONNECT);
|
||||
ConResPuts(StdOut, IDS_DISPLAY_THEADER);
|
||||
if (bDoShowProcessId)
|
||||
ConResPuts(StdOut, IDS_DISPLAY_PROCESS);
|
||||
else
|
||||
ConPuts(StdOut, L"\n");
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
* Parse command line parameters and set any options
|
||||
*
|
||||
*/
|
||||
BOOL ParseCmdline(int argc, wchar_t* argv[])
|
||||
{
|
||||
|
@ -89,6 +94,7 @@ BOOL ParseCmdline(int argc, wchar_t* argv[])
|
|||
break;
|
||||
case L'b':
|
||||
bDoShowProcName = TRUE;
|
||||
bDoShowProcessId = TRUE;
|
||||
break;
|
||||
case L'e':
|
||||
bDoShowEthStats = TRUE;
|
||||
|
@ -96,8 +102,17 @@ BOOL ParseCmdline(int argc, wchar_t* argv[])
|
|||
case L'n':
|
||||
bDoShowNumbers = TRUE;
|
||||
break;
|
||||
case L'o':
|
||||
bDoShowProcessId = TRUE;
|
||||
break;
|
||||
case L'p':
|
||||
bDoShowProtoCons = TRUE;
|
||||
if (i+1 >= argc)
|
||||
{
|
||||
DisplayTableHeader();
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
Proto = argv[i+1];
|
||||
if (!_wcsicmp(L"IP", Proto))
|
||||
Protocol = IP;
|
||||
|
@ -108,10 +123,7 @@ BOOL ParseCmdline(int argc, wchar_t* argv[])
|
|||
else if (!_wcsicmp(L"UDP", Proto))
|
||||
Protocol = UDP;
|
||||
else
|
||||
{
|
||||
ConResPuts(StdOut, IDS_USAGE);
|
||||
return FALSE;
|
||||
}
|
||||
goto StopParsingAndShowUsageHelp;
|
||||
break;
|
||||
case L'r':
|
||||
bDoShowRouteTable = TRUE;
|
||||
|
@ -119,15 +131,11 @@ BOOL ParseCmdline(int argc, wchar_t* argv[])
|
|||
case L's':
|
||||
bDoShowProtoStats = TRUE;
|
||||
break;
|
||||
case L'o':
|
||||
bDoShowProcessId = TRUE;
|
||||
break;
|
||||
case L'v':
|
||||
// FIXME!
|
||||
ConPuts(StdOut, L"got v\n");
|
||||
bDoDispSeqComp = TRUE;
|
||||
break;
|
||||
default:
|
||||
StopParsingAndShowUsageHelp:
|
||||
ConResPuts(StdOut, IDS_USAGE);
|
||||
return FALSE;
|
||||
}
|
||||
|
@ -140,28 +148,11 @@ BOOL ParseCmdline(int argc, wchar_t* argv[])
|
|||
else
|
||||
return FALSE;
|
||||
}
|
||||
// else
|
||||
// {
|
||||
// ConResPrintf(StdOut, IDS_USAGE);
|
||||
// return FALSE;
|
||||
// }
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/*
|
||||
* Display table header
|
||||
*/
|
||||
VOID DisplayTableHeader(VOID)
|
||||
{
|
||||
ConResPuts(StdOut, IDS_DISPLAY_THEADER);
|
||||
if (bDoShowProcessId)
|
||||
ConResPuts(StdOut, IDS_DISPLAY_PROCESS);
|
||||
else
|
||||
ConPuts(StdOut, L"\n");
|
||||
}
|
||||
|
||||
/*
|
||||
* Simulate Microsofts netstat utility output
|
||||
*/
|
||||
|
@ -204,13 +195,11 @@ BOOL DisplayOutput(VOID)
|
|||
case TCP:
|
||||
if (bDoShowProtoStats)
|
||||
ShowTcpStatistics();
|
||||
ConResPuts(StdOut, IDS_ACTIVE_CONNECT);
|
||||
DisplayTableHeader();
|
||||
return ShowTcpTable();
|
||||
case UDP:
|
||||
if (bDoShowProtoStats)
|
||||
ShowUdpStatistics();
|
||||
ConResPuts(StdOut, IDS_ACTIVE_CONNECT);
|
||||
DisplayTableHeader();
|
||||
return (bDoShowAllCons ? ShowUdpTable() : TRUE);
|
||||
default:
|
||||
|
@ -227,7 +216,6 @@ BOOL DisplayOutput(VOID)
|
|||
}
|
||||
else
|
||||
{
|
||||
ConResPuts(StdOut, IDS_ACTIVE_CONNECT);
|
||||
DisplayTableHeader();
|
||||
if (ShowTcpTable() && bDoShowAllCons)
|
||||
ShowUdpTable();
|
||||
|
@ -316,7 +304,6 @@ VOID ShowIcmpStatistics(VOID)
|
|||
}
|
||||
|
||||
HeapFree(GetProcessHeap(), 0, pIcmpStats);
|
||||
|
||||
}
|
||||
|
||||
VOID ShowTcpStatistics(VOID)
|
||||
|
@ -504,7 +491,6 @@ BOOL ShowUdpTable(VOID)
|
|||
/* Dump the UDP table */
|
||||
for (i = 0; i < udpTable->dwNumEntries; i++)
|
||||
{
|
||||
|
||||
/* I've split this up so it's easier to follow */
|
||||
GetIpHostName(TRUE, udpTable->table[i].dwLocalAddr, HostIp, sizeof(HostIp));
|
||||
GetPortName(udpTable->table[i].dwLocalPort, "udp", HostPort, sizeof(HostPort));
|
||||
|
@ -602,10 +588,8 @@ GetIpHostName(BOOL Local, UINT IpAddr, CHAR Name[], INT NameLen)
|
|||
}
|
||||
|
||||
/*
|
||||
*
|
||||
* Parse command line parameters and set any options
|
||||
* Run display output, looping over set intervals if a number is given
|
||||
*
|
||||
* Run display output, looping over set interval if a number is given
|
||||
*/
|
||||
int wmain(int argc, wchar_t *argv[])
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue