public override void HandleSocksRequest(ISocksClient clientToHandle)
        {
            logger.Trace($"Received new client request from {((IPEndPoint)(clientToHandle.Client.RemoteEndPoint)).Address}");
            var socks4Request = Socks4Request.From(clientToHandle);

            if (socks4Request.Header.RequestType == Socks4RequestType.TcpIpConnection)
            {
                logger.Notice($"Request command is TCP/IP connection to:{socks4Request.IpAddress} on:{socks4Request.Port}");
                var connectionTarget = new IPEndPoint(socks4Request.IpAddress, socks4Request.Port);

                try
                {
                    logger.Notice("Trying to connect");
                    clientToHandle.Connect(connectionTarget);
                }
                catch (SocketException e)
                {
                    logger.Error($"Connection to {socks4Request.IpAddress} on port {socks4Request.Port} thrown an exception:{Environment.NewLine}{e.Message}");
                    CloseConnectionAndSendError(clientToHandle, (uint)SocksCore.Socks4ErrorCodes.Error);
                    return;
                }
            }
            if (socks4Request.Header.RequestType == Socks4RequestType.PortBinding)
            {
                throw new NotImplementedException();
                // TODO: add port binding functionality
            }
            CloseConnectionAndSendError(clientToHandle, (uint)SocksCore.Socks4ErrorCodes.Error);
        }
Пример #2
0
        public static Socks4Request From(IByteReceiver receiver)
        {
            var structSize = Marshal.SizeOf(typeof(Socks4RequestHeader));

            var requestHeader =
                Socks4RequestHeaderFabric.FromHeader(receiver.Receive(structSize));

            var userName = ReadUserName(receiver);

            var socks4Request = new Socks4Request {
                Header = requestHeader, UserName = userName
            };

            return(socks4Request);
        }