From 2c19d084481e6a710d47ce72c357b1c1a6340531 Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Mon, 29 May 2017 02:07:53 +0100 Subject: [PATCH] cleanup util.cs get dns --- OpenSim/Framework/Util.cs | 169 +++++++++--------- .../Caps/EventQueue/EventQueueGetModule.cs | 2 +- 2 files changed, 87 insertions(+), 84 deletions(-) diff --git a/OpenSim/Framework/Util.cs b/OpenSim/Framework/Util.cs index 83d9df19bb..e3d89dc059 100644 --- a/OpenSim/Framework/Util.cs +++ b/OpenSim/Framework/Util.cs @@ -429,64 +429,6 @@ namespace OpenSim.Framework return regionCoord << 8; } - public static IPEndPoint getEndPoint(IPAddress ia, int port) - { - if(ia == null) - return null; - - IPEndPoint newEP = null; - try - { - newEP = new IPEndPoint(ia, port); - } - catch - { - newEP = null; - } - return newEP; - } - - public static IPEndPoint getEndPoint(string hostname, int port) - { - IPAddress ia = null; - // If it is already an IP, don't resolve it - just return directly - // we should not need this - if (IPAddress.TryParse(hostname, out ia)) - { - if (ia.Equals(IPAddress.Any) || ia.Equals(IPAddress.IPv6Any)) - return null; - return getEndPoint(ia, port); - } - - // Reset for next check - ia = null; - try - { - foreach (IPAddress Adr in Dns.GetHostAddresses(hostname)) - { - if (ia == null) - ia = Adr; - - if (Adr.AddressFamily == AddressFamily.InterNetwork) - { - ia = Adr; - break; - } - } - } - catch // (SocketException e) - { - /*throw new Exception( - "Unable to resolve local hostname " + m_externalHostName + " innerException of type '" + - e + "' attached to this exception", e);*/ - // Don't throw a fatal exception here, instead, return Null and handle it in the caller. - // Reason is, on systems such as OSgrid it has occured that known hostnames stop - // resolving and thus make surrounding regions crash out with this exception. - return null; - } - - return getEndPoint(ia,port); - } public static bool checkServiceURI(string uristr, out string serviceURI) { @@ -1066,38 +1008,99 @@ namespace OpenSim.Framework /// An IP address, or null public static IPAddress GetHostFromDNS(string dnsAddress) { - // Is it already a valid IP? No need to look it up. - IPAddress ipa; - if (IPAddress.TryParse(dnsAddress, out ipa)) - return ipa; - - IPAddress[] hosts = null; - - // Not an IP, lookup required + // If it is already an IP, avoid possible broken mono from seeing it + IPAddress ia = null; + if (IPAddress.TryParse(dnsAddress, out ia) && ia != null) + { + if (ia.Equals(IPAddress.Any) || ia.Equals(IPAddress.IPv6Any)) + return null; + return ia; + } + // Reset for next check + ia = 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); - - // Still going to throw the exception on for now, since this was what was happening in the first place - throw e; - } - - foreach (IPAddress host in hosts) - { - if (host.AddressFamily == AddressFamily.InterNetwork) + foreach (IPAddress Adr in Dns.GetHostAddresses(dnsAddress)) { - return host; + if (ia == null) + ia = Adr; + + if (Adr.AddressFamily == AddressFamily.InterNetwork) + { + ia = Adr; + break; + } } } + catch // (SocketException e) + { + /*throw new Exception( + "Unable to resolve local hostname " + m_externalHostName + " innerException of type '" + + e + "' attached to this exception", e);*/ + // Don't throw a fatal exception here, instead, return Null and handle it in the caller. + // Reason is, on systems such as OSgrid it has occured that known hostnames stop + // resolving and thus make surrounding regions crash out with this exception. + return null; + } + return ia; + } - if (hosts.Length > 0) - return hosts[0]; + public static IPEndPoint getEndPoint(IPAddress ia, int port) + { + if(ia == null) + return null; - return null; + IPEndPoint newEP = null; + try + { + newEP = new IPEndPoint(ia, port); + } + catch + { + newEP = null; + } + return newEP; + } + + public static IPEndPoint getEndPoint(string hostname, int port) + { + IPAddress ia = null; + // If it is already an IP, avoid possible broken mono from seeing it + if (IPAddress.TryParse(hostname, out ia) && ia != null) + { + if (ia.Equals(IPAddress.Any) || ia.Equals(IPAddress.IPv6Any)) + return null; + return getEndPoint(ia, port); + } + + // Reset for next check + ia = null; + try + { + foreach (IPAddress Adr in Dns.GetHostAddresses(hostname)) + { + if (ia == null) + ia = Adr; + + if (Adr.AddressFamily == AddressFamily.InterNetwork) + { + ia = Adr; + break; + } + } + } + catch // (SocketException e) + { + /*throw new Exception( + "Unable to resolve local hostname " + m_externalHostName + " innerException of type '" + + e + "' attached to this exception", e);*/ + // Don't throw a fatal exception here, instead, return Null and handle it in the caller. + // Reason is, on systems such as OSgrid it has occured that known hostnames stop + // resolving and thus make surrounding regions crash out with this exception. + return null; + } + + return getEndPoint(ia,port); } public static Uri GetURI(string protocol, string hostname, int port, string path) diff --git a/OpenSim/Region/ClientStack/Linden/Caps/EventQueue/EventQueueGetModule.cs b/OpenSim/Region/ClientStack/Linden/Caps/EventQueue/EventQueueGetModule.cs index c6499cdbe8..50543269c2 100644 --- a/OpenSim/Region/ClientStack/Linden/Caps/EventQueue/EventQueueGetModule.cs +++ b/OpenSim/Region/ClientStack/Linden/Caps/EventQueue/EventQueueGetModule.cs @@ -516,7 +516,7 @@ namespace OpenSim.Region.ClientStack.Linden if(endPoint == null) m_log.DebugFormat("EnableSimulator null endpoint"); if(endPoint.Address == null) - m_log.DebugFormat("EnableSimulator null endpoint"); + m_log.DebugFormat("EnableSimulator null endpoint address"); OSD item = EventQueueHelper.EnableSimulator(handle, endPoint, regionSizeX, regionSizeY); Enqueue(item, avatarID);