Ejemplo n.º 1
0
 internal void Resolve()
 {
     if (!this.cached && !this.wildcard)
     {
         if (this.IsValidWildcard)
         {
             this.wildcard = true;
             this.cached   = true;
         }
         else
         {
             IPAddress address;
             if (IPAddress.TryParse(this.hostname, out address))
             {
                 this.address = new IPAddress[] { address };
                 this.cached  = true;
             }
             else
             {
                 try
                 {
                     bool        flag;
                     IPHostEntry entry = Dns.InternalResolveFast(this.hostname, -1, out flag);
                     if (entry != null)
                     {
                         this.address = entry.AddressList;
                     }
                 }
                 catch (SecurityException)
                 {
                     throw;
                 }
                 catch
                 {
                 }
             }
         }
     }
 }
        internal void Resolve()
        {
            //
            // if we already resolved this name then don't do it again
            //

            if (cached)
            {
                return;
            }

            //
            // IP wildcards are not resolved
            //

            if (wildcard)
            {
                return;
            }

            //
            // IP addresses with wildcards are allowed in permissions
            //

            if (IsValidWildcard)
            {
                wildcard = true;
                cached   = true;
                return;
            }

            //
            // Check if the permission was specified as numeric IP.
            //
            IPAddress ipaddr;

            if (IPAddress.TryParse(hostname, out ipaddr))
            {
                address    = new IPAddress[1];
                address[0] = ipaddr;
                cached     = true;
                return;
            }

            //
            // Not numeric: use GetHostByName to determine addresses
            //
            try {
                bool        timedOut;
                IPHostEntry ipHostEntry = Dns.InternalResolveFast(hostname, Timeout.Infinite, out timedOut);
                if (ipHostEntry != null)
                {
                    address = ipHostEntry.AddressList;
                }

                // NB: It never caches DNS responses
                //
            }
            catch (SecurityException) {
                throw;
            }
            catch {
                // ignore second exception
            }
        }
        private IPAddress[] GetIPAddressInfoList(out int currentIndex, IPAddress[] addresses, int timeout, out bool timedOut)
        {
            IPHostEntry ipHostEntry = null;

            currentIndex = 0;
            bool flag  = false;
            bool flag2 = false;

            timedOut = false;
            lock (this)
            {
                if (((addresses != null) && !this.m_ConnectedSinceDns) && (!this.m_AddressListFailed && (addresses == this.m_IPAddressInfoList)))
                {
                    return(null);
                }
                if (((this.m_IPAddressInfoList == null) || this.m_AddressListFailed) || ((addresses == this.m_IPAddressInfoList) || this.HasTimedOut))
                {
                    this.m_CurrentAddressInfoIndex = 0;
                    this.m_ConnectedSinceDns       = false;
                    this.m_AddressListFailed       = false;
                    this.m_LastDnsResolve          = DateTime.UtcNow;
                    flag = true;
                }
            }
            if (flag)
            {
                try
                {
                    ipHostEntry = Dns.InternalResolveFast(this.m_Host, timeout, out timedOut);
                    if (timedOut)
                    {
                        flag2 = true;
                    }
                }
                catch (Exception exception)
                {
                    if (NclUtilities.IsFatal(exception))
                    {
                        throw;
                    }
                    flag2 = true;
                }
            }
            lock (this)
            {
                if (flag)
                {
                    this.m_IPAddressInfoList = null;
                    if ((!flag2 && (ipHostEntry != null)) && ((ipHostEntry.AddressList != null) && (ipHostEntry.AddressList.Length > 0)))
                    {
                        this.SetAddressList(ipHostEntry);
                    }
                }
                if ((this.m_IPAddressInfoList != null) && (this.m_IPAddressInfoList.Length > 0))
                {
                    currentIndex = this.m_CurrentAddressInfoIndex;
                    if (ServicePointManager.EnableDnsRoundRobin)
                    {
                        this.m_CurrentAddressInfoIndex++;
                        if (this.m_CurrentAddressInfoIndex >= this.m_IPAddressInfoList.Length)
                        {
                            this.m_CurrentAddressInfoIndex = 0;
                        }
                    }
                    return(this.m_IPAddressInfoList);
                }
            }
            return(null);
        }