ConstructEndPoint() static private method

static private ConstructEndPoint ( IPHostEntry host, int port ) : IPEndPoint
host System.Net.IPHostEntry
port int
return System.Net.IPEndPoint
Exemplo n.º 1
0
        void GetHost_End(IAsyncResult ar)
        {
            Connect_SO stateObj = (Connect_SO)ar.AsyncState;

            try
            {
                stateObj.UpdateContext();
                IPHostEntry host = Dns.EndGetHostByName(ar);
                if (null == host)
                {
                    throw new SocketException(SockErrors.WSAHOST_NOT_FOUND);
                }
                //throw new HostNotFoundException("Unable to resolve host name.");

                EndPoint remoteEP = SocketBase.ConstructEndPoint(host, stateObj.Port);
                _socket.BeginConnect(remoteEP,
                                     new AsyncCallback(Connect_End),
                                     stateObj);
            }
            catch (Exception e)
            {
                stateObj.Exception = e;
                stateObj.SetCompleted();
            }
        }
 internal override void Bind(SocketBase socket)
 {
     base.CheckDisposed();
     this.SetProgress(true);
     try
     {
         IPHostEntry hostByName = SocketBase.GetHostByName(base._proxyServer);
         if (hostByName == null)
         {
             throw new SocketException(0x2af9);
         }
         IPEndPoint remoteEP = SocketBase.ConstructEndPoint(hostByName, base._proxyPort);
         base._socket.Connect(remoteEP);
         this.Negotiate();
         byte[] buffer = this.PrepareBindCmd((Socket_Socks5)socket);
         base.NStream.Write(buffer, 0, buffer.Length);
         byte[] reply = this.ReadVerifyReply();
         this._localEndPoint  = this.ExtractReplyAddr(reply);
         this._remoteEndPoint = null;
     }
     finally
     {
         this.SetProgress(false);
     }
 }
Exemplo n.º 3
0
        void Connect_GetHost_Host_End(IAsyncResult ar)
        {
            Connect_SO stateObj = (Connect_SO)ar.AsyncState;

            try
            {
                stateObj.UpdateContext();
                IPHostEntry host = EndGetHostByName(ar);
                if (null == host)
                {
                    throw new SocketException(SockErrors.WSAHOST_NOT_FOUND);
                }
                //throw new HostNotFoundException("Unable to resolve host name.");

                stateObj.RemoteEndPoint = SocketBase.ConstructEndPoint(host, stateObj.Port);

                //------------------------------------
                // Get end point for the proxy server
                //
                BeginGetHostByName(_proxyServer,
                                   new AsyncCallback(this.Connect_GetHost_Proxy_End),
                                   stateObj);
            }
            catch (Exception e)
            {
                stateObj.Exception = e;
                stateObj.SetCompleted();
            }
        }
 internal override void Bind(SocketBase socket)
 {
     base.CheckDisposed();
     this.SetProgress(true);
     try
     {
         IPHostEntry hostByName = SocketBase.GetHostByName(base._proxyServer);
         if (hostByName == null)
         {
             throw new SocketException(0x2af9);
         }
         IPEndPoint remoteEP = SocketBase.ConstructEndPoint(hostByName, base._proxyPort);
         base._socket.Connect(remoteEP);
         byte[] buffer = this.PrepareBindCmd((Socket_Socks4a)socket);
         base.NStream.Write(buffer, 0, buffer.Length);
         for (int i = 0; i < 8; i += base.NStream.Read(this._response, i, this._response.Length - i))
         {
         }
         this.VerifyResponse();
         this._localEndPoint  = this.ConstructBindEndPoint(remoteEP.Address);
         this._remoteEndPoint = null;
     }
     finally
     {
         this.SetProgress(false);
     }
 }
