On 09/16/2013 11:39 AM, Chris Hegarty wrote:
On some platforms, Windows, tunneling interfaces report a very "bad" mac address, e.g. 00-00-00-00-00-00-00-E0. I wonder if it is worth skipping all isVirtual() nifs?
Good idea. This makes it impossible to also take advantage of Guy's de-uglification though. Leaving the following. (This might stand as a record for the most expert attention spent on the least important issue ever in JDK :-)! Recall that the motivation is solely to act as a tie-breaker in the incredibly unlikely scenario of a cluster of communicating hosts all starting at the same time.) private static long initialSeed() { String pp = java.security.AccessController.doPrivileged( new sun.security.action.GetPropertyAction( "java.util.secureRandomSeed")); if (pp != null && pp.equalsIgnoreCase("true")) { byte[] seedBytes = java.security.SecureRandom.getSeed(8); long s = (long)(seedBytes[0]) & 0xffL; for (int i = 1; i < 8; ++i) s = (s << 8) | ((long)(seedBytes[i]) & 0xffL); return s; } long h = 0L; try { Enumeration<NetworkInterface> ifcs = NetworkInterface.getNetworkInterfaces(); boolean retry = false; // retry once if getHardwareAddress is null while (ifcs.hasMoreElements()) { NetworkInterface ifc = ifcs.nextElement(); if (!ifc.isVirtual()) { // skip fake addresses byte[] bs = ifc.getHardwareAddress(); if (bs != null) { for (int i = 0; i < 8 && i < bs.length; ++i) h = (h << 8) ^ bs[i]; break; } else if (!retry) retry = true; else break; } } } catch (Exception ignore) { } return (mix64(h ^ System.currentTimeMillis()) ^ mix64(System.nanoTime())); }