From 11efebd29ee264402117f0a98b460b7aff23d369 Mon Sep 17 00:00:00 2001
From: Adam Frisby
Date: Wed, 18 Jul 2007 21:55:24 +0000
Subject: * 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.
---
OpenSim/Framework/General/Types/RegionInfo.cs | 2 +-
OpenSim/Framework/General/Util.cs | 25 +++++++++++++++++++++++++
OpenSim/Grid/UserServer/UserManager.cs | 2 +-
3 files changed, 27 insertions(+), 2 deletions(-)
diff --git a/OpenSim/Framework/General/Types/RegionInfo.cs b/OpenSim/Framework/General/Types/RegionInfo.cs
index c347918..251d7f8 100644
--- a/OpenSim/Framework/General/Types/RegionInfo.cs
+++ b/OpenSim/Framework/General/Types/RegionInfo.cs
@@ -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();
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_externalHostName = GetString(configData, "ExternalHostName", "127.0.0.1", "External Host Name");
diff --git a/OpenSim/Framework/General/Util.cs b/OpenSim/Framework/General/Util.cs
index 3333ced..97fe7da 100644
--- a/OpenSim/Framework/General/Util.cs
+++ b/OpenSim/Framework/General/Util.cs
@@ -27,6 +27,7 @@
*/
using System;
using System.Security.Cryptography;
+using System.Net;
using System.Text;
using libsecondlife;
@@ -176,6 +177,30 @@ namespace OpenSim.Framework.Utilities
return output.ToString();
}
+
+ ///
+ /// Returns a IP address from a specified DNS, favouring IPv4 addresses.
+ ///
+ /// DNS Hostname
+ /// An IP address, or null
+ 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()
{
diff --git a/OpenSim/Grid/UserServer/UserManager.cs b/OpenSim/Grid/UserServer/UserManager.cs
index 74d2248..c459b93 100644
--- a/OpenSim/Grid/UserServer/UserManager.cs
+++ b/OpenSim/Grid/UserServer/UserManager.cs
@@ -60,7 +60,7 @@ namespace OpenSim.Grid.UserServer
// Destination
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.RegionX = SimInfo.regionLocX;
response.RegionY = SimInfo.regionLocY;
--
cgit v1.1