X-Git-Url: https://git.proxmox.com/?p=pve-common.git;a=blobdiff_plain;f=src%2FPVE%2FTools.pm;h=0fb7f3c0b15b6a47a4c7d33a29b2f8db60e3339b;hp=039c9fb8dae5e2d10cb492b9f41ecf4f08397a91;hb=123921731abd556c038c746973fee1a1c87b6920;hpb=c9c6d9107387fd09d3b26206c81a66326f138de9 diff --git a/src/PVE/Tools.pm b/src/PVE/Tools.pm index 039c9fb..0fb7f3c 100644 --- a/src/PVE/Tools.pm +++ b/src/PVE/Tools.pm @@ -851,9 +851,9 @@ sub df { $pipe->reader(); my $readvalues = sub { - $res->{total} = int(<$pipe>); - $res->{used} = int(<$pipe>); - $res->{avail} = int(<$pipe>); + $res->{total} = int((<$pipe> =~ /^(\d*)$/)[0]); + $res->{used} = int((<$pipe> =~ /^(\d*)$/)[0]); + $res->{avail} = int((<$pipe> =~ /^(\d*)$/)[0]); }; eval { run_with_timeout($timeout, $readvalues); @@ -980,15 +980,20 @@ sub decode_utf8_parameters { } sub random_ether_addr { + my ($prefix) = @_; my ($seconds, $microseconds) = gettimeofday; - my $rand = Digest::SHA::sha1_hex($$, rand(), $seconds, $microseconds); + my $rand = Digest::SHA::sha1($$, rand(), $seconds, $microseconds); # 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 {