[pve-devel] [RFC PATCH common] tools: optional prefix for random_ether_addr

Wolfgang Bumiller w.bumiller at proxmox.com
Wed Jul 13 16:25:45 CEST 2016


---
 src/PVE/Tools.pm | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/src/PVE/Tools.pm b/src/PVE/Tools.pm
index 0d03b04..0fb7f3c 100644
--- a/src/PVE/Tools.pm
+++ b/src/PVE/Tools.pm
@@ -980,6 +980,7 @@ sub decode_utf8_parameters {
 }
 
 sub random_ether_addr {
+    my ($prefix) = @_;
 
     my ($seconds, $microseconds) = gettimeofday;
 
@@ -988,7 +989,11 @@ sub random_ether_addr {
     # clear multicast, set local id
     vec($rand, 0, 8) = (vec($rand, 0, 8) & 0xfe) | 2;
 
-    return sprintf("%02X:%02X:%02X:%02X:%02X:%02X", unpack("C6", $rand));
+    my $addr = sprintf("%02X:%02X:%02X:%02X:%02X:%02X", unpack("C6", $rand));
+    if (defined($prefix)) {
+	$addr = uc($prefix) . substr($addr, length($prefix));
+    }
+    return $addr;
 }
 
 sub shellquote {
-- 
2.1.4





More information about the pve-devel mailing list