Skip to content

Commit 435fa22

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> (cherry picked from commit 3b5aa42) Signed-off-by: Rohit Yadav <rohit.yadav@shapeblue.com>
1 parent f5483ee commit 435fa22

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
@@ -16,6 +16,8 @@
1616
// under the License.
1717
package com.cloud.utils.net;
1818

19+
import com.cloud.utils.NumbersUtil;
20+
1921
import java.io.BufferedReader;
2022
import java.io.File;
2123
import java.io.IOException;
@@ -24,8 +26,6 @@
2426
import java.net.UnknownHostException;
2527
import java.util.Formatter;
2628

27-
import com.cloud.utils.NumbersUtil;
28-
2929
/**
3030
* copied from the public domain utility from John Burkard.
3131
* @author <a href="mailto:jb@eaio.com">Johann Burkard</a>
@@ -117,8 +117,12 @@ public String toString() {
117117
String l = null;
118118
while ((l = in.readLine()) != null) {
119119
macAddress = MacAddress.parse(l);
120-
if (macAddress != null && MacAddress.parseShort(macAddress) != 0xff)
121-
break;
120+
if (macAddress != null) {
121+
short parsedShortMacAddress = MacAddress.parseShort(macAddress);
122+
if (parsedShortMacAddress != 0xff && parsedShortMacAddress != 0x00)
123+
break;
124+
}
125+
macAddress = null;
122126
}
123127
}
124128

0 commit comments

Comments
 (0)