From: Dietmar Maurer Date: Wed, 5 Oct 2011 07:21:52 +0000 (+0200) Subject: add PVE::Tools::random_ether_addr() X-Git-Url: https://git.proxmox.com/?p=pve-common.git;a=commitdiff_plain;h=a413a515c5937862029c30c5171b935e3abd6824 add PVE::Tools::random_ether_addr() --- diff --git a/Makefile b/Makefile index feb0d19..7f07783 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ RELEASE=2.0 VERSION=1.0 -PKGREL=5 +PKGREL=6 PACKAGE=libpve-common-perl diff --git a/data/PVE/Tools.pm b/data/PVE/Tools.pm index d805240..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 @@ -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; diff --git a/debian/changelog b/debian/changelog index 9610fe3..b612dd6 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +libpve-common-perl (1.0-6) unstable; urgency=low + + * add PVE::Tools::random_ether_addr() + + -- Proxmox Support Team Wed, 05 Oct 2011 09:19:39 +0200 + libpve-common-perl (1.0-5) unstable; urgency=low * cleanups (prepare for beta release) diff --git a/debian/control b/debian/control index b2bb71f..9d7b695 100644 --- a/debian/control +++ b/debian/control @@ -7,6 +7,6 @@ Standards-Version: 3.8.4 Package: libpve-common-perl Architecture: all -Depends: ${perl:Depends} ${misc:Depends}, libdevel-cycle-perl, libwww-perl, libjson-perl, liblinux-inotify2-perl, libio-stringy-perl, liburi-perl +Depends: ${perl:Depends} ${misc:Depends}, libdevel-cycle-perl, libwww-perl, libjson-perl, liblinux-inotify2-perl, libio-stringy-perl, liburi-perl, libdigest-sha1-perl Description: Proxmox VE base library This package contains the base library used by other Proxmox VE components.