* Added "GetHostFromDNS" to Util to replace the various DNS resolution methods we use. Favours IPv4 addresses before IPv6 addresses to work around the Vista preference issue.

afrisby
Adam Frisby 2007-07-18 21:55:24 +00:00
parent 4c8b8d22ff
commit 11efebd29e
3 changed files with 27 additions and 2 deletions

View File

@ -212,7 +212,7 @@ namespace OpenSim.Framework.Types
string internalAddress = GetString(configData, "InternalIPAddress", "0.0.0.0", "Internal IP Address for UDP client connections").ToString(); string internalAddress = GetString(configData, "InternalIPAddress", "0.0.0.0", "Internal IP Address for UDP client connections").ToString();
int internalPort = GetIPPort(configData, "InternalIPPort", "9000", "Internal IP Port for UDP client connections"); int internalPort = GetIPPort(configData, "InternalIPPort", "9000", "Internal IP Port for UDP client connections");
IPAddress internalIPAddress = Dns.GetHostByName(internalAddress).AddressList[0]; IPAddress internalIPAddress = Util.GetHostFromDNS(internalAddress);
m_internalEndPoint = new IPEndPoint(internalIPAddress, internalPort); m_internalEndPoint = new IPEndPoint(internalIPAddress, internalPort);
m_externalHostName = GetString(configData, "ExternalHostName", "127.0.0.1", "External Host Name"); m_externalHostName = GetString(configData, "ExternalHostName", "127.0.0.1", "External Host Name");

View File

@ -27,6 +27,7 @@
*/ */
using System; using System;
using System.Security.Cryptography; using System.Security.Cryptography;
using System.Net;
using System.Text; using System.Text;
using libsecondlife; using libsecondlife;
@ -176,6 +177,30 @@ namespace OpenSim.Framework.Utilities
return output.ToString(); return output.ToString();
} }
/// <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>
public static IPAddress GetHostFromDNS(string dnsAddress)
{
IPAddress[] hosts = Dns.GetHostEntry(dnsAddress).AddressList;
foreach (IPAddress host in hosts)
{
if (host.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
{
return host;
}
}
if (hosts.Length > 0)
return hosts[0];
return null;
}
public Util() public Util()
{ {

View File

@ -60,7 +60,7 @@ namespace OpenSim.Grid.UserServer
// Destination // Destination
Console.WriteLine("CUSTOMISERESPONSE: Region X: " + SimInfo.regionLocX + "; Region Y: " + SimInfo.regionLocY); Console.WriteLine("CUSTOMISERESPONSE: Region X: " + SimInfo.regionLocX + "; Region Y: " + SimInfo.regionLocY);
response.SimAddress = Dns.GetHostByName(SimInfo.serverIP).AddressList[0].ToString(); response.SimAddress = Util.GetHostFromDNS(SimInfo.serverIP).ToString();
response.SimPort = (Int32)SimInfo.serverPort; response.SimPort = (Int32)SimInfo.serverPort;
response.RegionX = SimInfo.regionLocX; response.RegionX = SimInfo.regionLocX;
response.RegionY = SimInfo.regionLocY; response.RegionY = SimInfo.regionLocY;