mirror of
https://github.com/reactos/reactos.git
synced 2024-10-01 06:57:08 +00:00
[NETSTAT]
- Fix parsing of the -p option and enable / as option indicator. - Display foreign address of a listening TCP port as '<host>:0'. svn path=/trunk/; revision=71095
This commit is contained in:
parent
bb8967851b
commit
57bdb633c8
|
@ -83,20 +83,18 @@ DWORD DoFormatMessage(DWORD ErrorCode)
|
|||
*/
|
||||
BOOL ParseCmdline(int argc, char* argv[])
|
||||
{
|
||||
LPSTR Proto;
|
||||
CHAR c;
|
||||
INT i;
|
||||
|
||||
TCHAR Proto[5];
|
||||
|
||||
if ((argc == 1) || (_istdigit(*argv[1])))
|
||||
bNoOptions = TRUE;
|
||||
|
||||
/* Parse command line for options we have been given. */
|
||||
for (i = 1; i < argc; i++)
|
||||
{
|
||||
if ( (argc > 1)&&(argv[i][0] == '-') )
|
||||
if ((argc > 1) && (argv[i][0] == '-' || argv[i][0] == '/'))
|
||||
{
|
||||
TCHAR c;
|
||||
|
||||
while ((c = *++argv[i]) != '\0')
|
||||
{
|
||||
switch (tolower(c))
|
||||
|
@ -113,31 +111,29 @@ BOOL ParseCmdline(int argc, char* argv[])
|
|||
case 'n' :
|
||||
bDoShowNumbers = TRUE;
|
||||
break;
|
||||
case 's' :
|
||||
bDoShowProtoStats = TRUE;
|
||||
break;
|
||||
case 'p' :
|
||||
bDoShowProtoCons = TRUE;
|
||||
|
||||
strncpy(Proto, (++argv)[i], sizeof(Proto));
|
||||
if (!_tcsicmp( "IP", Proto ))
|
||||
Proto = argv[i+1];
|
||||
if (!_stricmp("IP", Proto))
|
||||
Protocol = IP;
|
||||
else if (!_tcsicmp( "ICMP", Proto ))
|
||||
else if (!_stricmp("ICMP", Proto))
|
||||
Protocol = ICMP;
|
||||
else if (!_tcsicmp( "TCP", Proto ))
|
||||
else if (!_stricmp("TCP", Proto))
|
||||
Protocol = TCP;
|
||||
else if (!_tcsicmp( "UDP", Proto ))
|
||||
else if (!_stricmp("UDP", Proto))
|
||||
Protocol = UDP;
|
||||
else
|
||||
{
|
||||
Usage();
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
--i; /* move pointer back down to previous argv */
|
||||
break;
|
||||
case 'r' :
|
||||
bDoShowRouteTable = TRUE;
|
||||
break;
|
||||
case 's' :
|
||||
bDoShowProtoStats = TRUE;
|
||||
break;
|
||||
case 'v' :
|
||||
_tprintf(_T("got v\n"));
|
||||
bDoDispSeqComp = TRUE;
|
||||
|
@ -452,11 +448,18 @@ VOID ShowTcpTable()
|
|||
/* I've split this up so it's easier to follow */
|
||||
GetIpHostName(TRUE, tcpTable->table[i].dwLocalAddr, HostIp, HOSTNAMELEN);
|
||||
GetPortName(tcpTable->table[i].dwLocalPort, "tcp", HostPort, PORTNAMELEN);
|
||||
sprintf(Host, "%s:%s", HostIp, HostPort);
|
||||
|
||||
if (tcpTable->table[i].dwState == MIB_TCP_STATE_LISTEN)
|
||||
{
|
||||
sprintf(Remote, "%s:0", HostIp);
|
||||
}
|
||||
else
|
||||
{
|
||||
GetIpHostName(FALSE, tcpTable->table[i].dwRemoteAddr, RemoteIp, HOSTNAMELEN);
|
||||
GetPortName(tcpTable->table[i].dwRemotePort, "tcp", RemotePort, PORTNAMELEN);
|
||||
|
||||
sprintf(Host, "%s:%s", HostIp, HostPort);
|
||||
sprintf(Remote, "%s:%s", RemoteIp, RemotePort);
|
||||
}
|
||||
|
||||
_tprintf(_T(" %-6s %-22s %-22s %s\n"), _T("TCP"),
|
||||
Host, Remote, TcpState[tcpTable->table[i].dwState]);
|
||||
|
@ -585,7 +588,7 @@ GetIpHostName(BOOL Local, UINT IpAddr, CHAR Name[], int NameLen)
|
|||
VOID Usage()
|
||||
{
|
||||
_tprintf(_T("\nDisplays current TCP/IP protocol statistics and network connections.\n\n"
|
||||
"NETSTAT [-a] [-e] [-n] [-s] [-p proto] [-r] [interval]\n\n"
|
||||
"NETSTAT [-a] [-e] [-n] [-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"
|
||||
|
|
Loading…
Reference in a new issue