コード例 #1
0
        public static void HandleDoCloseConnection(Client client, DoCloseConnection packet)
        {
            MIB_TCPROW_OWNER_PID[] table = GetTable();
            bool matchFound = false; // handle if connections's ports found

            for (int i = 0; i < table.Length; i++)
            {
                //search for connection by Local and Remote Ports
                if ((packet.LocalPort.ToString() == table[i].LocalPort.ToString()) &&
                    (packet.RemotePort.ToString() == table[i].RemotePort.ToString()))
                // it will close the connection only if client run as admin
                {
                    matchFound = true;
                    //table[i].state = (byte)ConnectionStates.Delete_TCB;
                    table[i].state = 12;  // 12 for Delete_TCB state
                    IntPtr ptr = Marshal.AllocCoTaskMem(Marshal.SizeOf(table[i]));
                    Marshal.StructureToPtr(table[i], ptr, false);
                    int ret = SetTcpEntry(ptr);
                }
            }
            if (matchFound)
            {
                HandleGetConnections(client, new GetConnections());
            }
        }
コード例 #2
0
        public static void HandleDoCloseConnection(Client client, DoCloseConnection packet)
        {
            var table = GetTable();

            for (var i = 0; i < table.Length; i++)
            {
                //search for connection
                if (packet.LocalAddress == table[i].LocalAddress.ToString() &&
                    packet.LocalPort == table[i].LocalPort &&
                    packet.RemoteAddress == table[i].RemoteAddress.ToString() &&
                    packet.RemotePort == table[i].RemotePort)
                {
                    // it will close the connection only if client run as admin
                    //table[i].state = (byte)ConnectionStates.Delete_TCB;
                    table[i].state = 12; // 12 for Delete_TCB state
                    var ptr = Marshal.AllocCoTaskMem(Marshal.SizeOf(table[i]));
                    Marshal.StructureToPtr(table[i], ptr, false);
                    SetTcpEntry(ptr);
                }
            }
        }
コード例 #3
0
        private void Execute(ISender client, DoCloseConnection message)
        {
            var table = GetTable();

            for (var i = 0; i < table.Length; i++)
            {
                //search for connection
                if (message.LocalAddress == table[i].LocalAddress.ToString() &&
                    message.LocalPort == table[i].LocalPort &&
                    message.RemoteAddress == table[i].RemoteAddress.ToString() &&
                    message.RemotePort == table[i].RemotePort)
                {
                    // it will close the connection only if client run as admin
                    //table[i].state = (byte)ConnectionStates.Delete_TCB;
                    table[i].state = 12; // 12 for Delete_TCB state
                    var ptr = Marshal.AllocCoTaskMem(Marshal.SizeOf(table[i]));
                    Marshal.StructureToPtr(table[i], ptr, false);
                    NativeMethods.SetTcpEntry(ptr);
                }
            }
        }
コード例 #4
0
 public static void HandleDoCloseConnection(Client client, DoCloseConnection packet)
 {
     var table = GetTable();
     var matchFound = false; // handle if connections's ports found
     for (var i = 0; i < table.Length; i++)
     {
         //search for connection by Local and Remote Ports
         if ((packet.LocalPort.ToString() == table[i].LocalPort.ToString()) &&
             (packet.RemotePort.ToString() == table[i].RemotePort.ToString()))
             // it will close the connection only if client run as admin
         {
             matchFound = true;
             //table[i].state = (byte)ConnectionStates.Delete_TCB;
             table[i].state = 12; // 12 for Delete_TCB state
             var ptr = Marshal.AllocCoTaskMem(Marshal.SizeOf(table[i]));
             Marshal.StructureToPtr(table[i], ptr, false);
             SetTcpEntry(ptr);
         }
     }
     if (matchFound)
     {
         HandleGetConnections(client, new GetConnections());
     }
 }