Subject: | MAC addresses being formatted incorrectly |
The MAC addresses
ETHERNETFRAMEDATA: EtherSrcMac, EtherDestMac
COUNTERLAG: dot3adAggPortActorSystemID dot3adAggPortPartnerOperSystemID
Are unpacked as 2 4-byte unsigned integers (so far so good)
After unpacking they are formatted as hex.
The hex for the MAC should be bytes 0-3 of the first integer and bytes 0-1 of the second integer, but isn't.
I've attached a short test script that shows the issue.
Subject: | MAC_test.pl |
#!/usr/bin/perl
use strict;
use warnings;
my ( $N1, $N2 );
$N1 = pack( 'H*', '01020304' );
for my $N ( '05060000', '05060708', '00000708' ) {
print "N2 = $N:\n";
$N2 = pack( 'H*', $N );
fmt_macs( $N1, $N2 );
}
sub fmt_macs {
my ( $N1, $N2 ) = @_;
my $MAC = $N1 . $N2;
print "MAC (new):", unpack( 'H12', $MAC ), "\n";
( $N1, $N2 ) = unpack( 'N2', $N1 . $N2 );
print "MAC (old):", sprintf( "%08x%04x", $N1, $N2 ), "\n";
}
__END__
# Local Variables: ***
# mode:CPerl ***
# cperl-indent-level:2 ***
# perl-indent-level:2 ***
# tab-width: 2 ***
# indent-tabs-mode: t ***
# End: ***
#
# vim: ts=2 sw=2 noexpandtab