From: minkee.lee Date: Tue, 13 Jan 2015 12:26:33 +0000 (+0900) Subject: Tun/tap: Modified MAC address generation. X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f754eae65ef8e050e4a863c96766a6b7cefb00d6;p=sdk%2Femulator%2Femulator-manager.git Tun/tap: Modified MAC address generation. - Added validation for Most Significant Byte. Change-Id: I6e1cb112239df331a275ebcd3f8d16d5a5f50f58 Signed-off-by: minkee.lee --- diff --git a/common-project/src/org/tizen/emulator/manager/ui/detail/item/property/NetMacViewItem.java b/common-project/src/org/tizen/emulator/manager/ui/detail/item/property/NetMacViewItem.java index 05df721..ce82f13 100644 --- a/common-project/src/org/tizen/emulator/manager/ui/detail/item/property/NetMacViewItem.java +++ b/common-project/src/org/tizen/emulator/manager/ui/detail/item/property/NetMacViewItem.java @@ -119,12 +119,18 @@ public class NetMacViewItem extends TextViewItem { StringBuilder sb = new StringBuilder(); for (int i = 0; i < 12; i++) { sb.append(MAC_CHAR[rd.nextInt(15)]); - if (i == 1) { // First 2 byte must be EVEN. - if ((Integer.parseInt(sb.toString(), 16) % 2) == 1) { - sb.delete(0, sb.length()); - i = -1; - continue; + if (i == 1) { + // Most significant byte should satisfy following conditions. + // - 1st bit = 0 (least significant bit) + // - 2nd bit = 1 + int firstByteInt = Integer.parseInt(sb.toString(), 16); + firstByteInt &= 252; // set last two bit zero. + firstByteInt |= 2; // set last two bit '10'. + StringBuilder hex = new StringBuilder(Integer.toHexString(firstByteInt)); + if (hex.length() < 2) { + hex.insert(0, "0"); // padding zero. } + sb.replace(0, 2, hex.toString()); } if (i > 0 && i < 11 && (i % 2 == 1)) { sb.append(":");