diff --git a/OpenSim/Framework/Communications/Tests/LoginServiceTests.cs b/OpenSim/Framework/Communications/Tests/LoginServiceTests.cs index a2a388e9e4..7fda38cf2b 100644 --- a/OpenSim/Framework/Communications/Tests/LoginServiceTests.cs +++ b/OpenSim/Framework/Communications/Tests/LoginServiceTests.cs @@ -103,7 +103,10 @@ namespace OpenSim.Framework.Communications.Tests XmlRpcRequest request = new XmlRpcRequest("login_to_simulator", sendParams); - XmlRpcResponse response = loginService.XmlRpcLoginMethod(request, new IPEndPoint(Util.GetLocalHost(), 80)); + IPAddress tmpLocal = Util.GetLocalHost(); + IPEndPoint tmpEnd = new IPEndPoint(tmpLocal, 80); + XmlRpcResponse response = m_loginService.XmlRpcLoginMethod(request, tmpEnd); + Hashtable responseData = (Hashtable)response.Value; Assert.That(responseData["first_name"], Is.EqualTo(m_firstName)); @@ -113,7 +116,7 @@ namespace OpenSim.Framework.Communications.Tests Regex capsSeedPattern = new Regex("^http://" - + m_regionExternalName + + NetworkUtil.GetHostFor(tmpLocal, m_regionExternalName) + ":9000/CAPS/[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}0000/$"); Assert.That(capsSeedPattern.IsMatch((string)responseData["seed_capability"]), Is.True); @@ -140,7 +143,10 @@ namespace OpenSim.Framework.Communications.Tests XmlRpcRequest request = new XmlRpcRequest("login_to_simulator", sendParams); - XmlRpcResponse response = m_loginService.XmlRpcLoginMethod(request, new IPEndPoint(Util.GetLocalHost(), 80)); + IPAddress tmpLocal = Util.GetLocalHost(); + IPEndPoint tmpEnd = new IPEndPoint(tmpLocal, 80); + XmlRpcResponse response = m_loginService.XmlRpcLoginMethod(request, tmpEnd); + Hashtable responseData = (Hashtable)response.Value; UserAgentData uagent = m_userProfileData.CurrentAgent; @@ -163,7 +169,7 @@ namespace OpenSim.Framework.Communications.Tests Regex capsSeedPattern = new Regex("^http://" - + m_regionExternalName + + NetworkUtil.GetHostFor(tmpLocal, m_regionExternalName) + ":9000/CAPS/[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}0000/$"); Assert.That(capsSeedPattern.IsMatch((string)responseData["seed_capability"]), Is.True); @@ -194,14 +200,16 @@ namespace OpenSim.Framework.Communications.Tests XmlRpcRequest request = new XmlRpcRequest("login_to_simulator", sendParams); - XmlRpcResponse response = m_loginService.XmlRpcLoginMethod(request, new IPEndPoint(Util.GetLocalHost(), 80)); + IPAddress tmpLocal = Util.GetLocalHost(); + IPEndPoint tmpEnd = new IPEndPoint(tmpLocal, 80); + XmlRpcResponse response = m_loginService.XmlRpcLoginMethod(request, tmpEnd); + Hashtable responseData = (Hashtable)response.Value; ArrayList friendslist = (ArrayList) responseData["buddy-list"]; Assert.That(friendslist,Is.Not.Null); - Hashtable buddy1 = (Hashtable) friendslist[0]; Hashtable buddy2 = (Hashtable) friendslist[1]; Assert.That(friendslist.Count, Is.EqualTo(2)); @@ -231,7 +239,10 @@ namespace OpenSim.Framework.Communications.Tests XmlRpcRequest request = new XmlRpcRequest("login_to_simulator", sendParams); - XmlRpcResponse response = m_loginService.XmlRpcLoginMethod(request, new IPEndPoint(Util.GetLocalHost(), 80)); + IPAddress tmpLocal = Util.GetLocalHost(); + IPEndPoint tmpEnd = new IPEndPoint(tmpLocal, 80); + XmlRpcResponse response = m_loginService.XmlRpcLoginMethod(request, tmpEnd); + Hashtable responseData = (Hashtable)response.Value; Assert.That(responseData["message"], Is.EqualTo(error_auth_message)); @@ -256,7 +267,10 @@ namespace OpenSim.Framework.Communications.Tests XmlRpcRequest request = new XmlRpcRequest("login_to_simulator", sendParams); - XmlRpcResponse response = m_loginService.XmlRpcLoginMethod(request, new IPEndPoint(Util.GetLocalHost(), 80)); + IPAddress tmpLocal = Util.GetLocalHost(); + IPEndPoint tmpEnd = new IPEndPoint(tmpLocal, 80); + XmlRpcResponse response = m_loginService.XmlRpcLoginMethod(request, tmpEnd); + Hashtable responseData = (Hashtable)response.Value; Assert.That(responseData["message"], Is.EqualTo(error_auth_message)); @@ -281,7 +295,10 @@ namespace OpenSim.Framework.Communications.Tests XmlRpcRequest request = new XmlRpcRequest("login_to_simulator", sendParams); - XmlRpcResponse response = m_loginService.XmlRpcLoginMethod(request, new IPEndPoint(Util.GetLocalHost(), 80)); + IPAddress tmpLocal = Util.GetLocalHost(); + IPEndPoint tmpEnd = new IPEndPoint(tmpLocal, 80); + XmlRpcResponse response = m_loginService.XmlRpcLoginMethod(request, tmpEnd); + Hashtable responseData = (Hashtable)response.Value; Assert.That(responseData["message"], Is.EqualTo(error_xml_message)); @@ -312,20 +329,24 @@ namespace OpenSim.Framework.Communications.Tests // First we log in. XmlRpcRequest request = new XmlRpcRequest("login_to_simulator", sendParams); - XmlRpcResponse response = m_loginService.XmlRpcLoginMethod(request, new IPEndPoint(Util.GetLocalHost(), 80)); + + IPAddress tmpLocal = Util.GetLocalHost(); + IPEndPoint tmpEnd = new IPEndPoint(tmpLocal, 80); + XmlRpcResponse response = m_loginService.XmlRpcLoginMethod(request, tmpEnd); + Hashtable responseData = (Hashtable)response.Value; Assert.That(responseData["message"], Is.EqualTo("Hello folks")); // Then we try again, this time expecting failure. request = new XmlRpcRequest("login_to_simulator", sendParams); - response = m_loginService.XmlRpcLoginMethod(request, new IPEndPoint(Util.GetLocalHost(), 80)); + response = m_loginService.XmlRpcLoginMethod(request, tmpEnd); responseData = (Hashtable)response.Value; Assert.That(responseData["message"], Is.EqualTo(error_already_logged)); // Finally the third time we should be able to get right back in. request = new XmlRpcRequest("login_to_simulator", sendParams); - response = m_loginService.XmlRpcLoginMethod(request, new IPEndPoint(Util.GetLocalHost(), 80)); + response = m_loginService.XmlRpcLoginMethod(request, tmpEnd); responseData = (Hashtable)response.Value; Assert.That(responseData["message"], Is.EqualTo("Hello folks")); diff --git a/OpenSim/Framework/NetworkUtil.cs b/OpenSim/Framework/NetworkUtil.cs index d4fc1e28b1..328d3bc8b5 100644 --- a/OpenSim/Framework/NetworkUtil.cs +++ b/OpenSim/Framework/NetworkUtil.cs @@ -73,9 +73,8 @@ namespace OpenSim.Framework private static IPAddress GetExternalIPFor(IPAddress destination, string defaultHostname) { - bool ipv6 = false; // Adds IPv6 Support (Not that any of the major protocols supports it...) - if (ipv6 && destination.AddressFamily == AddressFamily.InterNetworkV6) + if (destination.AddressFamily == AddressFamily.InterNetworkV6) { foreach (IPAddress host in Dns.GetHostAddresses(defaultHostname)) { @@ -91,10 +90,14 @@ namespace OpenSim.Framework return null; // Check if we're accessing localhost. - foreach (IPAddress host in Dns.GetHostAddresses(Dns.GetHostName())) + foreach (KeyValuePair pair in m_subnets) { + IPAddress host = pair.Value; if (host.Equals(destination) && host.AddressFamily == AddressFamily.InterNetwork) + { + m_log.Info("[NATROUTING] Localhost user detected, sending them '" + host + "' instead of '" + defaultHostname + "'"); return destination; + } } // Check for same LAN segment diff --git a/OpenSim/Framework/Util.cs b/OpenSim/Framework/Util.cs index 0128735b12..ee47e0fe90 100644 --- a/OpenSim/Framework/Util.cs +++ b/OpenSim/Framework/Util.cs @@ -546,7 +546,15 @@ namespace OpenSim.Framework } if (hosts.Length > 0) + { + foreach (IPAddress host in hosts) + { + if(host.AddressFamily == AddressFamily.InterNetwork) + return host; + } + // Well all else failed... return hosts[0]; + } return null; }