/// <summary> /// Sets the state for a specified TCP connection /// </summary> /// <param name="localAddress">Local IP address for the connection</param> /// <param name="localPort">Local port for the connection</param> /// <param name="remoteAddress">Remote IP address for the connection</param> /// <param name="remotePort">Remote port for the connection</param> /// <param name="newState">New state for the connection</param> public void SetTcpState(IPAddress localAddress, int localPort, IPAddress remoteAddress, int remotePort, TcpState newState) { MIB_TCPROW row = new MIB_TCPROW(); row.dwLocalAddr = BitConverter.ToUInt32(localAddress.GetAddressBytes(), 0); row.dwLocalPort = (uint)localPort; row.dwRemoteAddr = BitConverter.ToUInt32(remoteAddress.GetAddressBytes(), 0); row.dwRemotePort = (uint)remotePort; row.dwState = newState; int errorCode = NativeMethods.SetTcpEntry(ref row); if (errorCode != NativeMethods.NO_ERROR) { throw new NetworkInformationException(errorCode); } }
internal static unsafe extern int SetTcpEntry(ref MIB_TCPROW pTcpRow);