mirror of
https://github.com/Telecominfraproject/wlan-lanforge-scripts.git
synced 2025-11-01 19:28:00 +00:00
LANforge/Utils: gains mac_add() routine; requires Math::BigInt. Tested on F24
This commit is contained in:
@@ -3,7 +3,8 @@ use strict;
|
|||||||
use warnings;
|
use warnings;
|
||||||
use Carp;
|
use Carp;
|
||||||
use Net::Telnet;
|
use Net::Telnet;
|
||||||
use bigint;
|
#use bigint;
|
||||||
|
use Math::BigInt;
|
||||||
$| = 1;
|
$| = 1;
|
||||||
#$SIG{ __DIE__ } = sub { Carp::confess( @_ ) };
|
#$SIG{ __DIE__ } = sub { Carp::confess( @_ ) };
|
||||||
#$SIG{ __WARN__ } = sub { Carp::confess( @_ ) };
|
#$SIG{ __WARN__ } = sub { Carp::confess( @_ ) };
|
||||||
@@ -1160,18 +1161,23 @@ sub expand_unit_str {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sub mac_add {
|
sub mac_add {
|
||||||
my ($first_mac, $second_dec) = @_;
|
my ($self, $first_mac, $second_dec) = @_;
|
||||||
$first_mac =~ s/[:]//g if ($first_mac =~ /[:]/);
|
$first_mac =~ s/[:]//g if ($first_mac =~ /[:]/);
|
||||||
|
|
||||||
$first_mac = "0x".$first_mac if ($first_mac !~ /^0x/);
|
$first_mac = "0x".$first_mac if ($first_mac !~ /^0x/);
|
||||||
|
my $newdec = Math::BigInt->new($first_mac);
|
||||||
my $newdec = (0+$second_dec) + hex($first_mac);
|
$newdec->badd(0+$second_dec);
|
||||||
my $newhex = sprintf("%x", $newdec);
|
my $pad = Math::BigInt->new('0x1000000000000');
|
||||||
|
$newdec->badd($pad);
|
||||||
|
my $newhex = "".$newdec->as_hex();
|
||||||
my $rv = "";
|
my $rv = "";
|
||||||
|
$newhex = substr($newhex, -12); # we begin 0x100...much bigger than we need
|
||||||
for (my $i = length($newhex); $i > 0; $i-=2) {
|
for (my $i = length($newhex); $i > 0; $i-=2) {
|
||||||
$rv = substr($newhex, $i-2, 2).":$rv";
|
$rv = substr($newhex, $i-2, 2).":$rv";
|
||||||
}
|
}
|
||||||
return substr($newhex, 0, -1);
|
$rv =substr($rv, 0, -1);
|
||||||
|
undef($newdec);
|
||||||
|
undef($pad);
|
||||||
|
return $rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user