Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
  • 3 commits
  • 3 files changed
  • 0 commit comments
  • 1 contributor
Showing with 20 additions and 11 deletions.
  1. +4 −0 Changes
  2. +9 −2 lib/NetAddr/MAC.pm
  3. +7 −9 t/{100-mac-formats.t → 150-misc-bad-formats.t}
View
4 Changes
@@ -1,5 +1,9 @@
NetAddr::MAC - A MAC address object
+0.82 2013-12-09
+ - Tests for bad mac addresses from Oliver Gorwits (http://gorwits.me.uk/)
+ - For Cisco format 1111.2222.3333 - we no longer support dropping leading zeros. This was a trade off to better detect broken mac's. Cisco doesnt drop them anyway so its, IMO, the most sensible compromise.
+
0.81 2013-11-01
- Handle strange things like aabb.cc.11.22.33 or 11.22.33.aabbcc
View
11 lib/NetAddr/MAC.pm
@@ -38,7 +38,7 @@ use constant ETHER2TOKEN => (
use base qw( Exporter );
use vars qw( $VERSION %EXPORT_TAGS @EXPORT_OK );
-$VERSION = (qw$Revision: 0.81 $)[1];
+$VERSION = (qw$Revision: 0.82 $)[1];
%EXPORT_TAGS = (
all => [
@@ -252,7 +252,8 @@ sub new {
return;
}
- if (scalar grep {!defined $_ or 0 == length $_} @{$self->{mac}}) {
+ # check none of the list elements are empty
+ if (first { not defined $_ or 0 == length $_} @{$self->{mac}}) {
croak "Invalid MAC format '$self->{original}'\n" if $self->{_die};
return;
}
@@ -313,6 +314,12 @@ sub new {
# 0019:e301:0e72
if ( @parts == EUI48LENGTHDEC / 2 || @parts == EUI64LENGTHDEC / 2 )
{
+ # it would be nice to accept no leading 0's but this gives
+ # problems detecting broken formatted macs.
+ # cisco doesnt drop leading zeros so lets go for the least
+ # edgey of the edge cases.
+ last if (first {length $_ < 4} @parts);
+
return [
map {
m{^ ([a-f0-9]{2}) ([a-f0-9]{2}) $}ix
View
16 t/100-mac-formats.t → t/150-misc-bad-formats.t 100644 → 100755
@@ -2,7 +2,7 @@
use strict;
use warnings FATAL => 'all';
-use Test::More 0.88;
+use Test::More tests => 6;
BEGIN {
use_ok('NetAddr::MAC');
@@ -11,22 +11,20 @@ $NetAddr::MAC::die_on_error = 1;
eval{NetAddr::MAC->new('')};
like ($@,
- qr/Please provide a mac address/i, "Empty MAC");
+ qr/Please provide a mac address/i, 'Empty MAC');
eval{NetAddr::MAC->new()};
like ($@,
- qr/please provide a mac address/i, "Undef MAC");
+ qr/please provide a mac address/i, 'Undef MAC');
eval{NetAddr::MAC->new('11:22:33:44:xx:55')};
like ($@,
- qr/Invalid MAC format/, "Bad MAC character");
+ qr/Invalid MAC format/, 'Bad MAC character');
eval{NetAddr::MAC->new('1:1')};
like ($@,
- qr/Invalid MAC format/, "Bad MAC octet");
+ qr/Invalid MAC format/, 'Bad MAC octet');
-eval{NetAddr::MAC->new('11:22:33:44')};
+eval{NetAddr::MAC->new('11:22:33')};
like ($@,
- qr/Invalid MAC format/, "Short MAC");
-
-done_testing;
+ qr/Invalid MAC format/, 'Short MAC');

No commit comments for this range

Something went wrong with that request. Please try again.