aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework
diff options
context:
space:
mode:
authorMelanie2010-08-20 08:36:54 +0100
committerMelanie2010-08-20 08:36:54 +0100
commit82abaadd556ac6215474886daf9f9e943c64b685 (patch)
tree5ee8683e183d5e9263d04d3e610457b94ef9d378 /OpenSim/Framework
parentAdd some maptile options, change maptile generation from OpenSimBase to Scene (diff)
parentMerge branch 'master' of ssh://diva@opensimulator.org/var/git/opensim (diff)
downloadopensim-SC_OLD-82abaadd556ac6215474886daf9f9e943c64b685.zip
opensim-SC_OLD-82abaadd556ac6215474886daf9f9e943c64b685.tar.gz
opensim-SC_OLD-82abaadd556ac6215474886daf9f9e943c64b685.tar.bz2
opensim-SC_OLD-82abaadd556ac6215474886daf9f9e943c64b685.tar.xz
Merge branch 'master' of melanie@opensimulator.org:/var/git/opensim
Diffstat (limited to '')
-rw-r--r--OpenSim/Framework/Constants.cs4
-rw-r--r--OpenSim/Framework/NetworkUtil.cs82
2 files changed, 3 insertions, 83 deletions
diff --git a/OpenSim/Framework/Constants.cs b/OpenSim/Framework/Constants.cs
index 5757061..1b1aaf2 100644
--- a/OpenSim/Framework/Constants.cs
+++ b/OpenSim/Framework/Constants.cs
@@ -83,7 +83,9 @@ namespace OpenSim.Framework
83 /// <summary>Finished, Sim Changed</summary> 83 /// <summary>Finished, Sim Changed</summary>
84 FinishedViaNewSim = 1 << 28, 84 FinishedViaNewSim = 1 << 28,
85 /// <summary>Finished, Same Sim</summary> 85 /// <summary>Finished, Same Sim</summary>
86 FinishedViaSameSim = 1 << 29 86 FinishedViaSameSim = 1 << 29,
87 /// <summary>Agent coming into the grid from another grid</summary>
88 ViaHGLogin = 1 << 30
87 } 89 }
88 90
89 } 91 }
diff --git a/OpenSim/Framework/NetworkUtil.cs b/OpenSim/Framework/NetworkUtil.cs
index 831ff70..2e94b0d 100644
--- a/OpenSim/Framework/NetworkUtil.cs
+++ b/OpenSim/Framework/NetworkUtil.cs
@@ -181,18 +181,10 @@ namespace OpenSim.Framework
181 throw new ArgumentException("[NetworkUtil] Unable to resolve defaultHostname to an IPv4 address for an IPv4 client"); 181 throw new ArgumentException("[NetworkUtil] Unable to resolve defaultHostname to an IPv4 address for an IPv4 client");
182 } 182 }
183 183
184 static IPAddress externalIPAddress;
185
186 static NetworkUtil() 184 static NetworkUtil()
187 { 185 {
188 try 186 try
189 { 187 {
190 externalIPAddress = GetExternalIP();
191 }
192 catch { /* ignore */ }
193
194 try
195 {
196 foreach (NetworkInterface ni in NetworkInterface.GetAllNetworkInterfaces()) 188 foreach (NetworkInterface ni in NetworkInterface.GetAllNetworkInterfaces())
197 { 189 {
198 foreach (UnicastIPAddressInformation address in ni.GetIPProperties().UnicastAddresses) 190 foreach (UnicastIPAddressInformation address in ni.GetIPProperties().UnicastAddresses)
@@ -254,79 +246,5 @@ namespace OpenSim.Framework
254 return defaultHostname; 246 return defaultHostname;
255 } 247 }
256 248
257 public static IPAddress GetExternalIPOf(IPAddress user)
258 {
259 if (externalIPAddress == null)
260 return user;
261
262 if (user.ToString() == "127.0.0.1")
263 {
264 m_log.Info("[NetworkUtil] 127.0.0.1 user detected, sending '" + externalIPAddress + "' instead of '" + user + "'");
265 return externalIPAddress;
266 }
267 // Check if we're accessing localhost.
268 foreach (IPAddress host in Dns.GetHostAddresses(Dns.GetHostName()))
269 {
270 if (host.Equals(user) && host.AddressFamily == AddressFamily.InterNetwork)
271 {
272 m_log.Info("[NetworkUtil] Localhost user detected, sending '" + externalIPAddress + "' instead of '" + user + "'");
273 return externalIPAddress;
274 }
275 }
276
277 // Check for same LAN segment
278 foreach (KeyValuePair<IPAddress, IPAddress> subnet in m_subnets)
279 {
280 byte[] subnetBytes = subnet.Value.GetAddressBytes();
281 byte[] localBytes = subnet.Key.GetAddressBytes();
282 byte[] destBytes = user.GetAddressBytes();
283
284 if (subnetBytes.Length != destBytes.Length || subnetBytes.Length != localBytes.Length)
285 return user;
286
287 bool valid = true;
288
289 for (int i = 0; i < subnetBytes.Length; i++)
290 {
291 if ((localBytes[i] & subnetBytes[i]) != (destBytes[i] & subnetBytes[i]))
292 {
293 valid = false;
294 break;
295 }
296 }
297
298 if (subnet.Key.AddressFamily != AddressFamily.InterNetwork)
299 valid = false;
300
301 if (valid)
302 {
303 m_log.Info("[NetworkUtil] Local LAN user detected, sending '" + externalIPAddress + "' instead of '" + user + "'");
304 return externalIPAddress;
305 }
306 }
307
308 // Otherwise, return user address
309 return user;
310 }
311
312 private static IPAddress GetExternalIP()
313 {
314 string whatIsMyIp = "http://www.whatismyip.com/automation/n09230945.asp";
315 WebClient wc = new WebClient();
316 UTF8Encoding utf8 = new UTF8Encoding();
317 string requestHtml = "";
318 try
319 {
320 requestHtml = utf8.GetString(wc.DownloadData(whatIsMyIp));
321 }
322 catch (WebException we)
323 {
324 m_log.Info("[NetworkUtil]: Exception in GetExternalIP: " + we.ToString());
325 return null;
326 }
327
328 IPAddress externalIp = IPAddress.Parse(requestHtml);
329 return externalIp;
330 }
331 } 249 }
332} 250}