https://git.reactos.org/?p=reactos.git;a=commitdiff;h=dca7e5689ff1f885a67bf9...
commit dca7e5689ff1f885a67bf98058136c1d3c15d7b9 Author: Pierre Schweitzer pierre@reactos.org AuthorDate: Sat Nov 24 20:23:29 2018 +0100 Commit: Pierre Schweitzer pierre@reactos.org CommitDate: Sat Nov 24 21:41:09 2018 +0100
[IPHLPAPI] Implement getOwnerTcpTable(), to get TCP connections with owner PID --- dll/win32/iphlpapi/ipstats_reactos.c | 61 ++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+)
diff --git a/dll/win32/iphlpapi/ipstats_reactos.c b/dll/win32/iphlpapi/ipstats_reactos.c index d8ec38f32b..d117a5f4ce 100644 --- a/dll/win32/iphlpapi/ipstats_reactos.c +++ b/dll/win32/iphlpapi/ipstats_reactos.c @@ -809,3 +809,64 @@ PMIB_TCPTABLE getTcpTable(void)
return IpTcpTable; } + +PMIB_TCPTABLE_OWNER_PID getOwnerTcpTable(void) +{ + DWORD numEntities, returnSize; + TDIEntityID *entitySet; + HANDLE tcpFile; + int i, totalNumber, TmpIdx, CurrIdx = 0; + NTSTATUS status; + PMIB_TCPTABLE_OWNER_PID IpOwnerTcpTable = NULL; + PMIB_TCPROW_OWNER_PID AdapterOwnerTcpTable = NULL; + + TRACE("called.\n"); + + totalNumber = getNumTcpEntries(); + + status = openTcpFile( &tcpFile, FILE_READ_DATA ); + if( !NT_SUCCESS(status) ) { + ERR("openTcpFile returned 0x%08lx\n", status); + return 0; + } + + IpOwnerTcpTable = HeapAlloc + ( GetProcessHeap(), 0, + sizeof(DWORD) + (sizeof(MIB_TCPROW_OWNER_PID) * totalNumber) ); + if (!IpOwnerTcpTable) { + closeTcpFile(tcpFile); + return NULL; + } + + status = tdiGetEntityIDSet( tcpFile, &entitySet, &numEntities ); + + for( i = 0; i < numEntities; i++ ) { + if( entitySet[i].tei_entity == CO_TL_ENTITY && + hasArp( tcpFile, &entitySet[i] ) ) { + + status = tdiGetSetOfThings( tcpFile, + INFO_CLASS_PROTOCOL, + INFO_TYPE_PROVIDER, + IP_MIB_ADDRTABLE_ENTRY_ID, + CO_TL_ENTITY, + entitySet[i].tei_instance, + 0, + sizeof(MIB_TCPROW_OWNER_PID), + (PVOID *)&AdapterOwnerTcpTable, + &returnSize ); + + if( status == STATUS_SUCCESS ) { + for( TmpIdx = 0; TmpIdx < returnSize; TmpIdx++, CurrIdx++ ) + IpOwnerTcpTable->table[CurrIdx] = AdapterOwnerTcpTable[TmpIdx]; + tdiFreeThingSet( AdapterOwnerTcpTable ); + } + } + } + + closeTcpFile( tcpFile ); + + tdiFreeThingSet( entitySet ); + IpOwnerTcpTable->dwNumEntries = CurrIdx; + + return IpOwnerTcpTable; +}