diff options
author | Diva Canto | 2010-08-19 19:54:40 -0700 |
---|---|---|
committer | Diva Canto | 2010-08-19 19:54:40 -0700 |
commit | a39ea07158756a76757d4b616c60cbcedf06f268 (patch) | |
tree | 59438c64692b850dc09f96e2658e9f4d77b36a9d /OpenSim/Framework/NetworkUtil.cs | |
parent | Partial rewrite of client IP verification. Not completely finished yet, and u... (diff) | |
download | opensim-SC-a39ea07158756a76757d4b616c60cbcedf06f268.zip opensim-SC-a39ea07158756a76757d4b616c60cbcedf06f268.tar.gz opensim-SC-a39ea07158756a76757d4b616c60cbcedf06f268.tar.bz2 opensim-SC-a39ea07158756a76757d4b616c60cbcedf06f268.tar.xz |
Finished implementing ViaLogin vs ViaHGLogin. Removed lookup on myipaddress.com. Also removed client IP verification upon UDP connection that had been left there -- we can't do that in general.
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Framework/NetworkUtil.cs | 82 |
1 files changed, 0 insertions, 82 deletions
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 | } |