https://git.reactos.org/?p=reactos.git;a=commitdiff;h=411504b5f4a56443233c8acc9247851448dcf544

commit 411504b5f4a56443233c8acc9247851448dcf544
Author:     Pierre Schweitzer <[email protected]>
AuthorDate: Sat Nov 24 20:22:00 2018 +0100
Commit:     Pierre Schweitzer <[email protected]>
CommitDate: Sat Nov 24 21:41:09 2018 +0100

    [TCPIP] Implement enumerating TCP connections with owner PID
---
 drivers/network/tcpip/include/info.h |  3 ++-
 drivers/network/tcpip/tcpip/info.c   | 17 +++++++++++------
 drivers/network/tcpip/tcpip/ninfo.c  | 23 +++++++++++++++++------
 3 files changed, 30 insertions(+), 13 deletions(-)

diff --git a/drivers/network/tcpip/include/info.h 
b/drivers/network/tcpip/include/info.h
index 8c1625d5af..c0998db479 100644
--- a/drivers/network/tcpip/include/info.h
+++ b/drivers/network/tcpip/include/info.h
@@ -116,7 +116,8 @@ TDI_STATUS InfoTdiQueryGetRouteTable( PIP_INTERFACE IF,
 
 TDI_STATUS InfoTdiQueryGetConnectionTcpTable( PADDRESS_FILE AddrFile,
                                               PNDIS_BUFFER Buffer,
-                                              PUINT BufferSize);
+                                              PUINT BufferSize,
+                                              BOOLEAN Extended);
 
 TDI_STATUS InfoTdiQueryGetConnectionUdpTable( PADDRESS_FILE AddrFile,
                                               PNDIS_BUFFER Buffer,
diff --git a/drivers/network/tcpip/tcpip/info.c 
b/drivers/network/tcpip/tcpip/info.c
index e642bf1dc1..e29d415a7a 100644
--- a/drivers/network/tcpip/tcpip/info.c
+++ b/drivers/network/tcpip/tcpip/info.c
@@ -260,14 +260,19 @@ TDI_STATUS InfoTdiQueryInformationEx(
                      return TDI_INVALID_PARAMETER;
 
               case IP_MIB_ADDRTABLE_ENTRY_ID:
-                 if (ID->toi_entity.tei_entity != CL_NL_ENTITY && 
-                     ID->toi_entity.tei_entity != CO_NL_ENTITY)
-                     return TDI_INVALID_PARAMETER;
-
                  if (ID->toi_type != INFO_TYPE_PROVIDER)
                      return TDI_INVALID_PARAMETER;
 
-                 return InfoTdiQueryGetAddrTable(ID->toi_entity, Buffer, 
BufferSize);
+                 if (ID->toi_entity.tei_entity == CL_NL_ENTITY ||
+                     ID->toi_entity.tei_entity == CO_NL_ENTITY)
+                    return InfoTdiQueryGetAddrTable(ID->toi_entity, Buffer, 
BufferSize);
+                else if (ID->toi_entity.tei_entity == CO_TL_ENTITY)
+                     if ((EntityListContext = GetContext(ID->toi_entity)))
+                         return 
InfoTdiQueryGetConnectionTcpTable(EntityListContext, Buffer, BufferSize, TRUE);
+                     else
+                         return TDI_INVALID_PARAMETER;
+                else
+                    return TDI_INVALID_PARAMETER;
 
               case IP_MIB_ARPTABLE_ENTRY_ID:
                  if (ID->toi_type != INFO_TYPE_PROVIDER)
@@ -287,7 +292,7 @@ TDI_STATUS InfoTdiQueryInformationEx(
                          return TDI_INVALID_PARAMETER;
                  else if (ID->toi_entity.tei_entity == CO_TL_ENTITY)
                      if ((EntityListContext = GetContext(ID->toi_entity)))
-                         return 
InfoTdiQueryGetConnectionTcpTable(EntityListContext, Buffer, BufferSize);
+                         return 
InfoTdiQueryGetConnectionTcpTable(EntityListContext, Buffer, BufferSize, FALSE);
                      else
                          return TDI_INVALID_PARAMETER;
                  else if (ID->toi_entity.tei_entity == CL_TL_ENTITY)
diff --git a/drivers/network/tcpip/tcpip/ninfo.c 
b/drivers/network/tcpip/tcpip/ninfo.c
index d45b4bb1e5..63d1d124c4 100644
--- a/drivers/network/tcpip/tcpip/ninfo.c
+++ b/drivers/network/tcpip/tcpip/ninfo.c
@@ -181,15 +181,26 @@ TDI_STATUS InfoTdiQueryGetIPSnmpInfo( TDIEntityID ID,
 
 TDI_STATUS InfoTdiQueryGetConnectionTcpTable(PADDRESS_FILE AddrFile,
                                    PNDIS_BUFFER Buffer,
-                                   PUINT BufferSize)
+                                   PUINT BufferSize,
+                    BOOLEAN Extended)
 {
-    MIB_TCPROW TcpRow;
+    SIZE_T Size;
+    MIB_TCPROW_OWNER_PID TcpRow;
     TDI_STATUS Status = TDI_SUCCESS;
 
     TI_DbgPrint(DEBUG_INFO, ("Called.\n"));
 
     TcpRow.dwLocalAddr = AddrFile->Address.Address.IPv4Address;
     TcpRow.dwLocalPort = AddrFile->Port;
+    TcpRow.dwOwningPid = (DWORD)AddrFile->ProcessId;
+    if (Extended)
+    {
+        Size = sizeof(MIB_TCPROW_OWNER_PID);
+    }
+    else
+    {
+        Size = sizeof(MIB_TCPROW);
+    }
 
     if (AddrFile->Listener != NULL)
     {
@@ -197,7 +208,7 @@ TDI_STATUS InfoTdiQueryGetConnectionTcpTable(PADDRESS_FILE 
AddrFile,
 
         EndPoint = AddrFile->Listener->AddressFile;
 
-        TcpRow.State = MIB_TCP_STATE_LISTEN;
+        TcpRow.dwState = MIB_TCP_STATE_LISTEN;
         TcpRow.dwRemoteAddr = EndPoint->Address.Address.IPv4Address;
         TcpRow.dwRemotePort = EndPoint->Port;
     }
@@ -215,19 +226,19 @@ TDI_STATUS 
InfoTdiQueryGetConnectionTcpTable(PADDRESS_FILE AddrFile,
             TcpRow.dwRemotePort = 
ntohs(EndPoint.Address[0].Address[0].sin_port);
         }
 
-        Status = TCPGetSocketStatus(AddrFile->Connection, 
(PULONG)&TcpRow.State);
+        Status = TCPGetSocketStatus(AddrFile->Connection, &TcpRow.dwState);
         ASSERT(NT_SUCCESS(Status));
     }
     else
     {
-        TcpRow.State = 0;
+        TcpRow.dwState = 0;
         TcpRow.dwRemoteAddr = 0;
         TcpRow.dwRemotePort = 0;
     }
 
     if (NT_SUCCESS(Status))
     {
-        Status = InfoCopyOut( (PCHAR)&TcpRow, sizeof(TcpRow),
+        Status = InfoCopyOut( (PCHAR)&TcpRow, Size,
                               Buffer, BufferSize );
     }
 

Reply via email to