Пример #1
0
        public Socket Accept()
        {
            byte[] response = new byte[262];

            if (_socket.Receive(response) < 10)
            {
                throw new SocksClientException("The connection was reset by the remote peer.");
            }

            if (response[0] != SocksClient.SOCKS_VERSION)
            {
                throw new SocksClientException("Socks version 5 is not supported by the proxy server.");
            }

            SocksReplyCode reply = (SocksReplyCode)response[1];

            if (reply != SocksReplyCode.Succeeded)
            {
                throw new SocksClientException("Socks proxy server request failed: " + reply.ToString());
            }

            _dstEP = SocksClient.ParseEndpoint(response, 3);

            return(_socket);
        }
Пример #2
0
        public Socket Accept()
        {
            byte[] response = new byte[262];

            if (_socket.Receive(response) < 10)
            {
                throw new SocksClientException("Invalid response received from proxy server");
            }

            if (response[0] != SocksClient.SOCKS_VERSION)
            {
                throw new SocksClientException("Socks version 5 is not supported by the proxy server.");
            }

            SocksReplyCode reply = (SocksReplyCode)response[1];

            if (reply != SocksReplyCode.Succeeded)
            {
                throw new SocksClientException("Socks proxy server request failed: " + reply.ToString());
            }

            _dstEP = new SocksEndPoint(response, 3);

            return(_socket);
        }
Пример #3
0
        private static EndPoint Request(Socket socket, SocksRequestCommand command, EndPoint dstAddr)
        {
            socket.Send(CreateRequest(command, dstAddr));

            byte[] response = new byte[262];

            if (socket.Receive(response) < 10)
            {
                throw new SocksClientException("The connection was reset by the remote peer.");
            }

            if (response[0] != SOCKS_VERSION)
            {
                throw new SocksClientException("Socks version 5 is not supported by the proxy server.");
            }

            SocksReplyCode replyCode = (SocksReplyCode)response[1];

            if (replyCode != SocksReplyCode.Succeeded)
            {
                throw new SocksClientException("Socks proxy server request failed: " + replyCode.ToString(), replyCode);
            }

            return(ParseEndpoint(response, 3));
        }
Пример #4
0
        private SocksEndPoint Request(Socket socket, SocksRequestCommand command, SocksEndPoint dstAddr)
        {
            socket.Send(dstAddr.CreateRequest(command));

            byte[] response = new byte[262];

            if (socket.Receive(response) < 10)
            {
                throw new SocksClientException("Invalid response received from proxy server.");
            }

            if (response[0] != SOCKS_VERSION)
            {
                throw new SocksClientException("Socks version 5 is not supported by the proxy server.");
            }

            SocksReplyCode reply = (SocksReplyCode)response[1];

            if (reply != SocksReplyCode.Succeeded)
            {
                throw new SocksClientException("Socks proxy server request failed: " + reply.ToString());
            }

            return(new SocksEndPoint(response, 3));
        }