public ReceiverController( IEnumerable <IReceiverCommandDefinition> commands, IObservable <IRawResponseData> rawDataObservable, TcpClient tcpClient) : this(commands, rawDataObservable) { _transportLayerType = TransportLayerType.Tcp; _tcpClient = tcpClient; }
public ReceiverController( IEnumerable <IReceiverCommandDefinition> commands, IObservable <IRawResponseData> rawDataObservable, SerialPort serialPort) : this(commands, rawDataObservable) { _transportLayerType = TransportLayerType.SerialPort; _serialPort = serialPort; }
public ReceiverController( IEnumerable <IReceiverCommandDefinition> commands, SerialPort serialPort, int bufferSize) { _listenerObservable = serialPort .ToByteStreamObservable(bufferSize) .ToResponseObservable() .Where(r => r.Data != "R"); _commands = commands; _transportLayerType = TransportLayerType.SerialPort; _serialPort = serialPort; }
public ReceiverController( IEnumerable <IReceiverCommandDefinition> commands, TcpClient tcpClient, IPAddress ipAddress, int port) { _listenerObservable = tcpClient .ToByteStreamObservable(ipAddress, port) .ToResponseObservable() .Where(r => r.Data != "R"); _commands = commands; _transportLayerType = TransportLayerType.Tcp; _tcpClient = tcpClient; }
//******************************************************************************// public static MitmSession CreateMitmSession(Input input, Zitm zit) { TransportLayerType tltype = input.TlType; if (tltype != TransportLayerType.Tcp && tltype != TransportLayerType.Udp) { throw new NotImplementedException(); } string stltype = ""; if (tltype == TransportLayerType.Tcp) { stltype = "tcp"; } if (tltype == TransportLayerType.Udp) { stltype = "udp"; } MitmSession ret = new MitmSession(); ret.tltype = tltype; ret.zit = zit; ret.r_allow = new System.Threading.ManualResetEvent(false); if (tltype == TransportLayerType.Tcp) { ret.client = new IPEndPoint( IPAddress.Parse(input.IPv4_source_ip), input.TCP_source_port); ret.remote = new IPEndPoint( IPAddress.Parse(input.IPv4_destination_ip), input.TCP_destination_port); Socket stcp = new Socket(zit._local.Address.AddressFamily, SocketType.Stream, ProtocolType.Tcp); IPEndPoint ep = new IPEndPoint(zit._local.Address, 0); stcp.Bind(ep); ret.local = new IPEndPoint( zit._local.Address, Common.GetPort(stcp)); ret.binded_socket = stcp; } if (tltype == TransportLayerType.Udp) { ret.client = new IPEndPoint( IPAddress.Parse(input.IPv4_source_ip), input.UDP_source_port); ret.remote = new IPEndPoint( IPAddress.Parse(input.IPv4_destination_ip), input.UDP_destination_port); Socket sudp = new Socket(zit._local.Address.AddressFamily, SocketType.Dgram, ProtocolType.Udp); IPEndPoint ep = new IPEndPoint(zit._local.Address, 0); sudp.Bind(ep); ret.local = new IPEndPoint( zit._local.Address, Common.GetPort(sudp)); ret.binded_socket = sudp; } ret.workSocket = input.workSocket; //***// ret.addr_send = new WinDivertAddress(); ret.addr_send.Reset(); ret.addr_send.Direction = WinDivertDirection.Outbound; ret.addr_recv = new WinDivertAddress(); ret.addr_recv.Reset(); ret.addr_recv.Direction = WinDivertDirection.Outbound; ret.forward_handle = WinDivert.WinDivertOpen("false", WinDivertLayer.Network, 0, WinDivertOpenFlags.None); //***// UInt32 ulocal_ip = Common.IpToUint32(ret.local.Address.ToString()); UInt32 uremote_ip = Common.IpToUint32(ret.remote.Address.ToString()); string filter = "ip.DstAddr == " + ulocal_ip.ToString() + " and ip.SrcAddr == " + uremote_ip.ToString() + " and " + stltype + ".DstPort == " + ret.local.Port.ToString() + " and " + stltype + ".SrcPort == " + ret.remote.Port.ToString(); ret.listener_handle = WinDivert.WinDivertOpen(filter, WinDivertLayer.Network, 0, WinDivertOpenFlags.None); ret.listener_buffer = new WinDivertBuffer(); return(ret); }