System.Net.EndpointPermission.Resolve C# (CSharp) Method

Resolve() private method

private Resolve ( ) : void
return void
        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
            }
        }

Usage Example

Beispiel #1
0
        private string IntersectHostname(EndpointPermission perm)
        {
            if (this.hostname == perm.hostname)
            {
                return(this.hostname);
            }

            this.Resolve();
            perm.Resolve();

            string _hostname = null;

            if (this.hasWildcard)
            {
                if (perm.hasWildcard)
                {
                    _hostname = Intersect(this.hostname, perm.hostname);
                }
                else if (perm.addresses != null)
                {
                    for (int j = 0; j < perm.addresses.Length; j++)
                    {
                        _hostname = Intersect(this.hostname, perm.addresses [j].ToString());
                        if (_hostname != null)
                        {
                            break;
                        }
                    }
                }
            }
            else if (this.addresses != null)
            {
                for (int i = 0; i < this.addresses.Length; i++)
                {
                    string thisaddr = this.addresses [i].ToString();
                    if (perm.hasWildcard)
                    {
                        _hostname = Intersect(thisaddr, perm.hostname);
                    }
                    else if (perm.addresses != null)
                    {
                        for (int j = 0; j < perm.addresses.Length; j++)
                        {
                            _hostname = Intersect(thisaddr, perm.addresses [j].ToString());
                            if (_hostname != null)
                            {
                                break;
                            }
                        }
                    }
                }
            }

            return(_hostname);
        }
All Usage Examples Of System.Net.EndpointPermission::Resolve