aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Util.cs
diff options
context:
space:
mode:
authorUbitUmarov2017-05-29 02:07:53 +0100
committerUbitUmarov2017-05-29 02:07:53 +0100
commit2c19d084481e6a710d47ce72c357b1c1a6340531 (patch)
tree7e07c5da74a9c20e302c665fe18e426b2abb95b3 /OpenSim/Framework/Util.cs
parent add temporary debug msgs (diff)
downloadopensim-SC-2c19d084481e6a710d47ce72c357b1c1a6340531.zip
opensim-SC-2c19d084481e6a710d47ce72c357b1c1a6340531.tar.gz
opensim-SC-2c19d084481e6a710d47ce72c357b1c1a6340531.tar.bz2
opensim-SC-2c19d084481e6a710d47ce72c357b1c1a6340531.tar.xz
cleanup util.cs get dns
Diffstat (limited to 'OpenSim/Framework/Util.cs')
-rw-r--r--OpenSim/Framework/Util.cs157
1 files changed, 80 insertions, 77 deletions
diff --git a/OpenSim/Framework/Util.cs b/OpenSim/Framework/Util.cs
index 83d9df1..e3d89dc 100644
--- a/OpenSim/Framework/Util.cs
+++ b/OpenSim/Framework/Util.cs
@@ -429,64 +429,6 @@ 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
491 public static bool checkServiceURI(string uristr, out string serviceURI) 433 public static bool checkServiceURI(string uristr, out string serviceURI)
492 { 434 {
@@ -1066,38 +1008,99 @@ namespace OpenSim.Framework
1066 /// <returns>An IP address, or null</returns> 1008 /// <returns>An IP address, or null</returns>
1067 public static IPAddress GetHostFromDNS(string dnsAddress) 1009 public static IPAddress GetHostFromDNS(string dnsAddress)
1068 { 1010 {
1069 // Is it already a valid IP? No need to look it up. 1011 // If it is already an IP, avoid possible broken mono from seeing it
1070 IPAddress ipa; 1012 IPAddress ia = null;
1071 if (IPAddress.TryParse(dnsAddress, out ipa)) 1013 if (IPAddress.TryParse(dnsAddress, out ia) && ia != null)
1072 return ipa; 1014 {
1015 if (ia.Equals(IPAddress.Any) || ia.Equals(IPAddress.IPv6Any))
1016 return null;
1017 return ia;
1018 }
1019 // Reset for next check
1020 ia = null;
1021 try
1022 {
1023 foreach (IPAddress Adr in Dns.GetHostAddresses(dnsAddress))
1024 {
1025 if (ia == null)
1026 ia = Adr;
1073 1027
1074 IPAddress[] hosts = null; 1028 if (Adr.AddressFamily == AddressFamily.InterNetwork)
1029 {
1030 ia = Adr;
1031 break;
1032 }
1033 }
1034 }
1035 catch // (SocketException e)
1036 {
1037 /*throw new Exception(
1038 "Unable to resolve local hostname " + m_externalHostName + " innerException of type '" +
1039 e + "' attached to this exception", e);*/
1040 // Don't throw a fatal exception here, instead, return Null and handle it in the caller.
1041 // Reason is, on systems such as OSgrid it has occured that known hostnames stop
1042 // resolving and thus make surrounding regions crash out with this exception.
1043 return null;
1044 }
1045 return ia;
1046 }
1047
1048 public static IPEndPoint getEndPoint(IPAddress ia, int port)
1049 {
1050 if(ia == null)
1051 return null;
1075 1052
1076 // Not an IP, lookup required 1053 IPEndPoint newEP = null;
1077 try 1054 try
1078 { 1055 {
1079 hosts = Dns.GetHostEntry(dnsAddress).AddressList; 1056 newEP = new IPEndPoint(ia, port);
1080 } 1057 }
1081 catch (Exception e) 1058 catch
1082 { 1059 {
1083 m_log.WarnFormat("[UTIL]: An error occurred while resolving host name {0}, {1}", dnsAddress, e); 1060 newEP = null;
1084
1085 // Still going to throw the exception on for now, since this was what was happening in the first place
1086 throw e;
1087 } 1061 }
1062 return newEP;
1063 }
1088 1064
1089 foreach (IPAddress host in hosts) 1065 public static IPEndPoint getEndPoint(string hostname, int port)
1066 {
1067 IPAddress ia = null;
1068 // If it is already an IP, avoid possible broken mono from seeing it
1069 if (IPAddress.TryParse(hostname, out ia) && ia != null)
1090 { 1070 {
1091 if (host.AddressFamily == AddressFamily.InterNetwork) 1071 if (ia.Equals(IPAddress.Any) || ia.Equals(IPAddress.IPv6Any))
1072 return null;
1073 return getEndPoint(ia, port);
1074 }
1075
1076 // Reset for next check
1077 ia = null;
1078 try
1079 {
1080 foreach (IPAddress Adr in Dns.GetHostAddresses(hostname))
1092 { 1081 {
1093 return host; 1082 if (ia == null)
1083 ia = Adr;
1084
1085 if (Adr.AddressFamily == AddressFamily.InterNetwork)
1086 {
1087 ia = Adr;
1088 break;
1089 }
1094 } 1090 }
1095 } 1091 }
1092 catch // (SocketException e)
1093 {
1094 /*throw new Exception(
1095 "Unable to resolve local hostname " + m_externalHostName + " innerException of type '" +
1096 e + "' attached to this exception", e);*/
1097 // Don't throw a fatal exception here, instead, return Null and handle it in the caller.
1098 // Reason is, on systems such as OSgrid it has occured that known hostnames stop
1099 // resolving and thus make surrounding regions crash out with this exception.
1100 return null;
1101 }
1096 1102
1097 if (hosts.Length > 0) 1103 return getEndPoint(ia,port);
1098 return hosts[0];
1099
1100 return null;
1101 } 1104 }
1102 1105
1103 public static Uri GetURI(string protocol, string hostname, int port, string path) 1106 public static Uri GetURI(string protocol, string hostname, int port, string path)