opensim/OpenSim/Framework/Util.cs
/// <summary>
/// Returns a IP address from a specified DNS, favouring IPv4 addresses.
/// </summary>
/// <param name="dnsAddress">DNS Hostname</param>
/// <returns>An IP address, or null</returns>
Returns a IP address from a specified DNS, favouring IPv4 addresses.
Returns a IP address from a specified DNS favouring IPv4 addresses .
public static IPAddress GetHostFromDNS(string dnsAddress)
        {
            IPAddress ipa;
            if (IPAddress.TryParse(dnsAddress, out ipa))
                return ipa;
            IPAddress[] hosts = null;
            try
            {
                hosts = Dns.GetHostEntry(dnsAddress).AddressList;
            }
            catch (Exception e)
            {
                m_log.WarnFormat("[UTIL]: An error occurred while resolving host name {0}, {1}", dnsAddress, e);
                throw e;
            }
            foreach (IPAddress host in hosts)
            {
                if (host.AddressFamily == AddressFamily.InterNetwork)
                {
                    return host;
                }
            }
            if (hosts.Length > 0)
                return hosts[0];
            return null;
        }
public static IPAddress GetHostFromDNS ( string dnsAddress ) { IPAddress ipa ; if ( IPAddress . TryParse ( dnsAddress , out ipa ) ) return ipa ; IPAddress [ ] hosts = null ; try { hosts = Dns . GetHostEntry ( dnsAddress ) . AddressList ; } catch ( Exception e ) { m_log . WarnFormat ( " " , dnsAddress , e ) ; throw e ; } foreach ( IPAddress host in hosts ) { if ( host . AddressFamily == AddressFamily . InterNetwork ) { return host ; } } if ( hosts . Length > 0 ) return hosts [ 0 ] ; return null ; }
Returns a IP address from a specified DNS, favouring IPv4 addresses.
Returns a IP address from a specified DNS favouring IPv4 addresses .
// Is it already a valid IP? No need to look it up. // Not an IP, lookup required // Still going to throw the exception on for now, since this was what was happening in the first place
An IP address, or null
An IP address or null
dnsAddress
string
None