public TransparentProxyServer(IPEndPoint localEP, IProxyServerConnectionManager connectionManager = null, TransparentProxyServerMethod method = TransparentProxyServerMethod.DNAT, int backlog = 10)
        {
            if (Environment.OSVersion.Platform != PlatformID.Unix)
            {
                throw new NotSupportedException("Only Unix/Linux is supported.");
            }

            if ((method == TransparentProxyServerMethod.DNAT) && (localEP.AddressFamily != AddressFamily.InterNetwork))
            {
                throw new NotSupportedException("Only IPv4 is supported with DNAT.");
            }

            _listener = new Socket(localEP.AddressFamily, SocketType.Stream, ProtocolType.Tcp);

            if (method == TransparentProxyServerMethod.TPROXY)
            {
                _listener.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, 1);
                _listener.SetRawSocketOption(IPPROTO_IP, IP_TRANSPARENT, new byte[] { 1 });
            }

            _listener.Bind(localEP);
            _listener.Listen(backlog);
            _listener.NoDelay = true;

            _localEP           = (IPEndPoint)_listener.LocalEndPoint;
            _connectionManager = connectionManager;
            _method            = method;

            if (_connectionManager == null)
            {
                _connectionManager = new DefaultProxyServerConnectionManager();
            }

            //accept requests async
            int tasks = Math.Max(1, Environment.ProcessorCount);

            for (int i = 0; i < tasks; i++)
            {
                _ = Task.Factory.StartNew(AcceptRequestAsync, CancellationToken.None, TaskCreationOptions.DenyChildAttach, TaskScheduler.Current);
            }
        }
 public TransparentProxyServer(IProxyServerConnectionManager connectionManager = null, TransparentProxyServerMethod method = TransparentProxyServerMethod.DNAT, int backlog = 10)
     : this(new IPEndPoint(IPAddress.Any, 8081), connectionManager, method, backlog)
 {
 }
 public ProxyServerSession(Socket localSocket, IProxyServerConnectionManager connectionManager, TransparentProxyServerMethod method)
 {
     _localSocket       = localSocket;
     _connectionManager = connectionManager;
     _method            = method;
 }