cleanup util.cs get dns

0.9.0-post-fixes
UbitUmarov 2017-05-29 02:07:53 +01:00
parent 6d23e0bc31
commit 2c19d08448
2 changed files with 87 additions and 84 deletions

View File

@ -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
/// <returns>An IP address, or null</returns>
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)

View File

@ -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);