mirror of
https://git.proxmox.com/git/pve-common
synced 2025-05-29 15:12:13 +00:00
Shorter implementation of random_ether_addr().
This commit is contained in:
parent
e88f9c631c
commit
de9a267fec
@ -940,21 +940,13 @@ sub random_ether_addr {
|
||||
|
||||
my $rand = Digest::SHA::sha1_hex($$, rand(), $seconds, $microseconds);
|
||||
|
||||
my $mac = '';
|
||||
for (my $i = 0; $i < 6; $i++) {
|
||||
my $ss = hex(substr($rand, $i*2, 2));
|
||||
if (!$i) {
|
||||
$ss &= 0xfe; # clear multicast
|
||||
$ss |= 2; # set local id
|
||||
}
|
||||
$ss = sprintf("%02X", $ss);
|
||||
# clear multicast, set local id
|
||||
vec($rand, 0, 8) = (vec($rand, 0, 8) & 0xfe) | 2;
|
||||
|
||||
if (!$i) {
|
||||
$mac .= "$ss";
|
||||
} else {
|
||||
$mac .= ":$ss";
|
||||
}
|
||||
}
|
||||
my $mac = sprintf("%02X:" x 6, unpack("C6", $rand));
|
||||
|
||||
# remove superfluous ":" at end
|
||||
chop($mac);
|
||||
|
||||
return $mac;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user