예제 #1
0
        /// <summary>
        /// Called when the DNS resolved a host.
        /// </summary>
        /// <param name="ar">The asynchronous result object for the asynchronous method.</param>
        private void OnDnsGetHostEntry(IAsyncResult ar)
        {
            try
            {
                IPHostEntry     entry = Dns.EndGetHostEntry(ar);
                DNSResolveState state = (DNSResolveState)ar.AsyncState;

                base.BeginConnect(new IPEndPoint(entry.AddressList[0], state.Port), OnSocketBeginConnect, state.State);
            }
            catch (Exception exception)
            {
                throw new TorException("The fowarding socket failed to resolve a hostname", exception);
            }
        }
예제 #2
0
        /// <summary>
        /// Begins an asynchronous request to resolve the DNS information for a host.
        /// </summary>
        /// <param name="host">The host address to resolve.</param>
        /// <param name="port">The port number of the associated host.</param>
        /// <returns>An <see cref="T:System.IAsyncResult" /> that references the asynchronous request.</returns>
        private IAsyncResult BeginDNSResolve(string host, int port, AsyncCallback callback, object state)
        {
            DNSResolveState dnsState;

            try
            {
                dnsState          = new DNSResolveState();
                dnsState.Callback = callback;
                dnsState.Host     = host;
                dnsState.Port     = port;
                dnsState.State    = state;

                asyncResult = new Socks5AsyncResult();

                Dns.BeginGetHostEntry(host, OnDnsGetHostEntry, dnsState);

                return(asyncResult);
            }
            catch (Exception exception)
            {
                throw new TorException("The forwarding socket failed to resolve a host address", exception);
            }
        }