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); }
public void AcceptClientConnection(ISocksClient client /*Socket client*/) { var socksVersionFromClientRequest = SocksVersion.Unknown; socksVersionFromClientRequest = FromRequest(client); switch (socksVersionFromClientRequest) { case SocksVersion.Unknown: CloseConnectionAndSendError(client, DefaultSocksError); break; case SocksVersion.Socks4: socks4ClientHandler.HandleSocksRequest(client); break; case SocksVersion.Socks5: socks5ClientHandler.HandleSocksRequest(client); break; default: CloseConnectionAndSendError(client, DefaultSocksError); break; } }
public virtual void CloseConnectionAndSendError(ISocksClient connectionToClose, uint errorCode) { var errorArray = BitConverter.GetBytes(errorCode); try { connectionToClose.Send(errorArray); } finally { connectionToClose.Close(); } }
protected virtual void OnNewSocksClientConnected(ISocksClient e) { NewSocksClientConnected?.Invoke(this, e); }
public void CloseConnectionAndSendError(ISocksClient connectionToClose, uint errorCode) { connectionToClose.Close(); // throw new NotImplementedException(); }
public abstract void HandleSocksRequest(ISocksClient clientToHandle);