aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Util.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Framework/Util.cs59
1 files changed, 59 insertions, 0 deletions
diff --git a/OpenSim/Framework/Util.cs b/OpenSim/Framework/Util.cs
index 5eedd29..83d9df1 100644
--- a/OpenSim/Framework/Util.cs
+++ b/OpenSim/Framework/Util.cs
@@ -429,6 +429,65 @@ namespace OpenSim.Framework
429 return regionCoord << 8; 429 return regionCoord << 8;
430 } 430 }
431 431
432 public static IPEndPoint getEndPoint(IPAddress ia, int port)
433 {
434 if(ia == null)
435 return null;
436
437 IPEndPoint newEP = null;
438 try
439 {
440 newEP = new IPEndPoint(ia, port);
441 }
442 catch
443 {
444 newEP = null;
445 }
446 return newEP;
447 }
448
449 public static IPEndPoint getEndPoint(string hostname, int port)
450 {
451 IPAddress ia = null;
452 // If it is already an IP, don't resolve it - just return directly
453 // we should not need this
454 if (IPAddress.TryParse(hostname, out ia))
455 {
456 if (ia.Equals(IPAddress.Any) || ia.Equals(IPAddress.IPv6Any))
457 return null;
458 return getEndPoint(ia, port);
459 }
460
461 // Reset for next check
462 ia = null;
463 try
464 {
465 foreach (IPAddress Adr in Dns.GetHostAddresses(hostname))
466 {
467 if (ia == null)
468 ia = Adr;
469
470 if (Adr.AddressFamily == AddressFamily.InterNetwork)
471 {
472 ia = Adr;
473 break;
474 }
475 }
476 }
477 catch // (SocketException e)
478 {
479 /*throw new Exception(
480 "Unable to resolve local hostname " + m_externalHostName + " innerException of type '" +
481 e + "' attached to this exception", e);*/
482 // Don't throw a fatal exception here, instead, return Null and handle it in the caller.
483 // Reason is, on systems such as OSgrid it has occured that known hostnames stop
484 // resolving and thus make surrounding regions crash out with this exception.
485 return null;
486 }
487
488 return getEndPoint(ia,port);
489 }
490
432 public static bool checkServiceURI(string uristr, out string serviceURI) 491 public static bool checkServiceURI(string uristr, out string serviceURI)
433 { 492 {
434 serviceURI = string.Empty; 493 serviceURI = string.Empty;