https://git.reactos.org/?p=reactos.git;a=commitdiff;h=29c883e2a5595228a7773…
commit 29c883e2a5595228a7773912df1006ddd2504de6
Author: Pierre Schweitzer <pierre(a)reactos.org>
AuthorDate: Sat Nov 24 21:36:00 2018 +0100
Commit: Pierre Schweitzer <pierre(a)reactos.org>
CommitDate: Sat Nov 24 21:41:11 2018 +0100
[NETSTAT] Add support for displaying UDP connections owning process
Our netstat can basically look like this now:
https://twitter.com/HeisSpiter/status/1066430887208919040
---
base/applications/network/netstat/netstat.c | 20 +++++++++++++++-----
1 file changed, 15 insertions(+), 5 deletions(-)
diff --git a/base/applications/network/netstat/netstat.c
b/base/applications/network/netstat/netstat.c
index 6695777d62..aedbf5336e 100644
--- a/base/applications/network/netstat/netstat.c
+++ b/base/applications/network/netstat/netstat.c
@@ -496,23 +496,24 @@ VOID ShowTcpTable()
VOID ShowUdpTable()
{
- PMIB_UDPTABLE udpTable;
+ PMIB_UDPTABLE_OWNER_PID udpTable;
DWORD error, dwSize;
DWORD i;
CHAR HostIp[HOSTNAMELEN], HostPort[PORTNAMELEN];
CHAR Host[ADDRESSLEN];
+ CHAR PID[64];
/* Get the table of UDP endpoints */
dwSize = 0;
- error = GetUdpTable(NULL, &dwSize, TRUE);
+ error = GetExtendedUdpTable(NULL, &dwSize, TRUE, AF_INET, UDP_TABLE_OWNER_PID,
0);
if (error != ERROR_INSUFFICIENT_BUFFER)
{
printf("Failed to snapshot UDP endpoints.\n");
DoFormatMessage(error);
exit(EXIT_FAILURE);
}
- udpTable = (PMIB_UDPTABLE) HeapAlloc(GetProcessHeap(), 0, dwSize);
- error = GetUdpTable(udpTable, &dwSize, TRUE);
+ udpTable = (PMIB_UDPTABLE_OWNER_PID) HeapAlloc(GetProcessHeap(), 0, dwSize);
+ error = GetExtendedUdpTable(udpTable, &dwSize, TRUE, AF_INET,
UDP_TABLE_OWNER_PID, 0);
if (error)
{
printf("Failed to snapshot UDP endpoints table.\n");
@@ -531,7 +532,16 @@ VOID ShowUdpTable()
sprintf(Host, "%s:%s", HostIp, HostPort);
- _tprintf(_T(" %-6s %-22s %-22s\n"), _T("UDP"), Host,
_T("*:*"));
+ if (bDoShowProcessId)
+ {
+ sprintf(PID, "%ld", udpTable->table[i].dwOwningPid);
+ }
+ else
+ {
+ PID[0] = 0;
+ }
+
+ _tprintf(_T(" %-6s %-22s %-34s %s\n"), _T("UDP"), Host,
_T("*:*"), PID);
}
HeapFree(GetProcessHeap(), 0, udpTable);