mirror of
https://github.com/reactos/reactos.git
synced 2025-08-04 14:16:53 +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,12 +237,13 @@ BOOL DisplayOutput()
|
|||
ShowUdpStatistics();
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
else //if (bDoShowAllCons)
|
||||
else
|
||||
{
|
||||
_tprintf(_T("\nActive Connections\n"));
|
||||
_tprintf(_T("\n Proto Local Address Foreign Address State\n"));
|
||||
ShowTcpTable();
|
||||
ShowUdpTable();
|
||||
if (bDoShowAllCons)
|
||||
ShowUdpTable();
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
@ -422,23 +423,24 @@ VOID ShowTcpTable()
|
|||
CHAR Remote[ADDRESSLEN];
|
||||
|
||||
/* Get the table of TCP endpoints */
|
||||
dwSize = 0;
|
||||
error = GetTcpTable(NULL, &dwSize, TRUE);
|
||||
if (error != ERROR_INSUFFICIENT_BUFFER)
|
||||
dwSize = sizeof (MIB_TCPTABLE);
|
||||
/* Should also work when we get new connections between 2 GetTcpTable()
|
||||
* 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");
|
||||
DoFormatMessage(error);
|
||||
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 */
|
||||
for (i = 0; i < tcpTable->dwNumEntries; i++)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue