Compare commits

...

6 Commits

Author SHA1 Message Date
Joachim Henze
71142b486c [NETSTAT] Whitespace debloat for consistency to other funcs 2023-06-24 01:58:13 +02:00
Joachim Henze
f09d9d9ad1 [NETSTAT] Match Windows exact screen output and ERRORLEVEL like a freak
which means:
ERRORLEVEL 0 for 'netstat -abnop' and displaying Active-string + table header
ERRORLEVEL 1 for 'netstat -abnop bullshit' and displaying usage help
ERRORLEVEL 0 for 'netstat -abnop tcp' and displaying Active-string + table header + contents
ERRORLEVEL 0 for 'netstat -abnop udp' and displaying Active-string + table header + contents
2023-06-24 01:07:32 +02:00
Joachim Henze
c39e0a5be4 [NETSTAT] And the last nitpick, ready 4 review now 2023-06-24 00:20:19 +02:00
Joachim Henze
62ed5f18a3 [NETSTAT] Unrelated formatting nitpicks
Since we do touch the file anyway.
2023-06-24 00:11:27 +02:00
Joachim Henze
5db7c3b5d2 [NETSTAT] Anticipate a formatting nitpick from reviewers
By the way the crash was a regression of
0.4.11-dev-814-g 2b55073360
2023-06-23 23:53:50 +02:00
Joachim Henze
15f9460824 [NETSTAT] Fix crash when parsing the protocol CORE-19005 2023-06-23 23:39:34 +02:00

View File

@@ -1,16 +1,13 @@
/* /*
* PROJECT: ReactOS netstat utility * PROJECT: ReactOS netstat utility
* LICENSE: GPL - See COPYING in the top level directory * LICENSE: GPL - See COPYING in the top level directory
* FILE: base/applications/network/netstat/netstat.c
* PURPOSE: display IP stack statistics * PURPOSE: display IP stack statistics
* COPYRIGHT: Copyright 2005 Ged Murphy <gedmurphy@gmail.com> * COPYRIGHT: Copyright 2005 Ged Murphy <gedmurphy@gmail.com>
*/ */
/* /*
* TODO: * TODO:
* sort function return values.
* implement -b, -t and -v * implement -b, -t and -v
* clean up GetIpHostName * clean up GetIpHostName
* command line parser needs more work
*/ */
#include <stdio.h> #include <stdio.h>
@@ -62,9 +59,19 @@ VOID DoFormatMessage(DWORD ErrorCode)
} }
/* /*
* * Display table header
*/
VOID DisplayTableHeader(VOID)
{
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 * Parse command line parameters and set any options
*
*/ */
BOOL ParseCmdline(int argc, wchar_t* argv[]) BOOL ParseCmdline(int argc, wchar_t* argv[])
{ {
@@ -103,6 +110,13 @@ BOOL ParseCmdline(int argc, wchar_t* argv[])
break; break;
case L'p': case L'p':
bDoShowProtoCons = TRUE; bDoShowProtoCons = TRUE;
if (i+1 >= argc)
{
ConResPuts(StdOut, IDS_ACTIVE_CONNECT);
DisplayTableHeader();
return TRUE;
}
Proto = argv[i+1]; Proto = argv[i+1];
if (!_wcsicmp(L"IP", Proto)) if (!_wcsicmp(L"IP", Proto))
Protocol = IP; Protocol = IP;
@@ -113,10 +127,7 @@ BOOL ParseCmdline(int argc, wchar_t* argv[])
else if (!_wcsicmp(L"UDP", Proto)) else if (!_wcsicmp(L"UDP", Proto))
Protocol = UDP; Protocol = UDP;
else else
{ goto StopParsingAndShowUsageHelp;
ConResPuts(StdErr, IDS_USAGE);
return FALSE;
}
break; break;
case L'r': case L'r':
bDoShowRouteTable = TRUE; bDoShowRouteTable = TRUE;
@@ -134,6 +145,7 @@ BOOL ParseCmdline(int argc, wchar_t* argv[])
bDoDispSeqComp = TRUE; bDoDispSeqComp = TRUE;
break; break;
default: default:
StopParsingAndShowUsageHelp:
ConResPuts(StdErr, IDS_USAGE); ConResPuts(StdErr, IDS_USAGE);
return FALSE; return FALSE;
} }
@@ -146,28 +158,11 @@ BOOL ParseCmdline(int argc, wchar_t* argv[])
else else
return FALSE; return FALSE;
} }
// else
// {
// ConResPrintf(StdErr, IDS_USAGE);
// return FALSE;
// }
} }
return TRUE; 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 * Simulate Microsofts netstat utility output
*/ */
@@ -323,7 +318,6 @@ VOID ShowIcmpStatistics(VOID)
} }
HeapFree(GetProcessHeap(), 0, pIcmpStats); HeapFree(GetProcessHeap(), 0, pIcmpStats);
} }
VOID ShowTcpStatistics(VOID) VOID ShowTcpStatistics(VOID)
@@ -511,7 +505,6 @@ BOOL ShowUdpTable(VOID)
/* Dump the UDP table */ /* Dump the UDP table */
for (i = 0; i < udpTable->dwNumEntries; i++) for (i = 0; i < udpTable->dwNumEntries; i++)
{ {
/* I've split this up so it's easier to follow */ /* I've split this up so it's easier to follow */
GetIpHostName(TRUE, udpTable->table[i].dwLocalAddr, HostIp, sizeof(HostIp)); GetIpHostName(TRUE, udpTable->table[i].dwLocalAddr, HostIp, sizeof(HostIp));
GetPortName(udpTable->table[i].dwLocalPort, "udp", HostPort, sizeof(HostPort)); GetPortName(udpTable->table[i].dwLocalPort, "udp", HostPort, sizeof(HostPort));
@@ -609,10 +602,8 @@ GetIpHostName(BOOL Local, UINT IpAddr, CHAR Name[], INT NameLen)
} }
/* /*
*
* Parse command line parameters and set any options * 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[]) int wmain(int argc, wchar_t *argv[])
{ {