You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2020/07/15 13:57:59 UTC

[GitHub] [shardingsphere-elasticjob] mmx1960 commented on a change in pull request #1069: Consider about improvement of get IP address inaccurate

mmx1960 commented on a change in pull request #1069:
URL: https://github.com/apache/shardingsphere-elasticjob/pull/1069#discussion_r455069311



##########
File path: elasticjob-infra/elasticjob-infra-common/src/main/java/org/apache/shardingsphere/elasticjob/infra/env/IpUtils.java
##########
@@ -45,42 +52,93 @@ public static String getIp() {
         if (null != cachedIpAddress) {
             return cachedIpAddress;
         }
-        Enumeration<NetworkInterface> netInterfaces;
+        NetworkInterface networkInterface = findNetworkInterface();
+        if (null != networkInterface) {
+            Enumeration<InetAddress> ipAddresses = networkInterface.getInetAddresses();
+            while (ipAddresses.hasMoreElements()) {
+                InetAddress ipAddress = ipAddresses.nextElement();
+                if (isValidAddress(ipAddress)) {
+                    cachedIpAddress = ipAddress.getHostAddress();
+                    return cachedIpAddress;
+                }
+            }
+        }
+        return null;

Review comment:
       method **findNetworkInterface()** never return null. and if there is no valid ipAddress in the networkInterface,this mehod  **getIp()**  will return null. my confusing is : should return null when there is no valid ipAddress?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org