Index: base/applications/network/netstat/netstat.c =================================================================== --- base/applications/network/netstat/netstat.c (revision 42628) +++ base/applications/network/netstat/netstat.c (working copy) @@ -237,12 +237,13 @@ 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,21 +423,22 @@ 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 { - 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 != NO_ERROR ) + HeapFree(GetProcessHeap(), 0, tcpTable); } - tcpTable = (PMIB_TCPTABLE) HeapAlloc(GetProcessHeap(), 0, dwSize); - error = GetTcpTable(tcpTable, &dwSize, TRUE ); - if (error) + while ( error == ERROR_INSUFFICIENT_BUFFER ); + + if (error != NO_ERROR) { - printf("Failed to snapshot TCP endpoints table.\n"); + printf("Failed to snapshot TCP endpoints.\n"); DoFormatMessage(error); - HeapFree(GetProcessHeap(), 0, tcpTable); exit(EXIT_FAILURE); } Index: dll/win32/iphlpapi/iphlpapi_main.c =================================================================== --- dll/win32/iphlpapi/iphlpapi_main.c (revision 42628) +++ dll/win32/iphlpapi/iphlpapi_main.c (working copy) @@ -1707,20 +1707,26 @@ ret = ERROR_INSUFFICIENT_BUFFER; } else { + /* This is wrong currently: + * Following the (msdn) specs pTcpTable should be provided by caller + * and not allocated by getTcpTable() + */ PMIB_TCPTABLE pTcpTable = getTcpTable(); - if (pTcpTable) + if (pTcpTable) { size = sizeof(MIB_TCPTABLE); if (pTcpTable->dwNumEntries > 1) size += (pTcpTable->dwNumEntries - 1) * sizeof(MIB_TCPROW); *pdwSize = size; - if (bOrder) + if (bOrder) qsort(pTcpTable->table, pTcpTable->dwNumEntries, sizeof(MIB_TCPROW), TcpTableSorter); ret = NO_ERROR; - } - } + } + /* This is a stub: */ + ret = ERROR_CALL_NOT_IMPLEMENTED; + } } TRACE("returning %d\n", ret); return ret;