aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Framework')
-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...)