[TCPIP] Implement enumerating TCP connections with owner PID
authorPierre Schweitzer <pierre@reactos.org>
Sat, 24 Nov 2018 19:22:00 +0000 (20:22 +0100)
committerPierre Schweitzer <pierre@reactos.org>
Sat, 24 Nov 2018 20:41:09 +0000 (21:41 +0100)
drivers/network/tcpip/include/info.h
drivers/network/tcpip/tcpip/info.c
drivers/network/tcpip/tcpip/ninfo.c

index 8c1625d..c0998db 100644 (file)
@@ -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,
index e642bf1..e29d415 100644 (file)
@@ -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)
index d45b4bb..63d1d12 100644 (file)
@@ -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 );
     }