Esempio n. 1
0
        internal SocksProxyBindHandler(Socket socket, EndPoint bindEP)
        {
            _socket = socket;

            _replyCode = SocksProxyReplyCode.Succeeded;
            _bindEP    = bindEP;
        }
            public BindHandler(IPEndPoint bindEP, byte[] bindToInterfaceName = null)
            {
                switch (bindEP.AddressFamily)
                {
                case AddressFamily.InterNetwork:
                case AddressFamily.InterNetworkV6:
                    _socket = new Socket(bindEP.AddressFamily, SocketType.Stream, ProtocolType.Tcp);

                    if (bindToInterfaceName is not null)
                    {
                        _socket.SetRawSocketOption(SOL_SOCKET, SO_BINDTODEVICE, bindToInterfaceName);
                    }

                    _socket.Bind(bindEP);
                    _socket.Listen(1);
                    _socket.NoDelay = true;

                    _replyCode = SocksProxyReplyCode.Succeeded;
                    _bindEP    = new IPEndPoint(bindEP.Address, (_socket.LocalEndPoint as IPEndPoint).Port);
                    break;

                default:
                    _replyCode = SocksProxyReplyCode.AddressTypeNotSupported;
                    _bindEP    = new IPEndPoint(IPAddress.Any, 0);
                    break;
                }
            }
            public BindHandler(AddressFamily family)
            {
                EndPoint    localEP     = null;
                NetworkInfo networkInfo = null;

                switch (family)
                {
                case AddressFamily.InterNetwork:
                    localEP     = new IPEndPoint(IPAddress.Any, 0);
                    networkInfo = NetUtilities.GetDefaultIPv4NetworkInfo();
                    break;

                case AddressFamily.InterNetworkV6:
                    localEP     = new IPEndPoint(IPAddress.IPv6Any, 0);
                    networkInfo = NetUtilities.GetDefaultIPv6NetworkInfo();
                    break;

                default:
                    _replyCode = SocksProxyReplyCode.AddressTypeNotSupported;
                    _bindEP    = new IPEndPoint(IPAddress.Any, 0);
                    break;
                }

                if (localEP != null)
                {
                    if (networkInfo == null)
                    {
                        _replyCode = SocksProxyReplyCode.NetworkUnreachable;
                        _bindEP    = new IPEndPoint(IPAddress.Any, 0);
                    }
                    else
                    {
                        _socket = new Socket(localEP.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
                        _socket.Bind(localEP);
                        _socket.Listen(1);
                        _socket.NoDelay = true;

                        _replyCode = SocksProxyReplyCode.Succeeded;
                        _bindEP    = new IPEndPoint(networkInfo.LocalIP, (_socket.LocalEndPoint as IPEndPoint).Port);
                    }
                }
            }
            public BindHandler(IPEndPoint bindEP)
            {
                switch (bindEP.AddressFamily)
                {
                case AddressFamily.InterNetwork:
                case AddressFamily.InterNetworkV6:
                    _socket = new Socket(bindEP.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
                    _socket.Bind(bindEP);
                    _socket.Listen(1);
                    _socket.NoDelay = true;

                    _replyCode = SocksProxyReplyCode.Succeeded;
                    _bindEP    = new IPEndPoint(bindEP.Address, (_socket.LocalEndPoint as IPEndPoint).Port);
                    break;

                default:
                    _replyCode = SocksProxyReplyCode.AddressTypeNotSupported;
                    _bindEP    = new IPEndPoint(IPAddress.Any, 0);
                    break;
                }
            }
Esempio n. 5
0
 internal SocksProxyBindHandler(SocksProxyReplyCode replyCode)
 {
     _replyCode = replyCode;
     _bindEP    = new IPEndPoint(IPAddress.Any, 0);
 }
Esempio n. 6
0
 public SocksProxyAuthenticationFailedException(string message, SocksProxyReplyCode replyCode)
     : base(message)
 {
     _replyCode = replyCode;
 }
 public SocksProxyException(string message, SocksProxyReplyCode replyCode)
     : base(message)
 {
     _replyCode = replyCode;
 }
 public SocksProxyReply(SocksProxyReplyCode reply, EndPoint bindEP)
 {
     _version = SOCKS_VERSION;
     _reply   = reply;
     _bindEP  = bindEP;
 }
 public SocksProxyReply(SocksProxyReplyCode reply)
     : this(reply, new IPEndPoint(IPAddress.Any, 0))
 {
 }