ferencerdei commented on code in PR #8370:
URL: https://github.com/apache/nifi/pull/8370#discussion_r1481696475


##########
c2/c2-client-bundle/c2-client-service/src/main/java/org/apache/nifi/c2/client/service/C2HeartbeatFactory.java:
##########
@@ -169,14 +171,20 @@ private NetworkInfo generateNetworkInfo() {
                     logger.debug("Instance has multiple interfaces.  Generated 
information may be non-deterministic.");
                 }
 
+                boolean networkInfoUnset = true;
                 for (NetworkInterface networkInterface : operationIfaces) {
                     Enumeration<InetAddress> inetAddresses = 
networkInterface.getInetAddresses();
-                    if (inetAddresses.hasMoreElements()) {
+                    while (inetAddresses.hasMoreElements()) {
                         InetAddress inetAddress = inetAddresses.nextElement();
-                        networkInfo.setDeviceId(networkInterface.getName());
-                        networkInfo.setHostname(inetAddress.getHostName());
-                        networkInfo.setIpAddress(inetAddress.getHostAddress());
-                        break;
+                        // IPv4 address is preferred over IPv6 as it provides 
more readable information for the user
+                        if (inetAddress instanceof Inet4Address) {
+                            updateNetworkInfo(networkInfo, networkInterface, 
inetAddress);
+                            break;
+                        }
+                        if (networkInfoUnset) {
+                            updateNetworkInfo(networkInfo, networkInterface, 
inetAddress);
+                            networkInfoUnset = false;
+                        }

Review Comment:
   I think we should break the outer loop if any of these elements are found. 
Now the last networkInterface data is used instead of the first



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to