Esempio n. 1
0
        override public void Bind(SocketBase socket)
        {
            CheckDisposed();
            SetProgress(true);
            try
            {
                //-----------------------------------------
                // Get end point for the proxy server
                //
                IPHostEntry host = GetHostByName(_proxyServer);
                if (host == null)
                {
                    throw new SocketException(SockErrors.WSAHOST_NOT_FOUND);
                }

                // throw new HostNotFoundException("Unable to resolve proxy host name.");

                IPEndPoint proxyEndPoint = ConstructEndPoint(host, _proxyPort);

                //-----------------------------------------
                // Connect to proxy server
                //
                _socket.Connect(proxyEndPoint);

                //-----------------------------------------
                // Send BIND command
                //
                byte[] cmd = PrepareBindCmd((Socket_Socks4a)socket);
                NStream.Write(cmd, 0, cmd.Length);

                //-----------------------------------------
                // Read the response from the proxy server.
                //
                int read = 0;
                while (read < 8)
                {
                    read += NStream.Read(
                        _response,
                        read,
                        _response.Length - read);
                }

                VerifyResponse();
                _localEndPoint = ConstructBindEndPoint(proxyEndPoint.Address);

                // remote end point doesn't provided for BIND command
                _remoteEndPoint = null;
            }
            finally
            {
                SetProgress(false);
            }
        }
Esempio n. 2
0
        override internal void Connect(EndPoint remoteEP)
        {
            CheckDisposed();
            SetProgress(true);
            try
            {
                //------------------------------------
                // Get end point for the proxy server
                //
                IPHostEntry proxyEntry = GetHostByName(_proxyServer);
                if (null == proxyEntry)
                {
                    // throw new HostNotFoundException("Unable to resolve proxy name.");
                    throw new SocketException(SockErrors.WSAHOST_NOT_FOUND);
                }

                IPEndPoint proxyEndPoint = ConstructEndPoint(proxyEntry, _proxyPort);

                //------------------------------------------
                // Connect to proxy server
                //
                _socket.Connect(proxyEndPoint);

                _localEndPoint  = null; // CONNECT command doesn't provide us with local end point
                _remoteEndPoint = remoteEP;

                //------------------------------------------
                // Send CONNECT command
                //
                byte[] cmd = PrepareConnectCmd(remoteEP);
                NStream.Write(cmd, 0, cmd.Length);

                //------------------------------------------
                // Read the response from proxy the server.
                //
                int read = 0;
                while (read < 8)
                {
                    read += NStream.Read(
                        _response,
                        read,
                        _response.Length - read);
                }

                VerifyResponse();
            }
            finally
            {
                SetProgress(false);
            }
        }
Esempio n. 3
0
        override internal SocketBase Accept()
        {
            CheckDisposed();
            SetProgress(true);
            try
            {
                int read = 0;
                while (read < 8)
                {
                    read += NStream.Read(_response,
                                         read,
                                         _response.Length - read);
                }

                VerifyResponse();
            }
            finally
            {
                SetProgress(false);
            }
            return(this);
        }
Esempio n. 4
0
        void Connect(EndPoint remoteEP, string hostName, int port)
        {
            CheckDisposed();
            SetProgress(true);
            try
            {
                if (null == remoteEP)
                {
                    if (_resolveHostEnabled)
                    {
                        IPHostEntry host = GetHostByName(hostName);
                        if (null != host)
                        {
                            remoteEP = ConstructEndPoint(host, port);
                        }
                    }

                    if ((null == hostName) && (null == remoteEP))
                    {
                        throw new ArgumentNullException("hostName", "The value cannot be null.");
                    }
                }

                //------------------------------------
                // Get end point for the proxy server
                //
                IPHostEntry proxyEntry = GetHostByName(_proxyServer);
                if (null == proxyEntry)
                {
                    throw new SocketException(SockErrors.WSAHOST_NOT_FOUND);
                }
                //throw new HostNotFoundException("Unable to resolve proxy name.");

                IPEndPoint proxyEndPoint = ConstructEndPoint(proxyEntry, _proxyPort);

                //------------------------------------------
                // Connect to proxy server
                //
                _socket.Connect(proxyEndPoint);

                _localEndPoint  = null; //CONNECT command doesn't provide us with local end point
                _remoteEndPoint = remoteEP;

                //------------------------------------------
                // Send CONNECT command
                //
                byte[] cmd = PrepareConnectCmd(remoteEP, hostName, port);
                NStream.Write(cmd, 0, cmd.Length);

                //------------------------------------------
                // Read the response from proxy the server.
                //
                int read = 0;
                while (read < 8)
                {
                    read += NStream.Read(_response,
                                         read,
                                         _response.Length - read);
                }

                VerifyResponse();

                //---------------------------------------
                //I we unable to resolve remote host then
                //store information - it will required
                //later for BIND command.
                if (null == remoteEP)
                {
                    _remotePort = port;
                    _remoteHost = hostName;
                }
            }
            finally
            {
                SetProgress(false);
            }
        }