Procházet zdrojové kódy

Always call getInterfaceIp to find the host IP

Avoid resolving to a loopback interface.

Signed-off-by: Gavin Halliday <gavin.halliday@lexisnexis.com>
Gavin Halliday před 13 roky
rodič
revize
141bad7f82
1 změnil soubory, kde provedl 10 přidání a 11 odebrání
  1. 10 11
      system/jlib/jsocket.cpp

+ 10 - 11
system/jlib/jsocket.cpp

@@ -2568,23 +2568,22 @@ const char * GetCachedHostName()
     if (!cachehostname.get())
     {
 #ifndef _WIN32
-        StringBuffer ifs;
         IpAddress ip;
         if (EnvConfPath.length() == 0)
             EnvConfPath.append(CONFIG_DIR).append(PATHSEPSTR).append("environment.conf");
         Owned<IProperties> conf = createProperties(EnvConfPath.str(), true);
-        if (conf->getProp("interface", ifs) && ifs.length())
+
+        StringBuffer ifs;
+        conf->getProp("interface", ifs);
+        if (getInterfaceIp(ip, ifs.str()))
         {
-            if (getInterfaceIp(ip, ifs.str()))
+            StringBuffer ips;
+            ip.getIpText(ips);
+            if (ips.length())
             {
-                StringBuffer ips;
-                ip.getIpText(ips);
-                if (ips.length())
-                {
-                    cachehostname.set(ips.str());
-                    cachehostip.ipset(ip);
-                    return cachehostname.get();
-                }
+                cachehostname.set(ips.str());
+                cachehostip.ipset(ip);
+                return cachehostname.get();
             }
         }
 #endif