[jboss-cvs] JBoss Messaging SVN: r5820 - trunk/src/main/org/jboss/messaging/util.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Feb 5 11:40:18 EST 2009


Author: clebert.suconic at jboss.com
Date: 2009-02-05 11:40:18 -0500 (Thu, 05 Feb 2009)
New Revision: 5820

Modified:
   trunk/src/main/org/jboss/messaging/util/UUIDGenerator.java
Log:
Adding black-list of invalid MACs

Modified: trunk/src/main/org/jboss/messaging/util/UUIDGenerator.java
===================================================================
--- trunk/src/main/org/jboss/messaging/util/UUIDGenerator.java	2009-02-05 16:20:46 UTC (rev 5819)
+++ trunk/src/main/org/jboss/messaging/util/UUIDGenerator.java	2009-02-05 16:40:18 UTC (rev 5820)
@@ -18,6 +18,7 @@
 import java.lang.reflect.Method;
 import java.net.NetworkInterface;
 import java.security.SecureRandom;
+import java.util.Arrays;
 import java.util.Enumeration;
 import java.util.Random;
 
@@ -29,6 +30,9 @@
 
    private static final Logger log = Logger.getLogger(UUIDGenerator.class);
 
+   // Windows has some fake adapters that will return the same HARDWARE ADDRESS on any computer. We need to ignore those
+   private static final byte[][] BLACK_LIST = new byte[][] { { 2, 0, 84, 85, 78, 1 } };
+
    /**
     * Random-generator, used by various UUID-generation methods:
     */
@@ -81,7 +85,7 @@
       return mRnd;
    }
 
-   public final UUID generateTimeBasedUUID(byte[] byteAddr)
+   public final UUID generateTimeBasedUUID(final byte[] byteAddr)
    {
       byte[] contents = new byte[16];
       int pos = 10;
@@ -148,28 +152,34 @@
          Enumeration<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces();
          while (networkInterfaces.hasMoreElements())
          {
-            NetworkInterface networkInterface = (NetworkInterface)networkInterfaces.nextElement();
+            NetworkInterface networkInterface = networkInterfaces.nextElement();
             boolean up = (Boolean)isUpMethod.invoke(networkInterface);
             boolean loopback = (Boolean)isLoopbackMethod.invoke(networkInterface);
             boolean virtual = (Boolean)isVirtualMethod.invoke(networkInterface);
-            
+
             if (loopback || virtual || !up)
             {
                continue;
             }
-            
+
             Object res = getHardwareAddressMethod.invoke(networkInterface);
             if (res != null && res instanceof byte[])
             {
                byte[] address = (byte[])res;
                byte[] paddedAddress = getZeroPaddedSixBytes(address);
+
+               if (isBlackList(address))
+               {
+                  continue;
+               }
+
                if (paddedAddress != null)
                {
                   if (log.isDebugEnabled())
                   {
                      log.debug("using hardware address " + asString(paddedAddress));
                   }
-                  return paddedAddress;                  
+                  return paddedAddress;
                }
             }
          }
@@ -209,7 +219,7 @@
       }
    }
 
-   public final static byte[] getZeroPaddedSixBytes(byte[] bytes)
+   public final static byte[] getZeroPaddedSixBytes(final byte[] bytes)
    {
       if (bytes == null)
       {
@@ -223,21 +233,33 @@
          }
          else
          {
-            //pad with zeroes to have a 6-byte array
+            // pad with zeroes to have a 6-byte array
             byte[] paddedAddress = new byte[6];
             System.arraycopy(bytes, 0, paddedAddress, 0, bytes.length);
-            for(int i = bytes.length; i < 6; i++)
+            for (int i = bytes.length; i < 6; i++)
             {
                paddedAddress[i] = 0;
             }
-            return paddedAddress;                     
+            return paddedAddress;
          }
       }
       return null;
    }
-   
+
    // Private -------------------------------------------------------
 
+   private static final boolean isBlackList(final byte[] address)
+   {
+      for (byte[] blackList : BLACK_LIST)
+      {
+         if (Arrays.equals(address, blackList))
+         {
+            return true;
+         }
+      }
+      return false;
+   }
+
    private final byte[] getAddressBytes()
    {
       if (address == null)
@@ -252,7 +274,7 @@
       return address;
    }
 
-   private static final String asString(byte[] bytes)
+   private static final String asString(final byte[] bytes)
    {
       if (bytes == null)
       {
@@ -266,5 +288,5 @@
       }
       s += bytes[bytes.length - 1];
       return s;
-   }  
+   }
 }
\ No newline at end of file




More information about the jboss-cvs-commits mailing list