https://git.reactos.org/?p=reactos.git;a=commitdiff;h=559297fe818147587aa00a6062ebf0bee2e091f2

commit 559297fe818147587aa00a6062ebf0bee2e091f2
Author:     Pierre Schweitzer <pie...@reactos.org>
AuthorDate: Tue Nov 27 22:38:21 2018 +0100
Commit:     Pierre Schweitzer <pie...@reactos.org>
CommitDate: Tue Nov 27 23:12:56 2018 +0100

    [IPHLPAPI] Implement getOwnerModUdpTable() and getOwnerModTcpTable()
    
    These allow to enumerate UDP and TCP connections with module information
---
 dll/win32/iphlpapi/ipstats_reactos.c | 122 +++++++++++++++++++++++++++++++++++
 1 file changed, 122 insertions(+)

diff --git a/dll/win32/iphlpapi/ipstats_reactos.c 
b/dll/win32/iphlpapi/ipstats_reactos.c
index 8c1c842c9c..f26c43a4fe 100644
--- a/dll/win32/iphlpapi/ipstats_reactos.c
+++ b/dll/win32/iphlpapi/ipstats_reactos.c
@@ -761,6 +761,67 @@ PMIB_UDPTABLE_OWNER_PID getOwnerUdpTable(void)
     return IpOwnerUdpTable;
 }
 
+PMIB_UDPTABLE_OWNER_MODULE getOwnerModUdpTable(void)
+{
+    DWORD numEntities, returnSize;
+    TDIEntityID *entitySet;
+    HANDLE tcpFile;
+    int i, totalNumber, TmpIdx, CurrIdx = 0;
+    NTSTATUS status;
+    PMIB_UDPTABLE_OWNER_MODULE IpOwnerModUdpTable = NULL;
+    PMIB_UDPROW_OWNER_MODULE AdapterOwnerModUdpTable = NULL;
+
+    TRACE("called.\n");
+
+    totalNumber = getNumUdpEntries();
+
+    status = openTcpFile( &tcpFile, FILE_READ_DATA );
+    if( !NT_SUCCESS(status) ) {
+        ERR("openTcpFile returned 0x%08lx\n", status);
+        return 0;
+    }
+
+    IpOwnerModUdpTable = HeapAlloc
+       ( GetProcessHeap(), 0,
+         sizeof(DWORD) + (sizeof(MIB_UDPROW_OWNER_MODULE) * totalNumber) );
+    if (!IpOwnerModUdpTable) {
+        closeTcpFile(tcpFile);
+        return NULL;
+    }
+
+    status = tdiGetEntityIDSet( tcpFile, &entitySet, &numEntities );
+
+    for( i = 0; i < numEntities; i++ ) {
+        if( entitySet[i].tei_entity == CL_TL_ENTITY &&
+           hasArp( tcpFile, &entitySet[i] ) ) {
+
+           status = tdiGetSetOfThings( tcpFile,
+                                       INFO_CLASS_PROTOCOL,
+                                       INFO_TYPE_PROVIDER,
+                                       IP_SPECIFIC_MODULE_ENTRY_ID,
+                                       CL_TL_ENTITY,
+                                       entitySet[i].tei_instance,
+                                       0,
+                                       sizeof(MIB_UDPROW_OWNER_MODULE),
+                                       (PVOID *)&AdapterOwnerModUdpTable,
+                                       &returnSize );
+
+            if( status == STATUS_SUCCESS ) {
+                for( TmpIdx = 0; TmpIdx < returnSize; TmpIdx++, CurrIdx++ )
+                    IpOwnerModUdpTable->table[CurrIdx] = 
AdapterOwnerModUdpTable[TmpIdx];
+                tdiFreeThingSet( AdapterOwnerModUdpTable );
+            }
+        }
+    }
+
+    closeTcpFile( tcpFile );
+
+    tdiFreeThingSet( entitySet );
+    IpOwnerModUdpTable->dwNumEntries = CurrIdx;
+
+    return IpOwnerModUdpTable;
+}
+
 DWORD getNumTcpEntries(void)
 {
     DWORD numEntities;
@@ -931,3 +992,64 @@ PMIB_TCPTABLE_OWNER_PID getOwnerTcpTable(void)
 
     return IpOwnerTcpTable;
 }
+
+PMIB_TCPTABLE_OWNER_MODULE getOwnerModTcpTable(void)
+{
+    DWORD numEntities, returnSize;
+    TDIEntityID *entitySet;
+    HANDLE tcpFile;
+    int i, totalNumber, TmpIdx, CurrIdx = 0;
+    NTSTATUS status;
+    PMIB_TCPTABLE_OWNER_MODULE IpOwnerModTcpTable = NULL;
+    PMIB_TCPROW_OWNER_MODULE AdapterOwnerModTcpTable = 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;
+    }
+
+    IpOwnerModTcpTable = HeapAlloc
+       ( GetProcessHeap(), 0,
+         sizeof(DWORD) + (sizeof(PMIB_TCPROW_OWNER_MODULE) * totalNumber) );
+    if (!IpOwnerModTcpTable) {
+        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_SPECIFIC_MODULE_ENTRY_ID,
+                                       CO_TL_ENTITY,
+                                       entitySet[i].tei_instance,
+                                       0,
+                                       sizeof(PMIB_TCPROW_OWNER_MODULE),
+                                       (PVOID *)&AdapterOwnerModTcpTable,
+                                       &returnSize );
+
+            if( status == STATUS_SUCCESS ) {
+                for( TmpIdx = 0; TmpIdx < returnSize; TmpIdx++, CurrIdx++ )
+                    IpOwnerModTcpTable->table[CurrIdx] = 
AdapterOwnerModTcpTable[TmpIdx];
+                tdiFreeThingSet( AdapterOwnerModTcpTable );
+            }
+        }
+    }
+
+    closeTcpFile( tcpFile );
+
+    tdiFreeThingSet( entitySet );
+    IpOwnerModTcpTable->dwNumEntries = CurrIdx;
+
+    return IpOwnerModTcpTable;
+}

Reply via email to