mirror of
https://github.com/reactos/reactos.git
synced 2024-12-29 02:25:17 +00:00
[IPHLPAPI] Implement getOwnerTcpTable(), to get TCP connections with owner PID
This commit is contained in:
parent
411504b5f4
commit
dca7e5689f
1 changed files with 61 additions and 0 deletions
|
@ -809,3 +809,64 @@ PMIB_TCPTABLE getTcpTable(void)
|
||||||
|
|
||||||
return IpTcpTable;
|
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;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue