* "Fixed" an issue with NAT Login Handler, apparently an IPv4Mask can be null on an IPv4 address. Go figure. (!?!)

0.6.6-post-fixes
Adam Frisby 2009-05-23 07:07:02 +00:00
parent 6b312d9340
commit bb363d9aa4
1 changed files with 24 additions and 1 deletions

View File

@ -3,6 +3,8 @@ using System.Collections.Generic;
using System.Net.Sockets; using System.Net.Sockets;
using System.Net; using System.Net;
using System.Net.NetworkInformation; using System.Net.NetworkInformation;
using System.Reflection;
using log4net;
namespace OpenSim.Framework namespace OpenSim.Framework
{ {
@ -16,6 +18,9 @@ namespace OpenSim.Framework
/// </summary> /// </summary>
public static class NetworkUtil public static class NetworkUtil
{ {
// Logger
private static readonly ILog m_log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
// IPv4Address, Subnet // IPv4Address, Subnet
static readonly Dictionary<IPAddress,IPAddress> m_subnets = new Dictionary<IPAddress, IPAddress>(); static readonly Dictionary<IPAddress,IPAddress> m_subnets = new Dictionary<IPAddress, IPAddress>();
@ -25,7 +30,10 @@ namespace OpenSim.Framework
foreach (IPAddress host in Dns.GetHostAddresses(Dns.GetHostName())) foreach (IPAddress host in Dns.GetHostAddresses(Dns.GetHostName()))
{ {
if (host.Equals(user) && host.AddressFamily == AddressFamily.InterNetwork) if (host.Equals(user) && host.AddressFamily == AddressFamily.InterNetwork)
{
m_log.Info("[NATROUTING] Localhost user detected, sending them '" + host + "' instead of '" + simulator + "'");
return host; return host;
}
} }
// Check for same LAN segment // Check for same LAN segment
@ -50,7 +58,10 @@ namespace OpenSim.Framework
} }
if (valid) if (valid)
{
m_log.Info("[NATROUTING] Local LAN user detected, sending them '" + subnet.Key + "' instead of '" + simulator + "'");
return subnet.Key; return subnet.Key;
}
} }
// Otherwise, return outside address // Otherwise, return outside address
@ -65,7 +76,10 @@ namespace OpenSim.Framework
foreach (IPAddress host in Dns.GetHostAddresses(defaultHostname)) foreach (IPAddress host in Dns.GetHostAddresses(defaultHostname))
{ {
if (host.AddressFamily == AddressFamily.InterNetworkV6) if (host.AddressFamily == AddressFamily.InterNetworkV6)
{
m_log.Info("[NATROUTING] Localhost user detected, sending them '" + host + "' instead of '" + defaultHostname + "'");
return host; return host;
}
} }
} }
@ -101,7 +115,10 @@ namespace OpenSim.Framework
} }
if (valid) if (valid)
{
m_log.Info("[NATROUTING] Local LAN user detected, sending them '" + subnet.Key + "' instead of '" + defaultHostname + "'");
return subnet.Key; return subnet.Key;
}
} }
// Check to see if we can find a IPv4 address. // Check to see if we can find a IPv4 address.
@ -123,7 +140,13 @@ namespace OpenSim.Framework
{ {
if (address.Address.AddressFamily == AddressFamily.InterNetwork) if (address.Address.AddressFamily == AddressFamily.InterNetwork)
{ {
m_subnets.Add(address.Address, address.IPv4Mask); if (address.IPv4Mask != null)
{
m_subnets.Add(address.Address, address.IPv4Mask);
} else
{
m_log.Warn("[NetworkUtil] Found IPv4 Address without Subnet Mask!?");
}
} }
} }
} }