rohityadavcloud commented on code in PR #8988:
URL: https://github.com/apache/cloudstack/pull/8988#discussion_r1580918983


##########
utils/src/main/java/com/cloud/utils/net/MacAddress.java:
##########
@@ -79,209 +72,45 @@ public String toString() {
     static {
         String macAddress = null;
 
-        Process p = null;
-        BufferedReader in = null;
-
         try {
-            String osname = System.getProperty("os.name");
-
-            if (osname.startsWith("Windows")) {
-                p = Runtime.getRuntime().exec(new String[] {"ipconfig", 
"/all"}, null);
-            } else if (osname.startsWith("Solaris") || 
osname.startsWith("SunOS")) {
-                // Solaris code must appear before the generic code
-                String hostName = MacAddress.getFirstLineOfCommand(new 
String[] {"uname", "-n"});
-                if (hostName != null) {
-                    p = Runtime.getRuntime().exec(new String[] 
{"/usr/sbin/arp", hostName}, null);
-                }
-            } else if (new File("/usr/sbin/lanscan").exists()) {
-                p = Runtime.getRuntime().exec(new String[] 
{"/usr/sbin/lanscan"}, null);
-            } else if (new File("/sbin/ifconfig").exists()) {
-                p = Runtime.getRuntime().exec(new String[] {"/sbin/ifconfig", 
"-a"}, null);
-            }
-
-            if (p != null) {
-                in = new BufferedReader(new 
InputStreamReader(p.getInputStream()), 128);
-                String l = null;
-                while ((l = in.readLine()) != null) {
-                    macAddress = MacAddress.parse(l);
-                    if (macAddress != null) {
-                        short parsedShortMacAddress = 
MacAddress.parseShort(macAddress);
-                        if (parsedShortMacAddress != 0xff && 
parsedShortMacAddress != 0x00)
-                            break;
-                    }
-                    macAddress = null;
-                }
-            }
-
-        } catch (SecurityException ex) {
-            s_logger.info("[ignored] security exception in static initializer 
of MacAddress", ex);
-        } catch (IOException ex) {
-            s_logger.info("[ignored] io exception in static initializer of 
MacAddress");
-        } finally {
-            if (p != null) {
-                closeAutoCloseable(in, "closing init process input stream");
-                closeAutoCloseable(p.getErrorStream(), "closing init process 
error output stream");
-                closeAutoCloseable(p.getOutputStream(), "closing init process 
std output stream");
-                p.destroy();
-            }
+            Enumeration<NetworkInterface> networkInterfaces = 
NetworkInterface.getNetworkInterfaces();
+            while (networkInterfaces.hasMoreElements()) {
+                 NetworkInterface network = networkInterfaces.nextElement();
+                 final byte [] mac = network.getHardwareAddress();
+                 if (mac != null && !network.isVirtual() &&
+                         !network.getName().startsWith("br-") &&
+                         !network.getName().startsWith("veth") &&
+                         !network.getName().startsWith("vnet")) {

Review Comment:
   One concern though, cc @weizhouapache if you know - do people run CloudStack 
in containers - if so, could this cause issues (if we ignore virtual nics?)



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