Ejemplo n.º 1
0
 private void SetSocketAsConnected()
 {
     try {
         this.socketState = TcpSocketState.Connected;
         this.remoteIP    = ((System.Net.IPEndPoint) this.tcpClient.Client.RemoteEndPoint).Address;
         if (this.useSsl)
         {
             //send test stream with: cat dump.pcap | socat - SSL:localhost:57012,verify=0
             //socat GOPEN:dump.pcap SSL:localhost:57443,verify=0
             System.Net.Security.SslStream sslStream = new System.Net.Security.SslStream(tcpClient.GetStream(), false);
             //sslStream.ReadTimeout = idleTimeoutMS; //8 seconds
             sslStream.AuthenticateAsServer(ServerCert.Instance, false, System.Security.Authentication.SslProtocols.Default, false);
             this.pcapStream = sslStream;
         }
         else
         {
             this.pcapStream = this.tcpClient.GetStream();
         }
         this.pcapStream.ReadTimeout = this.idleTimeoutMS;
         //this.tcpClient.ReceiveTimeout = this.idleTimeoutMS;//not required, we do  stream.ReadTimeout instead
     }
     catch {
         this.Dispose();
     }
 }
Ejemplo n.º 2
0
 public PcapTcpStream(ushort localTcpPort, bool useSsl, int idleTimeoutMilliSeconds) : this(useSsl, idleTimeoutMilliSeconds)
 {
     this.socketState = TcpSocketState.Closed;
     this.tcpListener = new System.Net.Sockets.TcpListener(System.Net.IPAddress.Any, (int)localTcpPort);
     tcpListener.Start();
     this.socketState = TcpSocketState.Listening;
 }
Ejemplo n.º 3
0
 public void Dispose()
 {
     this.socketState = TcpSocketState.Closed;
     if (this.pcapStream != null)
     {
         try {
             this.pcapStream.Close();
         }
         catch { }
         this.pcapStream.Dispose();
     }
     this.pcapStream = null;
     if (this.tcpClient != null)
     {
         this.tcpClient.Close();
     }
     if (this.tcpListener != null)
     {
         try {
             this.tcpListener.Stop();
         }
         catch { }
         //this.tcpListener = null;
     }
 }
Ejemplo n.º 4
0
        public void Connect(IPAddress ipAddress, int port)
        {
            if (socketState != TcpSocketState.Connecting)
            {
                socketState = TcpSocketState.Connecting;
                socket.Connect(ipAddress, port);
                socketState = TcpSocketState.Idle;
                //socket.BeginConnect(ipAddress, port, new AsyncCallback(ConnectCallback), null);

                StartReceivingLoop();
            }
        }
Ejemplo n.º 5
0
 public PcapTcpStream(string remoteIpOrHost, ushort remotePort, bool useSSl, int idleTimeoutMilliSeconds, System.Windows.Forms.MethodInvoker streamEstablishedHandler) : this(useSSl, idleTimeoutMilliSeconds)
 {
     this.tcpClient = new TcpClient(remoteIpOrHost, remotePort);
     if (this.tcpClient.Connected)
     {
         this.SetSocketAsConnected();
         //streamEstablishedHandler. .DynamicInvoke();
     }
     else
     {
         this.socketState = TcpSocketState.Closed;
     }
 }
Ejemplo n.º 6
0
        public void Connect(string ipAddressOrHostname, int port)
        {
            if (socketState == TcpSocketState.Idle)
            {
                // Get host related information.
                IPHostEntry hostEntry = Dns.GetHostEntry(ipAddressOrHostname);

                socketState = TcpSocketState.Connecting;

                // Loop through the AddressList to obtain the supported AddressFamily. This is to avoid
                // an exception that occurs when the host host IP Address is not compatible with the address family
                // (typical in the IPv6 case).
                TryNextTempSocketConnection(hostEntry.AddressList, 0, port);
            }
        }
Ejemplo n.º 7
0
 private void TempSocketConnectComplete()
 {
     socketState = TcpSocketState.Idle;
 }
Ejemplo n.º 8
0
 private void ConnectCallback(IAsyncResult result)
 {
     // We are connected!
     socket.EndConnect(result);
     socketState = TcpSocketState.Idle;
 }
Ejemplo n.º 9
0
        public void Connect(IPAddress ipAddress, int port)
        {
            if (socketState != TcpSocketState.Connecting) {
                socketState = TcpSocketState.Connecting;
                socket.Connect(ipAddress, port);
                socketState = TcpSocketState.Idle;
                //socket.BeginConnect(ipAddress, port, new AsyncCallback(ConnectCallback), null);

                StartReceivingLoop();
            }
        }
Ejemplo n.º 10
0
        public void Connect(string ipAddressOrHostname, int port)
        {
            if (socketState == TcpSocketState.Idle) {
                // Get host related information.
                IPHostEntry hostEntry = Dns.GetHostEntry(ipAddressOrHostname);

                socketState = TcpSocketState.Connecting;

                // Loop through the AddressList to obtain the supported AddressFamily. This is to avoid
                // an exception that occurs when the host host IP Address is not compatible with the address family
                // (typical in the IPv6 case).
                TryNextTempSocketConnection(hostEntry.AddressList, 0, port);
            }
        }
Ejemplo n.º 11
0
 private void ConnectCallback(IAsyncResult result)
 {
     // We are connected!
     socket.EndConnect(result);
     socketState = TcpSocketState.Idle;
 }
Ejemplo n.º 12
0
 private void TempSocketConnectComplete()
 {
     socketState = TcpSocketState.Idle;
 }