From 842b68eeff7571d3c82415c65065bec3c95f34ea Mon Sep 17 00:00:00 2001 From: Melanie Date: Thu, 18 Feb 2010 04:19:33 +0000 Subject: Change handling of the SYSTEMIP constant to be more sane. This will now choose the first network interface IP address, or the loopback interface if no external interfaces are found. It will log the IP address used as [NETWORK]: Using x.x.x.x for SYSTEMIP. --- OpenSim/Framework/Util.cs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'OpenSim/Framework/Util.cs') diff --git a/OpenSim/Framework/Util.cs b/OpenSim/Framework/Util.cs index 7215086..48435cb 100644 --- a/OpenSim/Framework/Util.cs +++ b/OpenSim/Framework/Util.cs @@ -589,11 +589,17 @@ namespace OpenSim.Framework public static IPAddress GetLocalHost() { - string dnsAddress = "localhost"; + IPAddress[] iplist = GetLocalHosts(); - IPAddress[] hosts = Dns.GetHostEntry(dnsAddress).AddressList; + if (iplist.Length == 0) // No accessible external interfaces + { + IPAddress[] loopback = Dns.GetHostAddresses("localhost"); + IPAddress localhost = loopback[0]; - foreach (IPAddress host in hosts) + return localhost; + } + + foreach (IPAddress host in iplist) { if (!IPAddress.IsLoopback(host) && host.AddressFamily == AddressFamily.InterNetwork) { @@ -601,15 +607,15 @@ namespace OpenSim.Framework } } - if (hosts.Length > 0) + if (iplist.Length > 0) { - foreach (IPAddress host in hosts) + foreach (IPAddress host in iplist) { if (host.AddressFamily == AddressFamily.InterNetwork) return host; } // Well all else failed... - return hosts[0]; + return iplist[0]; } return null; -- cgit v1.1