Exemplo n.º 5
0
        override internal void Connect(EndPoint remoteEP)
        {
            CheckDisposed();
            SetProgress(true);
            try
            {
                //------------------------------------
                // Get end point for the proxy server
                //
                IPHostEntry proxyEntry = GetHostByName(_proxyServer);
                if (null == proxyEntry)
                {
                    //throw new HostNotFoundException("Unable to resolve proxy name.");
                    throw new SocketException(SockErrors.WSAHOST_NOT_FOUND);
                }

                IPEndPoint proxyEndPoint = SocketBase.ConstructEndPoint(proxyEntry, _proxyPort);

                //------------------------------------------
                // Connect to proxy server
                //
                _socket.Connect(proxyEndPoint);

                _localEndPoint  = null;                //CONNECT command doesn't provide us with local end point
                _remoteEndPoint = remoteEP;

                //------------------------------------------
                // Send CONNECT command
                //
                byte[] cmd = PrepareConnectCmd(remoteEP);
                NStream.Write(cmd, 0, cmd.Length);

                //------------------------------------------
                // Read the response from proxy the server.
                //
                int read = 0;
                while (read < 8)
                {
                    read += NStream.Read(_response,
                                         read,
                                         _response.Length - read);
                }

                VerifyResponse();
            }
            finally
            {
                SetProgress(false);
            }
        }
 private void Connect(EndPoint remoteEP, string hostName, int port)
 {
     base.CheckDisposed();
     this.SetProgress(true);
     try
     {
         if (remoteEP == null)
         {
             if (this._resolveHostEnabled)
             {
                 IPHostEntry host = SocketBase.GetHostByName(hostName);
                 if (host != null)
                 {
                     remoteEP = SocketBase.ConstructEndPoint(host, port);
                 }
             }
             if ((hostName == null) && (remoteEP == null))
             {
                 throw new ArgumentNullException("hostName", "The value cannot be null.");
             }
         }
         IPHostEntry hostByName = SocketBase.GetHostByName(base._proxyServer);
         if (hostByName == null)
         {
             throw new SocketException(0x2af9);
         }
         IPEndPoint point = SocketBase.ConstructEndPoint(hostByName, base._proxyPort);
         base._socket.Connect(point);
         this._localEndPoint  = null;
         this._remoteEndPoint = remoteEP;
         byte[] buffer = this.PrepareConnectCmd(remoteEP, hostName, port);
         base.NStream.Write(buffer, 0, buffer.Length);
         for (int i = 0; i < 8; i += base.NStream.Read(this._response, i, this._response.Length - i))
         {
         }
         this.VerifyResponse();
         if (remoteEP == null)
         {
             this._remotePort = port;
             this._remoteHost = hostName;
         }
     }
     finally
     {
         this.SetProgress(false);
     }
 }
Exemplo n.º 7
0
        internal override void Connect(string hostName, int hostPort)
        {
            base.CheckDisposed();
            this.SetProgress(true);
            try
            {
                byte[] buffer;
                if (hostName == null)
                {
                    throw new ArgumentNullException("hostName", "The value cannot be null.");
                }
                if ((hostPort < 0) || (hostPort > 0xffff))
                {
                    throw new ArgumentOutOfRangeException("hostPort", "Value, specified for the port is out of the valid range.");
                }
                IPHostEntry hostByName = SocketBase.GetHostByName(base._proxyServer);
                if (hostByName == null)
                {
                    throw new SocketException(0x2af9);
                }
                IPEndPoint remoteEP = SocketBase.ConstructEndPoint(hostByName, base._proxyPort);
                base._socket.Connect(remoteEP);
                bool preAuthenticate = base.PreAuthenticate;
Label_0076:
                buffer = this.GetConnectCmd(hostName, hostPort, preAuthenticate);
                base.NStream.Write(buffer, 0, buffer.Length);
                ByteVector reply  = this.ReadReply();
                string     reason = null;
                int        num    = this.AnalyzeReply(reply, out reason);
                if ((num < 200) || (num > 0x12b))
                {
                    if (((0x197 != num) || preAuthenticate) || (base._proxyUser == null))
                    {
                        throw new SocketException(0x274d);
                    }
                    preAuthenticate = true;
                    goto Label_0076;
                }
            }
            finally
            {
                this.SetProgress(false);
            }
        }
        private void Connect_GetHost_Host_End(IAsyncResult ar)
        {
            Connect_SO asyncState = (Connect_SO)ar.AsyncState;

            try
            {
                asyncState.UpdateContext();
                IPHostEntry host = SocketBase.EndGetHostByName(ar);
                if (host != null)
                {
                    asyncState.RemoteEndPoint = SocketBase.ConstructEndPoint(host, asyncState.HostPort);
                }
                SocketBase.BeginGetHostByName(base._proxyServer, new AsyncCallback(this.Connect_GetHost_Proxy_End), asyncState);
            }
            catch (Exception exception)
            {
                asyncState.Exception = exception;
                asyncState.SetCompleted();
            }
        }
        private void Connect_GetHost_Proxy_End(IAsyncResult ar)
        {
            Connect_SO asyncState = (Connect_SO)ar.AsyncState;

            try
            {
                asyncState.UpdateContext();
                IPHostEntry host = SocketBase.EndGetHostByName(ar);
                if (host == null)
                {
                    throw new SocketException(0x2af9);
                }
                IPEndPoint remoteEP = SocketBase.ConstructEndPoint(host, base._proxyPort);
                base._socket.BeginConnect(remoteEP, new AsyncCallback(this.Connect_Connect_End), asyncState);
            }
            catch (Exception exception)
            {
                asyncState.Exception = exception;
                asyncState.SetCompleted();
            }
        }