aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/NetworkUtil.cs
diff options
context:
space:
mode:
authorAdam Frisby2009-05-23 05:44:18 +0000
committerAdam Frisby2009-05-23 05:44:18 +0000
commit3b1b3ac9bbd77796a55bcc75d08f78bff5ca78af (patch)
tree3f9694631e41a4daf4465fea4a35bb966805d362 /OpenSim/Framework/NetworkUtil.cs
parent* NetworkUtil now handles an error case in a way which is easier to debug. (diff)
downloadopensim-SC_OLD-3b1b3ac9bbd77796a55bcc75d08f78bff5ca78af.zip
opensim-SC_OLD-3b1b3ac9bbd77796a55bcc75d08f78bff5ca78af.tar.gz
opensim-SC_OLD-3b1b3ac9bbd77796a55bcc75d08f78bff5ca78af.tar.bz2
opensim-SC_OLD-3b1b3ac9bbd77796a55bcc75d08f78bff5ca78af.tar.xz
* Breaks OpenSim.. err I mean.. adds NAT translation support to EnableSimulator EventQueue methods.
* NB: This may actually break logins on certain regions. Shake well before consuming.
Diffstat (limited to 'OpenSim/Framework/NetworkUtil.cs')
-rw-r--r--OpenSim/Framework/NetworkUtil.cs40
1 files changed, 39 insertions, 1 deletions
diff --git a/OpenSim/Framework/NetworkUtil.cs b/OpenSim/Framework/NetworkUtil.cs
index 759c52f..81e6cad 100644
--- a/OpenSim/Framework/NetworkUtil.cs
+++ b/OpenSim/Framework/NetworkUtil.cs
@@ -14,11 +14,49 @@ namespace OpenSim.Framework
14 /// This enables standard port forwarding techniques 14 /// This enables standard port forwarding techniques
15 /// to work correctly with OpenSim. 15 /// to work correctly with OpenSim.
16 /// </summary> 16 /// </summary>
17 static class NetworkUtil 17 public static class NetworkUtil
18 { 18 {
19 // IPv4Address, Subnet 19 // IPv4Address, Subnet
20 static readonly Dictionary<IPAddress,IPAddress> m_subnets = new Dictionary<IPAddress, IPAddress>(); 20 static readonly Dictionary<IPAddress,IPAddress> m_subnets = new Dictionary<IPAddress, IPAddress>();
21 21
22 public static IPAddress GetIPFor(IPAddress user, IPAddress simulator)
23 {
24 // Check if we're accessing localhost.
25 foreach (IPAddress host in Dns.GetHostAddresses(Dns.GetHostName()))
26 {
27 if (host.Equals(user) && host.AddressFamily == AddressFamily.InterNetwork)
28 return host;
29 }
30
31 // Check for same LAN segment
32 foreach (KeyValuePair<IPAddress, IPAddress> subnet in m_subnets)
33 {
34 byte[] subnetBytes = subnet.Value.GetAddressBytes();
35 byte[] localBytes = subnet.Key.GetAddressBytes();
36 byte[] destBytes = user.GetAddressBytes();
37
38 if (subnetBytes.Length != destBytes.Length || subnetBytes.Length != localBytes.Length)
39 return null;
40
41 bool valid = true;
42
43 for (int i = 0; i < subnetBytes.Length; i++)
44 {
45 if ((localBytes[i] & subnetBytes[i]) != (destBytes[i] & subnetBytes[i]))
46 {
47 valid = false;
48 break;
49 }
50 }
51
52 if (valid)
53 return subnet.Key;
54 }
55
56 // Otherwise, return outside address
57 return simulator;
58 }
59
22 private static IPAddress GetExternalIPFor(IPAddress destination, string defaultHostname) 60 private static IPAddress GetExternalIPFor(IPAddress destination, string defaultHostname)
23 { 61 {
24 // Adds IPv6 Support (Not that any of the major protocols supports it...) 62 // Adds IPv6 Support (Not that any of the major protocols supports it...)