mirror of
https://github.com/reactos/reactos.git
synced 2025-08-05 16:52:59 +00:00
[NETSTAT]
- Allocate memory for the TCP table properly - Only netstat -a should show UDP connections - Patch by Jan Roeloffzen [jroeloffzen at hotmail dot com] svn path=/trunk/; revision=48564
This commit is contained in:
parent
f2d4e1a828
commit
44e8a7f7b6
1 changed files with 16 additions and 14 deletions
|
@ -237,11 +237,12 @@ BOOL DisplayOutput()
|
||||||
ShowUdpStatistics();
|
ShowUdpStatistics();
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
else //if (bDoShowAllCons)
|
else
|
||||||
{
|
{
|
||||||
_tprintf(_T("\nActive Connections\n"));
|
_tprintf(_T("\nActive Connections\n"));
|
||||||
_tprintf(_T("\n Proto Local Address Foreign Address State\n"));
|
_tprintf(_T("\n Proto Local Address Foreign Address State\n"));
|
||||||
ShowTcpTable();
|
ShowTcpTable();
|
||||||
|
if (bDoShowAllCons)
|
||||||
ShowUdpTable();
|
ShowUdpTable();
|
||||||
}
|
}
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
|
@ -422,23 +423,24 @@ VOID ShowTcpTable()
|
||||||
CHAR Remote[ADDRESSLEN];
|
CHAR Remote[ADDRESSLEN];
|
||||||
|
|
||||||
/* Get the table of TCP endpoints */
|
/* Get the table of TCP endpoints */
|
||||||
dwSize = 0;
|
dwSize = sizeof (MIB_TCPTABLE);
|
||||||
error = GetTcpTable(NULL, &dwSize, TRUE);
|
/* Should also work when we get new connections between 2 GetTcpTable()
|
||||||
if (error != ERROR_INSUFFICIENT_BUFFER)
|
* calls: */
|
||||||
|
do
|
||||||
|
{
|
||||||
|
tcpTable = (PMIB_TCPTABLE) HeapAlloc(GetProcessHeap(), 0, dwSize);
|
||||||
|
error = GetTcpTable(tcpTable, &dwSize, TRUE);
|
||||||
|
if ( error != NO_ERROR )
|
||||||
|
HeapFree(GetProcessHeap(), 0, tcpTable);
|
||||||
|
}
|
||||||
|
while ( error == ERROR_INSUFFICIENT_BUFFER );
|
||||||
|
|
||||||
|
if (error != NO_ERROR)
|
||||||
{
|
{
|
||||||
printf("Failed to snapshot TCP endpoints.\n");
|
printf("Failed to snapshot TCP endpoints.\n");
|
||||||
DoFormatMessage(error);
|
DoFormatMessage(error);
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
tcpTable = (PMIB_TCPTABLE) HeapAlloc(GetProcessHeap(), 0, dwSize);
|
|
||||||
error = GetTcpTable(tcpTable, &dwSize, TRUE );
|
|
||||||
if (error)
|
|
||||||
{
|
|
||||||
printf("Failed to snapshot TCP endpoints table.\n");
|
|
||||||
DoFormatMessage(error);
|
|
||||||
HeapFree(GetProcessHeap(), 0, tcpTable);
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Dump the TCP table */
|
/* Dump the TCP table */
|
||||||
for (i = 0; i < tcpTable->dwNumEntries; i++)
|
for (i = 0; i < tcpTable->dwNumEntries; i++)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue