Skip to content

Commit 3b5aa42

Browse files
committed
CLOUDSTACK-4770: In MacAddress skip macAddress when parsed value is 0x00
In MacAddress class, we start by settig macAddress String as null and go through the output of ifconfig -a and pick the one string that is a valid mac address but is not 0x00 and 0xff. With each loop we set the macAddress to null so that it does not pick the last one if everything fails. Tested on Ubuntu where I had an interface called cloud0 whose mac id was 0x00 and it was skipped to get the next one: $ java -classpath <path-to-cloud-utils.jar> com.cloud.utils.net.MacAddress addr in integer is 5071953436 addr in bytes is 0 1 2e 4f de 1c addr in char is 00:01:2e:4f:de:1c Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
1 parent f6bde7b commit 3b5aa42

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

utils/src/com/cloud/utils/net/MacAddress.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
package com.cloud.utils.net;
2121

22+
import com.cloud.utils.NumbersUtil;
23+
2224
import java.io.BufferedReader;
2325
import java.io.File;
2426
import java.io.IOException;
@@ -27,8 +29,6 @@
2729
import java.net.UnknownHostException;
2830
import java.util.Formatter;
2931

30-
import com.cloud.utils.NumbersUtil;
31-
3232
/**
3333
* copied from the public domain utility from John Burkard.
3434
* @author <a href="mailto:jb@eaio.com">Johann Burkard</a>
@@ -114,8 +114,12 @@ public String toString() {
114114
String l = null;
115115
while ((l = in.readLine()) != null) {
116116
macAddress = MacAddress.parse(l);
117-
if (macAddress != null && MacAddress.parseShort(macAddress) != 0xff)
118-
break;
117+
if (macAddress != null) {
118+
short parsedShortMacAddress = MacAddress.parseShort(macAddress);
119+
if (parsedShortMacAddress != 0xff && parsedShortMacAddress != 0x00)
120+
break;
121+
}
122+
macAddress = null;
119123
}
120124
}
121125

0 commit comments

Comments
 (0)