cleanup util.cs get dns
parent
6d23e0bc31
commit
2c19d08448
|
@ -429,64 +429,6 @@ namespace OpenSim.Framework
|
||||||
return regionCoord << 8;
|
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)
|
public static bool checkServiceURI(string uristr, out string serviceURI)
|
||||||
{
|
{
|
||||||
|
@ -1066,39 +1008,100 @@ namespace OpenSim.Framework
|
||||||
/// <returns>An IP address, or null</returns>
|
/// <returns>An IP address, or null</returns>
|
||||||
public static IPAddress GetHostFromDNS(string dnsAddress)
|
public static IPAddress GetHostFromDNS(string dnsAddress)
|
||||||
{
|
{
|
||||||
// Is it already a valid IP? No need to look it up.
|
// If it is already an IP, avoid possible broken mono from seeing it
|
||||||
IPAddress ipa;
|
IPAddress ia = null;
|
||||||
if (IPAddress.TryParse(dnsAddress, out ipa))
|
if (IPAddress.TryParse(dnsAddress, out ia) && ia != null)
|
||||||
return ipa;
|
{
|
||||||
|
if (ia.Equals(IPAddress.Any) || ia.Equals(IPAddress.IPv6Any))
|
||||||
IPAddress[] hosts = null;
|
return null;
|
||||||
|
return ia;
|
||||||
// Not an IP, lookup required
|
}
|
||||||
|
// Reset for next check
|
||||||
|
ia = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
hosts = Dns.GetHostEntry(dnsAddress).AddressList;
|
foreach (IPAddress Adr in Dns.GetHostAddresses(dnsAddress))
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
{
|
||||||
m_log.WarnFormat("[UTIL]: An error occurred while resolving host name {0}, {1}", dnsAddress, e);
|
if (ia == null)
|
||||||
|
ia = Adr;
|
||||||
|
|
||||||
// Still going to throw the exception on for now, since this was what was happening in the first place
|
if (Adr.AddressFamily == AddressFamily.InterNetwork)
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (IPAddress host in hosts)
|
|
||||||
{
|
{
|
||||||
if (host.AddressFamily == AddressFamily.InterNetwork)
|
ia = Adr;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch // (SocketException e)
|
||||||
{
|
{
|
||||||
return host;
|
/*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.
|
||||||
if (hosts.Length > 0)
|
// Reason is, on systems such as OSgrid it has occured that known hostnames stop
|
||||||
return hosts[0];
|
// resolving and thus make surrounding regions crash out with this exception.
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
return ia;
|
||||||
|
}
|
||||||
|
|
||||||
|
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, 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)
|
public static Uri GetURI(string protocol, string hostname, int port, string path)
|
||||||
{
|
{
|
||||||
|
|
|
@ -516,7 +516,7 @@ namespace OpenSim.Region.ClientStack.Linden
|
||||||
if(endPoint == null)
|
if(endPoint == null)
|
||||||
m_log.DebugFormat("EnableSimulator null endpoint");
|
m_log.DebugFormat("EnableSimulator null endpoint");
|
||||||
if(endPoint.Address == null)
|
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);
|
OSD item = EventQueueHelper.EnableSimulator(handle, endPoint, regionSizeX, regionSizeY);
|
||||||
Enqueue(item, avatarID);
|
Enqueue(item, avatarID);
|
||||||
|
|
Loading…
Reference in New Issue