add PVE::Tools::random_ether_addr()

This commit is contained in:
Dietmar Maurer 2011-10-05 09:21:52 +02:00
parent 67799787db
commit a413a515c5
4 changed files with 31 additions and 2 deletions

View File

@ -1,7 +1,7 @@
RELEASE=2.0
VERSION=1.0
PKGREL=5
PKGREL=6
PACKAGE=libpve-common-perl

View File

@ -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;

6
debian/changelog vendored
View File

@ -1,3 +1,9 @@
libpve-common-perl (1.0-6) unstable; urgency=low
* add PVE::Tools::random_ether_addr()
-- Proxmox Support Team <support@proxmox.com> Wed, 05 Oct 2011 09:19:39 +0200
libpve-common-perl (1.0-5) unstable; urgency=low
* cleanups (prepare for beta release)

2
debian/control vendored
View File

@ -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.