X-Git-Url: https://git.proxmox.com/?p=pve-common.git;a=blobdiff_plain;f=data%2FPVE%2FTools.pm;h=5e8e7bf46460c1abfa5fd199e3bcca14c5176cbe;hp=6eaf68c7ac3422bd74db51f0f8899ffecf6e147b;hb=a413a515c5937862029c30c5171b935e3abd6824;hpb=e143e9d86b489c57166b5c192bf41dcc3452471e diff --git a/data/PVE/Tools.pm b/data/PVE/Tools.pm index 6eaf68c..5e8e7bf 100644 --- a/data/PVE/Tools.pm +++ b/data/PVE/Tools.pm @@ -12,6 +12,7 @@ use Fcntl qw(:DEFAULT :flock); use base 'Exporter'; use URI::Escape; use Encode; +use Digest::SHA1; our @EXPORT_OK = qw( lock_file @@ -212,7 +213,7 @@ sub run_command { my $orig_pid = $$; eval { - local $ENV{LANG} = $lang; + local $ENV{LC_ALL} = $lang; # suppress LVM warnings like: "File descriptor 3 left open"; local $ENV{LVM_SUPPRESS_FD_WARNINGS} = "1"; @@ -635,5 +636,27 @@ sub decode_text { return Encode::decode("utf8", uri_unescape($data)); } +sub random_ether_addr { + + my $rand = Digest::SHA1::sha1_hex(rand(), time()); + + 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); + + if (!$i) { + $mac .= "$ss"; + } else { + $mac .= ":$ss"; + } + } + + return $mac; +} 1;