line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!/bin/false |
2
|
|
|
|
|
|
|
# ABSTRACT: MAC address functions and object |
3
|
|
|
|
|
|
|
|
4
|
5
|
|
|
5
|
|
249062
|
use strict; |
|
5
|
|
|
|
|
32
|
|
|
5
|
|
|
|
|
113
|
|
5
|
5
|
|
|
5
|
|
20
|
use warnings; |
|
5
|
|
|
|
|
7
|
|
|
5
|
|
|
|
|
229
|
|
6
|
|
|
|
|
|
|
package NetAddr::MAC; |
7
|
|
|
|
|
|
|
$NetAddr::MAC::VERSION = '0.96'; |
8
|
|
|
|
|
|
|
|
9
|
5
|
|
|
5
|
|
24
|
use Carp qw( croak ); |
|
5
|
|
|
|
|
14
|
|
|
5
|
|
|
|
|
198
|
|
10
|
5
|
|
|
5
|
|
23
|
use List::Util qw( first ); |
|
5
|
|
|
|
|
5
|
|
|
5
|
|
|
|
|
439
|
|
11
|
|
|
|
|
|
|
|
12
|
5
|
|
|
5
|
|
24
|
use constant EUI48LENGTHHEX => 12; |
|
5
|
|
|
|
|
7
|
|
|
5
|
|
|
|
|
436
|
|
13
|
5
|
|
|
5
|
|
25
|
use constant EUI48LENGTHDEC => 6; |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
199
|
|
14
|
5
|
|
|
5
|
|
22
|
use constant EUI64LENGTHHEX => 16; |
|
5
|
|
|
|
|
6
|
|
|
5
|
|
|
|
|
190
|
|
15
|
5
|
|
|
5
|
|
22
|
use constant EUI64LENGTHDEC => 8; |
|
5
|
|
|
|
|
14
|
|
|
5
|
|
|
|
|
853
|
|
16
|
|
|
|
|
|
|
|
17
|
5
|
|
|
|
|
613
|
use constant ETHER2TOKEN => ( |
18
|
|
|
|
|
|
|
## see also http://www-01.ibm.com/support/docview.wss?uid=nas114157020a771b25d862567250003b62c |
19
|
|
|
|
|
|
|
## note this table is rotated compared to the above link, |
20
|
|
|
|
|
|
|
## so that the hex values line up as a linear array :) |
21
|
|
|
|
|
|
|
## 0 1 2 3 4 5 6 7 8 9 a b c d e f |
22
|
|
|
|
|
|
|
qw(00 80 40 c0 20 a0 60 e0 10 90 50 d0 30 b0 70 f0), # 0 |
23
|
|
|
|
|
|
|
qw(08 88 48 c8 28 a8 68 e8 18 98 58 d8 38 b8 78 f8), # 1 |
24
|
|
|
|
|
|
|
qw(04 84 44 c4 24 a4 64 e4 14 94 54 d4 34 b4 74 f4), # 2 |
25
|
|
|
|
|
|
|
qw(0c 8c 4c cc 2c ac 6c ec 1c 9c 5c dc 3c bc 7c fc), # 3 |
26
|
|
|
|
|
|
|
qw(02 82 42 c2 22 a2 62 e2 12 92 52 d2 32 b2 72 f2), # 4 |
27
|
|
|
|
|
|
|
qw(0a 8a 4a ca 2a aa 6a ea 1a 9a 5a da 3a ba 7a fa), # 5 |
28
|
|
|
|
|
|
|
qw(06 86 46 c6 26 a6 66 e6 16 96 56 d6 36 b6 76 f6), # 6 |
29
|
|
|
|
|
|
|
qw(0e 8e 4e ce 2e ae 6e ee 1e 9e 5e de 3e be 7e fe), # 7 |
30
|
|
|
|
|
|
|
qw(01 81 41 c1 21 a1 61 e1 11 91 51 d1 31 b1 71 f1), # 8 |
31
|
|
|
|
|
|
|
qw(09 89 49 c9 29 a9 69 e9 19 99 59 d9 39 b9 79 f9), # 9 |
32
|
|
|
|
|
|
|
qw(05 85 45 c5 25 a5 65 e5 15 95 55 d5 35 b5 75 f5), # a |
33
|
|
|
|
|
|
|
qw(0d 8d 4d cd 2d ad 6d ed 1d 9d 5d dd 3d bd 7d fd), # b |
34
|
|
|
|
|
|
|
qw(03 83 43 c3 23 a3 63 e3 13 93 53 d3 33 b3 73 f3), # c |
35
|
|
|
|
|
|
|
qw(0b 8b 4b cb 2b ab 6b eb 1b 9b 5b db 3b bb 7b fb), # d |
36
|
|
|
|
|
|
|
qw(07 87 47 c7 27 a7 67 e7 17 97 57 d7 37 b7 77 f7), # e |
37
|
|
|
|
|
|
|
qw(0f 8f 4f cf 2f af 6f ef 1f 9f 5f df 3f bf 7f ff), # f |
38
|
5
|
|
|
5
|
|
25
|
); |
|
5
|
|
|
|
|
10
|
|
39
|
|
|
|
|
|
|
|
40
|
5
|
|
|
5
|
|
26
|
use base qw( Exporter ); |
|
5
|
|
|
|
|
5
|
|
|
5
|
|
|
|
|
524
|
|
41
|
5
|
|
|
5
|
|
26
|
use vars qw( %EXPORT_TAGS ); |
|
5
|
|
|
|
|
8
|
|
|
5
|
|
|
|
|
19305
|
|
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
%EXPORT_TAGS = ( |
44
|
|
|
|
|
|
|
all => [ |
45
|
|
|
|
|
|
|
qw( |
46
|
|
|
|
|
|
|
mac_is_eui48 mac_is_eui64 |
47
|
|
|
|
|
|
|
mac_is_unicast mac_is_multicast |
48
|
|
|
|
|
|
|
mac_is_broadcast mac_is_vrrp |
49
|
|
|
|
|
|
|
mac_is_hsrp mac_is_hsrp2 |
50
|
|
|
|
|
|
|
mac_is_msnlb |
51
|
|
|
|
|
|
|
mac_is_local mac_is_universal |
52
|
|
|
|
|
|
|
mac_as_basic mac_as_sun |
53
|
|
|
|
|
|
|
mac_as_microsoft mac_as_cisco |
54
|
|
|
|
|
|
|
mac_as_bpr mac_as_ieee |
55
|
|
|
|
|
|
|
mac_as_ipv6_suffix |
56
|
|
|
|
|
|
|
mac_as_tokenring mac_as_singledash |
57
|
|
|
|
|
|
|
mac_as_pgsql |
58
|
|
|
|
|
|
|
) |
59
|
|
|
|
|
|
|
], |
60
|
|
|
|
|
|
|
properties => [ |
61
|
|
|
|
|
|
|
qw( |
62
|
|
|
|
|
|
|
mac_is_eui48 mac_is_eui64 |
63
|
|
|
|
|
|
|
mac_is_unicast mac_is_multicast |
64
|
|
|
|
|
|
|
mac_is_broadcast mac_is_vrrp |
65
|
|
|
|
|
|
|
mac_is_hsrp mac_is_hsrp2 |
66
|
|
|
|
|
|
|
mac_is_msnlb |
67
|
|
|
|
|
|
|
mac_is_local mac_is_universal |
68
|
|
|
|
|
|
|
) |
69
|
|
|
|
|
|
|
], |
70
|
|
|
|
|
|
|
normals => [ |
71
|
|
|
|
|
|
|
qw( |
72
|
|
|
|
|
|
|
mac_as_basic mac_as_sun |
73
|
|
|
|
|
|
|
mac_as_microsoft mac_as_cisco |
74
|
|
|
|
|
|
|
mac_as_bpr mac_as_ieee |
75
|
|
|
|
|
|
|
mac_as_ipv6_suffix |
76
|
|
|
|
|
|
|
mac_as_tokenring mac_as_singledash |
77
|
|
|
|
|
|
|
mac_as_pgsql |
78
|
|
|
|
|
|
|
) |
79
|
|
|
|
|
|
|
], |
80
|
|
|
|
|
|
|
); |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
Exporter::export_ok_tags( keys %EXPORT_TAGS ); |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub new { |
86
|
|
|
|
|
|
|
|
87
|
16
|
|
|
16
|
1
|
7773
|
my ( $p, @q ) = @_; |
88
|
16
|
|
33
|
|
|
54
|
my $c = ref($p) || $p; |
89
|
16
|
|
|
|
|
29
|
my $self = bless {}, $c; |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
# clear the errstr, see also RT96045 |
92
|
16
|
|
|
|
|
21
|
$NetAddr::MAC::errstr = undef; |
93
|
|
|
|
|
|
|
|
94
|
16
|
100
|
|
|
|
30
|
unless (@q) { |
95
|
1
|
|
|
|
|
2
|
my $e = q|Please provide a mac address|; |
96
|
1
|
50
|
|
|
|
79
|
croak "$e\n" if $NetAddr::MAC::die_on_error; |
97
|
0
|
|
|
|
|
0
|
$NetAddr::MAC::errstr = $e; |
98
|
|
|
|
|
|
|
return |
99
|
0
|
|
|
|
|
0
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
# massage a single argument into a mac argument if needed |
102
|
15
|
50
|
|
|
|
44
|
$self->_init( @q % 2 ? ( mac => shift @q, @q ) : @q ) |
|
|
100
|
|
|
|
|
|
103
|
|
|
|
|
|
|
or return; |
104
|
|
|
|
|
|
|
|
105
|
3
|
|
|
|
|
7
|
return $self |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
{ |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
my $_die; |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub _init { |
114
|
|
|
|
|
|
|
|
115
|
15
|
|
|
15
|
|
33
|
my ( $self, %args ) = @_; |
116
|
|
|
|
|
|
|
|
117
|
15
|
50
|
|
|
|
24
|
if ( defined $args{die_on_error} ) { |
118
|
0
|
0
|
|
|
|
0
|
$self->{_die}++ if $args{die_on_error}; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
else { |
121
|
15
|
100
|
|
|
|
41
|
$self->{_die}++ if $NetAddr::MAC::die_on_error; |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
15
|
100
|
|
|
|
25
|
$_die++ if $self->{_die}; |
125
|
|
|
|
|
|
|
|
126
|
15
|
|
|
|
|
26
|
$self->{original} = $args{mac}; |
127
|
|
|
|
|
|
|
|
128
|
15
|
100
|
|
|
|
37
|
if ($args{mac} =~ m/^(\d+)\#(.+)$/ ) { |
129
|
1
|
|
|
|
|
3
|
$self->{priority} = $1; |
130
|
1
|
|
|
|
|
2
|
$args{mac} = $2; |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
|
133
|
15
|
|
|
|
|
27
|
$self->{mac} = _mac_to_integers( $args{mac} ); |
134
|
|
|
|
|
|
|
|
135
|
4
|
100
|
|
|
|
9
|
unless ( $self->{mac} ) { |
136
|
1
|
50
|
|
|
|
2
|
croak $NetAddr::MAC::errstr . "\n" if $self->{_die}; |
137
|
|
|
|
|
|
|
return |
138
|
1
|
|
|
|
|
4
|
} |
139
|
|
|
|
|
|
|
|
140
|
3
|
100
|
|
|
|
4
|
if (defined $self->{priority}) { |
141
|
1
|
50
|
33
|
|
|
3
|
if ($args{priority} and $args{priority} != $self->{priority}) { |
142
|
0
|
|
|
|
|
0
|
my $e = "Conflicting priority in '$self->{original}' and priority argument $args{priority}"; |
143
|
0
|
0
|
|
|
|
0
|
croak "$e\n" if $self->{_die}; |
144
|
0
|
|
|
|
|
0
|
$NetAddr::MAC::errstr = $e; |
145
|
|
|
|
|
|
|
return |
146
|
0
|
|
|
|
|
0
|
} |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
else { |
149
|
2
|
|
50
|
|
|
7
|
$self->{priority} = $args{priority} || 0; |
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
# check none of the list elements are empty |
153
|
3
|
50
|
|
18
|
|
8
|
if (first { not defined $_ or 0 == length $_} @{$self->{mac}}) { |
|
18
|
50
|
|
|
|
39
|
|
|
3
|
|
|
|
|
7
|
|
154
|
0
|
|
|
|
|
0
|
my $e = "Invalid MAC format '$self->{original}'"; |
155
|
0
|
0
|
|
|
|
0
|
croak "$e\n" if $self->{_die}; |
156
|
0
|
|
|
|
|
0
|
$NetAddr::MAC::errstr = $e; |
157
|
|
|
|
|
|
|
return |
158
|
0
|
|
|
|
|
0
|
} |
159
|
|
|
|
|
|
|
|
160
|
3
|
|
|
|
|
10
|
return 1 |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
} |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
sub _mac_to_integers { |
165
|
|
|
|
|
|
|
|
166
|
295
|
|
|
295
|
|
572
|
my $mac = shift; |
167
|
295
|
|
|
|
|
483
|
my $e; |
168
|
|
|
|
|
|
|
|
169
|
295
|
|
|
|
|
659
|
for (1) { |
170
|
|
|
|
|
|
|
|
171
|
295
|
100
|
|
|
|
737
|
unless ($mac) { |
172
|
1
|
|
|
|
|
1
|
$e = 'Please provide a mac address'; |
173
|
1
|
|
|
|
|
2
|
last; |
174
|
|
|
|
|
|
|
} |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
# be nice, strip leading and trailing whitespace |
177
|
294
|
|
|
|
|
971
|
$mac =~ s/^\s+//; |
178
|
294
|
|
|
|
|
721
|
$mac =~ s/\s+$//; |
179
|
|
|
|
|
|
|
|
180
|
294
|
|
|
|
|
563
|
$mac =~ s{^1,\d,}{} |
181
|
|
|
|
|
|
|
; # blindly remove the prefix from bpr, we could check that \d is the actual length, but oh well |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
# avoid matching ipv6 |
184
|
294
|
100
|
|
|
|
860
|
last if $mac =~ m/[a-f0-9]{1,4}:[a-f0-9]{1,4}::([a-f0-9]{1,4})?/i; |
185
|
289
|
100
|
|
|
|
761
|
last if $mac =~ m/[a-f0-9]{1,4}::[a-f0-9]{1,4}:[a-f0-9]{1,4}/i; |
186
|
|
|
|
|
|
|
|
187
|
287
|
|
|
|
|
1574
|
my @parts = grep { length } split( /[^a-z0-9]+/ix, $mac ); |
|
975
|
|
|
|
|
2483
|
|
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
# anything other than hex... |
190
|
287
|
100
|
|
942
|
|
1806
|
last if ( first { m{[^a-f0-9]}i } @parts ); |
|
942
|
|
|
|
|
2513
|
|
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
# resolve wierd things like aabb.cc.00.11.22 or 11.22.33.aabbcc |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
@parts = map { |
195
|
269
|
|
|
|
|
1086
|
my $o = $_; |
|
894
|
|
|
|
|
1792
|
|
196
|
894
|
100
|
|
|
|
4607
|
(length($o) % 2) == 0 ? $o =~ m/(..)/g |
197
|
|
|
|
|
|
|
: $o |
198
|
|
|
|
|
|
|
} @parts; |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
# 12 characters for EUI48, 16 for EUI64 |
201
|
269
|
0
|
0
|
|
|
805
|
if ( |
|
|
|
33
|
|
|
|
|
202
|
|
|
|
|
|
|
@parts == 1 |
203
|
|
|
|
|
|
|
&& ( length $parts[0] == EUI48LENGTHHEX |
204
|
|
|
|
|
|
|
|| length $parts[0] == EUI64LENGTHHEX ) |
205
|
|
|
|
|
|
|
) |
206
|
|
|
|
|
|
|
{ # 0019e3010e72 |
207
|
0
|
|
|
|
|
0
|
local $_ = shift(@parts); |
208
|
0
|
|
|
|
|
0
|
while (m{([a-f0-9]{2})}igx) { push( @parts, $1 ) } |
|
0
|
|
|
|
|
0
|
|
209
|
0
|
|
|
|
|
0
|
return [ map { hex($_) } @parts ] |
|
0
|
|
|
|
|
0
|
|
210
|
|
|
|
|
|
|
} |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
# 00:19:e3:01:0e:72 |
213
|
269
|
100
|
100
|
|
|
912
|
if ( @parts == EUI48LENGTHDEC || @parts == EUI64LENGTHDEC ) { |
214
|
263
|
|
|
|
|
521
|
return [ map { hex($_) } @parts ] |
|
1728
|
|
|
|
|
3742
|
|
215
|
|
|
|
|
|
|
} |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
# 0019:e301:0e72 |
218
|
6
|
100
|
66
|
|
|
19
|
if ( @parts == EUI48LENGTHDEC / 2 || @parts == EUI64LENGTHDEC / 2 ) |
219
|
|
|
|
|
|
|
{ |
220
|
|
|
|
|
|
|
# it would be nice to accept no leading 0's but this gives |
221
|
|
|
|
|
|
|
# problems detecting broken formatted macs. |
222
|
|
|
|
|
|
|
# cisco doesnt drop leading zeros so lets go for the least |
223
|
|
|
|
|
|
|
# edgey of the edge cases. |
224
|
1
|
50
|
|
1
|
|
4
|
last if (first {length $_ < 4} @parts); |
|
1
|
|
|
|
|
4
|
|
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
return [ |
227
|
|
|
|
|
|
|
map { |
228
|
0
|
0
|
|
|
|
0
|
m{^ ([a-f0-9]{2}) ([a-f0-9]{2}) $}ix |
|
0
|
|
|
|
|
0
|
|
229
|
|
|
|
|
|
|
&& ( hex($1), hex($2) ) |
230
|
|
|
|
|
|
|
} @parts |
231
|
|
|
|
|
|
|
]; |
232
|
|
|
|
|
|
|
} |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
last |
235
|
|
|
|
|
|
|
|
236
|
5
|
|
|
|
|
8
|
} # just so we can jump out |
237
|
|
|
|
|
|
|
|
238
|
32
|
|
66
|
|
|
166
|
$e ||= "Invalid MAC format '$mac'"; |
239
|
|
|
|
|
|
|
|
240
|
32
|
100
|
|
|
|
59
|
if ( defined $_die ) { |
|
|
100
|
|
|
|
|
|
241
|
11
|
50
|
|
|
|
1018
|
croak "$e\n" if $_die; |
242
|
|
|
|
|
|
|
} |
243
|
|
|
|
|
|
|
elsif ($NetAddr::MAC::die_on_error) { |
244
|
20
|
|
|
|
|
1739
|
croak "$e\n"; |
245
|
|
|
|
|
|
|
} |
246
|
|
|
|
|
|
|
|
247
|
1
|
|
|
|
|
2
|
$NetAddr::MAC::errstr = $e; |
248
|
|
|
|
|
|
|
|
249
|
|
|
|
|
|
|
return |
250
|
1
|
|
|
|
|
2
|
} |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
} |
253
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
sub original { |
256
|
|
|
|
|
|
|
|
257
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
258
|
|
|
|
|
|
|
return $self->{original} |
259
|
|
|
|
|
|
|
|
260
|
0
|
|
|
|
|
0
|
} |
261
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
sub oui { |
264
|
|
|
|
|
|
|
|
265
|
1
|
|
|
1
|
1
|
218
|
my $self = shift; |
266
|
|
|
|
|
|
|
return uc join( |
267
|
|
|
|
|
|
|
q{-}, |
268
|
3
|
|
|
|
|
11
|
map { sprintf( '%02x', $_ ) } |
269
|
1
|
|
|
|
|
2
|
@{ $self->{mac} }[0 .. 2] |
|
1
|
|
|
|
|
3
|
|
270
|
|
|
|
|
|
|
); |
271
|
|
|
|
|
|
|
|
272
|
|
|
|
|
|
|
} |
273
|
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
|
275
|
|
|
|
|
|
|
sub errstr { |
276
|
|
|
|
|
|
|
|
277
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
278
|
0
|
0
|
|
|
|
0
|
return $NetAddr::MAC::errstr unless ref $self; |
279
|
|
|
|
|
|
|
return $self->{_errstr} |
280
|
|
|
|
|
|
|
|
281
|
0
|
|
|
|
|
0
|
} |
282
|
|
|
|
|
|
|
|
283
|
|
|
|
|
|
|
|
284
|
|
|
|
|
|
|
sub is_eui48 { |
285
|
145
|
|
|
145
|
1
|
192
|
my $self = shift; |
286
|
145
|
|
|
|
|
167
|
return scalar @{ $self->{mac} } == EUI48LENGTHDEC |
|
145
|
|
|
|
|
1389
|
|
287
|
|
|
|
|
|
|
} |
288
|
|
|
|
|
|
|
|
289
|
|
|
|
|
|
|
|
290
|
|
|
|
|
|
|
sub is_eui64 { |
291
|
21
|
|
|
21
|
1
|
38
|
my $self = shift; |
292
|
21
|
|
|
|
|
28
|
return scalar @{ $self->{mac} } == EUI64LENGTHDEC |
|
21
|
|
|
|
|
109
|
|
293
|
|
|
|
|
|
|
} |
294
|
|
|
|
|
|
|
|
295
|
|
|
|
|
|
|
|
296
|
|
|
|
|
|
|
sub is_multicast { |
297
|
15
|
|
|
15
|
1
|
27
|
my $self = shift; |
298
|
|
|
|
|
|
|
|
299
|
15
|
|
100
|
|
|
129
|
return ($self->{mac}->[0] & 1) && ! is_broadcast($self); |
300
|
|
|
|
|
|
|
} |
301
|
|
|
|
|
|
|
|
302
|
|
|
|
|
|
|
|
303
|
|
|
|
|
|
|
|
304
|
|
|
|
|
|
|
sub is_broadcast { |
305
|
22
|
|
|
22
|
1
|
36
|
my $self = shift; |
306
|
|
|
|
|
|
|
|
307
|
22
|
|
|
|
|
38
|
for (@{$self->{mac}}) { |
|
22
|
|
|
|
|
58
|
|
308
|
32
|
100
|
|
|
|
135
|
return 0 if $_ != 255 |
309
|
|
|
|
|
|
|
} |
310
|
2
|
|
|
|
|
14
|
return 1 |
311
|
|
|
|
|
|
|
} |
312
|
|
|
|
|
|
|
|
313
|
|
|
|
|
|
|
|
314
|
|
|
|
|
|
|
sub is_vrrp { |
315
|
31
|
|
|
31
|
1
|
48
|
my $self = shift; |
316
|
|
|
|
|
|
|
|
317
|
|
|
|
|
|
|
return |
318
|
|
|
|
|
|
|
is_eui48($self) && |
319
|
|
|
|
|
|
|
$self->{mac}->[0] == 0 && |
320
|
|
|
|
|
|
|
$self->{mac}->[1] == 0 && |
321
|
|
|
|
|
|
|
$self->{mac}->[2] == hex('0x5e') && |
322
|
|
|
|
|
|
|
$self->{mac}->[3] == 0 && |
323
|
31
|
|
66
|
|
|
53
|
$self->{mac}->[4] == 1; |
324
|
|
|
|
|
|
|
|
325
|
|
|
|
|
|
|
} |
326
|
|
|
|
|
|
|
|
327
|
|
|
|
|
|
|
|
328
|
|
|
|
|
|
|
sub is_hsrp { |
329
|
31
|
|
|
31
|
1
|
46
|
my $self = shift; |
330
|
|
|
|
|
|
|
|
331
|
|
|
|
|
|
|
return |
332
|
|
|
|
|
|
|
is_eui48($self) && |
333
|
|
|
|
|
|
|
$self->{mac}->[0] == 0 && |
334
|
|
|
|
|
|
|
$self->{mac}->[1] == 0 && |
335
|
|
|
|
|
|
|
$self->{mac}->[2] == hex('0xc') && |
336
|
|
|
|
|
|
|
$self->{mac}->[3] == 7 && |
337
|
31
|
|
66
|
|
|
58
|
$self->{mac}->[4] == hex('0xac'); |
338
|
|
|
|
|
|
|
|
339
|
|
|
|
|
|
|
} |
340
|
|
|
|
|
|
|
|
341
|
|
|
|
|
|
|
|
342
|
|
|
|
|
|
|
sub is_hsrp2 { |
343
|
31
|
|
|
31
|
1
|
69
|
my $self = shift; |
344
|
|
|
|
|
|
|
|
345
|
|
|
|
|
|
|
return |
346
|
|
|
|
|
|
|
is_eui48($self) && |
347
|
|
|
|
|
|
|
$self->{mac}->[0] == 0 && |
348
|
|
|
|
|
|
|
$self->{mac}->[1] == 0 && |
349
|
|
|
|
|
|
|
$self->{mac}->[2] == hex('0xc') && |
350
|
31
|
|
100
|
|
|
54
|
$self->{mac}->[3] == hex('0x9f'); |
351
|
0
|
|
|
|
|
0
|
$self->{mac}->[4] >= 240; # 0xFX |
352
|
|
|
|
|
|
|
|
353
|
|
|
|
|
|
|
} |
354
|
|
|
|
|
|
|
|
355
|
|
|
|
|
|
|
|
356
|
|
|
|
|
|
|
|
357
|
|
|
|
|
|
|
sub is_msnlb { |
358
|
31
|
|
|
31
|
1
|
47
|
my $self = shift; |
359
|
|
|
|
|
|
|
|
360
|
|
|
|
|
|
|
return |
361
|
|
|
|
|
|
|
is_eui48($self) && |
362
|
|
|
|
|
|
|
($self->{mac}->[0] == 2 |
363
|
|
|
|
|
|
|
|| $self->{mac}->[0] == 3) && |
364
|
31
|
|
66
|
|
|
52
|
$self->{mac}->[1] == hex('0xbf') |
365
|
|
|
|
|
|
|
|
366
|
|
|
|
|
|
|
} |
367
|
|
|
|
|
|
|
|
368
|
|
|
|
|
|
|
|
369
|
|
|
|
|
|
|
sub is_unicast { |
370
|
15
|
|
|
15
|
1
|
30
|
my $self = shift; |
371
|
15
|
|
|
|
|
94
|
return ! ($self->{mac}->[0] & 1); |
372
|
|
|
|
|
|
|
} |
373
|
|
|
|
|
|
|
|
374
|
|
|
|
|
|
|
|
375
|
|
|
|
|
|
|
sub is_local { |
376
|
40
|
|
|
40
|
1
|
59
|
my $self = shift; |
377
|
40
|
|
|
|
|
243
|
return $self->{mac}->[0] & 2 |
378
|
|
|
|
|
|
|
} |
379
|
|
|
|
|
|
|
|
380
|
|
|
|
|
|
|
|
381
|
|
|
|
|
|
|
sub is_universal { |
382
|
20
|
|
|
20
|
1
|
29
|
my $self = shift; |
383
|
20
|
|
|
|
|
40
|
return !is_local($self) |
384
|
|
|
|
|
|
|
} |
385
|
|
|
|
|
|
|
|
386
|
|
|
|
|
|
|
|
387
|
|
|
|
|
|
|
sub as_basic { |
388
|
1
|
|
|
1
|
1
|
2
|
my $self = shift; |
389
|
1
|
|
|
|
|
2
|
return join( q{}, map { sprintf( '%02x', $_ ) } @{ $self->{mac} } ) |
|
6
|
|
|
|
|
17
|
|
|
1
|
|
|
|
|
3
|
|
390
|
|
|
|
|
|
|
} |
391
|
|
|
|
|
|
|
|
392
|
|
|
|
|
|
|
|
393
|
|
|
|
|
|
|
sub as_bridge_id { |
394
|
1
|
|
|
1
|
1
|
588
|
my $self = shift; |
395
|
|
|
|
|
|
|
return $self->{priority} |
396
|
1
|
|
|
|
|
4
|
. '#' |
397
|
|
|
|
|
|
|
. $self->as_cisco; |
398
|
|
|
|
|
|
|
} |
399
|
|
|
|
|
|
|
|
400
|
|
|
|
|
|
|
|
401
|
|
|
|
|
|
|
sub as_bpr { |
402
|
1
|
|
|
1
|
1
|
2
|
my $self = shift; |
403
|
|
|
|
|
|
|
return |
404
|
|
|
|
|
|
|
q{1,} |
405
|
1
|
|
|
|
|
4
|
. scalar @{ $self->{mac} } . q{,} |
406
|
1
|
|
|
|
|
1
|
. join( q{:}, map { sprintf( '%02x', $_ ) } @{ $self->{mac} } ); |
|
6
|
|
|
|
|
16
|
|
|
1
|
|
|
|
|
3
|
|
407
|
|
|
|
|
|
|
} |
408
|
|
|
|
|
|
|
|
409
|
|
|
|
|
|
|
|
410
|
|
|
|
|
|
|
sub as_cisco { |
411
|
2
|
|
|
2
|
1
|
3
|
my $self = shift; |
412
|
|
|
|
|
|
|
return join( q{.}, |
413
|
2
|
|
|
|
|
18
|
map { m{([a-f0-9]{4})}gxi } |
414
|
2
|
|
|
|
|
4
|
join( q{}, map { sprintf( '%02x', $_ ) } @{ $self->{mac} } ) ) |
|
12
|
|
|
|
|
25
|
|
|
2
|
|
|
|
|
5
|
|
415
|
|
|
|
|
|
|
} |
416
|
|
|
|
|
|
|
|
417
|
|
|
|
|
|
|
|
418
|
|
|
|
|
|
|
sub as_ieee { |
419
|
1
|
|
|
1
|
1
|
1
|
my $self = shift; |
420
|
1
|
|
|
|
|
1
|
return join( q{:}, map { sprintf( '%02x', $_ ) } @{ $self->{mac} } ) |
|
6
|
|
|
|
|
14
|
|
|
1
|
|
|
|
|
3
|
|
421
|
|
|
|
|
|
|
} |
422
|
|
|
|
|
|
|
|
423
|
|
|
|
|
|
|
|
424
|
|
|
|
|
|
|
sub as_ipv6_suffix { |
425
|
|
|
|
|
|
|
|
426
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
427
|
0
|
|
|
|
|
0
|
my @tmpmac; |
428
|
|
|
|
|
|
|
|
429
|
|
|
|
|
|
|
# be slightly evil here, so that hashrefs and objects work |
430
|
0
|
0
|
|
|
|
0
|
if ( is_eui48($self) ) { |
431
|
|
|
|
|
|
|
|
432
|
|
|
|
|
|
|
# save this for later |
433
|
0
|
|
|
|
|
0
|
@tmpmac = @{ $self->{mac} }; |
|
0
|
|
|
|
|
0
|
|
434
|
|
|
|
|
|
|
|
435
|
0
|
|
|
|
|
0
|
to_eui64($self); |
436
|
|
|
|
|
|
|
|
437
|
|
|
|
|
|
|
} |
438
|
|
|
|
|
|
|
|
439
|
0
|
|
|
|
|
0
|
my @suffix = ( @{ $self->{mac} }[0] ^ 0x02, @{ $self->{mac} }[ 1 .. 7 ] ); |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
440
|
|
|
|
|
|
|
|
441
|
|
|
|
|
|
|
# restore the eui48 if needed |
442
|
0
|
0
|
|
|
|
0
|
$self->{mac} = \@tmpmac if @tmpmac; |
443
|
|
|
|
|
|
|
|
444
|
|
|
|
|
|
|
return join( |
445
|
|
|
|
|
|
|
q{:}, |
446
|
|
|
|
|
|
|
map { |
447
|
0
|
|
|
|
|
0
|
my $i = $_; |
|
0
|
|
|
|
|
0
|
|
448
|
0
|
|
|
|
|
0
|
$i *= 2; |
449
|
0
|
|
|
|
|
0
|
sprintf( '%02x%02x', $suffix[$i], $suffix[ $i + 1 ] ) |
450
|
|
|
|
|
|
|
} 0 .. 3 |
451
|
|
|
|
|
|
|
); |
452
|
|
|
|
|
|
|
} |
453
|
|
|
|
|
|
|
|
454
|
|
|
|
|
|
|
|
455
|
|
|
|
|
|
|
sub as_microsoft { |
456
|
1
|
|
|
1
|
1
|
2
|
my $self = shift; |
457
|
1
|
|
|
|
|
1
|
return join( q{-}, map { sprintf( '%02x', $_ ) } @{ $self->{mac} } ) |
|
6
|
|
|
|
|
15
|
|
|
1
|
|
|
|
|
2
|
|
458
|
|
|
|
|
|
|
} |
459
|
|
|
|
|
|
|
|
460
|
|
|
|
|
|
|
|
461
|
|
|
|
|
|
|
sub as_pgsql { |
462
|
1
|
|
|
1
|
1
|
1
|
my $self = shift; |
463
|
|
|
|
|
|
|
|
464
|
|
|
|
|
|
|
# there may be a better way to do this |
465
|
1
|
|
|
|
|
2
|
my $len = scalar @{ $self->{mac} }; |
|
1
|
|
|
|
|
2
|
|
466
|
|
|
|
|
|
|
return join( |
467
|
|
|
|
|
|
|
q{:}, |
468
|
|
|
|
|
|
|
join( '', |
469
|
3
|
|
|
|
|
10
|
map { sprintf( '%02x', $_ ) } |
470
|
1
|
|
|
|
|
2
|
@{ $self->{mac} }[ 0 .. ( $len / 2 - 1 ) ] ), |
471
|
|
|
|
|
|
|
join( '', |
472
|
3
|
|
|
|
|
13
|
map { sprintf( '%02x', $_ ) } |
473
|
1
|
|
|
|
|
3
|
@{ $self->{mac} }[ ( $len / 2 ) .. ( $len - 1 ) ] ), |
|
1
|
|
|
|
|
2
|
|
474
|
|
|
|
|
|
|
); |
475
|
|
|
|
|
|
|
} |
476
|
|
|
|
|
|
|
|
477
|
|
|
|
|
|
|
|
478
|
|
|
|
|
|
|
sub as_singledash { |
479
|
1
|
|
|
1
|
1
|
2
|
my $self = shift; |
480
|
|
|
|
|
|
|
|
481
|
|
|
|
|
|
|
# there may be a better way to do this |
482
|
1
|
|
|
|
|
1
|
my $len = scalar @{ $self->{mac} }; |
|
1
|
|
|
|
|
2
|
|
483
|
|
|
|
|
|
|
return join( |
484
|
|
|
|
|
|
|
q{-}, |
485
|
|
|
|
|
|
|
join( '', |
486
|
3
|
|
|
|
|
8
|
map { sprintf( '%02x', $_ ) } |
487
|
1
|
|
|
|
|
3
|
@{ $self->{mac} }[ 0 .. ( $len / 2 - 1 ) ] ), |
488
|
|
|
|
|
|
|
join( '', |
489
|
3
|
|
|
|
|
9
|
map { sprintf( '%02x', $_ ) } |
490
|
1
|
|
|
|
|
4
|
@{ $self->{mac} }[ ( $len / 2 ) .. ( $len - 1 ) ] ), |
|
1
|
|
|
|
|
3
|
|
491
|
|
|
|
|
|
|
); |
492
|
|
|
|
|
|
|
} |
493
|
|
|
|
|
|
|
|
494
|
|
|
|
|
|
|
|
495
|
|
|
|
|
|
|
sub as_sun { |
496
|
1
|
|
|
1
|
1
|
2
|
my $self = shift; |
497
|
1
|
|
|
|
|
1
|
return join( q{-}, map { sprintf( '%01x', $_ ) } @{ $self->{mac} } ) |
|
6
|
|
|
|
|
15
|
|
|
1
|
|
|
|
|
2
|
|
498
|
|
|
|
|
|
|
} |
499
|
|
|
|
|
|
|
|
500
|
|
|
|
|
|
|
|
501
|
|
|
|
|
|
|
sub as_tokenring { |
502
|
|
|
|
|
|
|
|
503
|
1
|
|
|
1
|
1
|
1
|
my $self = shift; |
504
|
1
|
|
|
|
|
2
|
return join( q{-}, map { (ETHER2TOKEN)[$_] } @{ $self->{mac} } ) |
|
6
|
|
|
|
|
15
|
|
|
1
|
|
|
|
|
3
|
|
505
|
|
|
|
|
|
|
} |
506
|
|
|
|
|
|
|
|
507
|
|
|
|
|
|
|
|
508
|
|
|
|
|
|
|
sub to_eui48 { |
509
|
|
|
|
|
|
|
|
510
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
511
|
|
|
|
|
|
|
|
512
|
|
|
|
|
|
|
# be slightly evil here, so that hashrefs and objects work |
513
|
0
|
0
|
|
|
|
0
|
if ( is_eui64($self) ) { |
514
|
0
|
0
|
0
|
|
|
0
|
if ( @{ $self->{mac} }[3] == 0xff |
|
0
|
|
0
|
|
|
0
|
|
515
|
|
|
|
|
|
|
and |
516
|
|
|
|
|
|
|
( @{ $self->{mac} }[4] == 0xff or @{ $self->{mac} }[4] == 0xfe ) ) |
517
|
|
|
|
|
|
|
{ |
518
|
|
|
|
|
|
|
|
519
|
|
|
|
|
|
|
# convert to eui-48 |
520
|
0
|
|
|
|
|
0
|
$self->{mac} = [ @{ $self->{mac} }[ 0 .. 2, 5 .. 7 ] ]; |
|
0
|
|
|
|
|
0
|
|
521
|
|
|
|
|
|
|
} |
522
|
|
|
|
|
|
|
else { |
523
|
0
|
|
|
|
|
0
|
my $e = 'eui-64 address is not derived from an eui-48 address'; |
524
|
0
|
0
|
|
|
|
0
|
croak "$e\n" if $self->{_die}; |
525
|
0
|
|
|
|
|
0
|
$self->{_errstr} = $e; |
526
|
|
|
|
|
|
|
return |
527
|
0
|
|
|
|
|
0
|
} |
528
|
|
|
|
|
|
|
} |
529
|
|
|
|
|
|
|
|
530
|
0
|
|
|
|
|
0
|
return 1 |
531
|
|
|
|
|
|
|
} |
532
|
|
|
|
|
|
|
|
533
|
|
|
|
|
|
|
|
534
|
|
|
|
|
|
|
sub to_eui64 { |
535
|
|
|
|
|
|
|
|
536
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
537
|
|
|
|
|
|
|
|
538
|
|
|
|
|
|
|
# be slightly evil here so that hashrefs and objects work |
539
|
0
|
0
|
|
|
|
0
|
if ( is_eui48($self) ) { |
540
|
|
|
|
|
|
|
|
541
|
|
|
|
|
|
|
# convert to EUI64 |
542
|
|
|
|
|
|
|
$self->{mac} = [ |
543
|
0
|
|
|
|
|
0
|
@{ $self->{mac} }[ 0 .. 2 ], |
544
|
|
|
|
|
|
|
0xff, |
545
|
|
|
|
|
|
|
0xfe, |
546
|
0
|
|
|
|
|
0
|
@{ $self->{mac} }[ 3 .. 5 ] |
|
0
|
|
|
|
|
0
|
|
547
|
|
|
|
|
|
|
]; |
548
|
|
|
|
|
|
|
|
549
|
|
|
|
|
|
|
} |
550
|
0
|
|
|
|
|
0
|
else { return } |
551
|
|
|
|
|
|
|
|
552
|
0
|
|
|
|
|
0
|
return 1 |
553
|
|
|
|
|
|
|
} |
554
|
|
|
|
|
|
|
|
555
|
|
|
|
|
|
|
|
556
|
|
|
|
|
|
|
sub mac_is_eui48 { |
557
|
|
|
|
|
|
|
|
558
|
31
|
|
|
31
|
1
|
18680
|
my $mac = shift; |
559
|
31
|
50
|
|
|
|
96
|
croak 'please use is_eui48' |
560
|
|
|
|
|
|
|
if ref $mac eq __PACKAGE__; |
561
|
31
|
50
|
|
|
|
65
|
if ( ref $mac ) { |
562
|
0
|
|
|
|
|
0
|
my $e = 'argument must be a string'; |
563
|
0
|
0
|
|
|
|
0
|
croak "$e\n" if $NetAddr::MAC::die_on_error; |
564
|
0
|
|
|
|
|
0
|
$NetAddr::MAC::errstr = $e; |
565
|
|
|
|
|
|
|
return |
566
|
0
|
|
|
|
|
0
|
} |
567
|
|
|
|
|
|
|
|
568
|
31
|
50
|
|
|
|
67
|
$mac = _mac_to_integers($mac) or return; |
569
|
21
|
|
|
|
|
74
|
return is_eui48( { mac => $mac } ) |
570
|
|
|
|
|
|
|
|
571
|
|
|
|
|
|
|
} |
572
|
|
|
|
|
|
|
|
573
|
|
|
|
|
|
|
|
574
|
|
|
|
|
|
|
sub mac_is_eui64 { |
575
|
|
|
|
|
|
|
|
576
|
31
|
|
|
31
|
1
|
18389
|
my $mac = shift; |
577
|
31
|
50
|
|
|
|
98
|
croak 'please use is_eui64' |
578
|
|
|
|
|
|
|
if ref $mac eq __PACKAGE__; |
579
|
31
|
50
|
|
|
|
61
|
if ( ref $mac ) { |
580
|
0
|
|
|
|
|
0
|
my $e = 'argument must be a string'; |
581
|
0
|
0
|
|
|
|
0
|
croak "$e\n" if $NetAddr::MAC::die_on_error; |
582
|
0
|
|
|
|
|
0
|
$NetAddr::MAC::errstr = $e; |
583
|
|
|
|
|
|
|
return |
584
|
0
|
|
|
|
|
0
|
} |
585
|
|
|
|
|
|
|
|
586
|
31
|
50
|
|
|
|
67
|
$mac = _mac_to_integers($mac) or return; |
587
|
21
|
|
|
|
|
76
|
return is_eui64( { mac => $mac } ) |
588
|
|
|
|
|
|
|
|
589
|
|
|
|
|
|
|
} |
590
|
|
|
|
|
|
|
|
591
|
|
|
|
|
|
|
|
592
|
|
|
|
|
|
|
sub mac_is_multicast { |
593
|
|
|
|
|
|
|
|
594
|
15
|
|
|
15
|
1
|
1629
|
my $mac = shift; |
595
|
15
|
50
|
|
|
|
47
|
croak 'please use is_multicast' |
596
|
|
|
|
|
|
|
if ref $mac eq __PACKAGE__; |
597
|
15
|
50
|
|
|
|
37
|
if ( ref $mac ) { |
598
|
0
|
|
|
|
|
0
|
my $e = 'argument must be a string'; |
599
|
0
|
0
|
|
|
|
0
|
croak "$e\n" if $NetAddr::MAC::die_on_error; |
600
|
0
|
|
|
|
|
0
|
$NetAddr::MAC::errstr = $e; |
601
|
|
|
|
|
|
|
return |
602
|
0
|
|
|
|
|
0
|
} |
603
|
|
|
|
|
|
|
|
604
|
15
|
50
|
|
|
|
41
|
$mac = _mac_to_integers($mac) or return; |
605
|
15
|
|
|
|
|
60
|
return is_multicast( { mac => $mac } ) |
606
|
|
|
|
|
|
|
|
607
|
|
|
|
|
|
|
} |
608
|
|
|
|
|
|
|
|
609
|
|
|
|
|
|
|
|
610
|
|
|
|
|
|
|
|
611
|
|
|
|
|
|
|
sub mac_is_broadcast { |
612
|
|
|
|
|
|
|
|
613
|
15
|
|
|
15
|
1
|
292
|
my $mac = shift; |
614
|
15
|
50
|
|
|
|
47
|
croak 'please use is_broadcast' |
615
|
|
|
|
|
|
|
if ref $mac eq __PACKAGE__; |
616
|
15
|
50
|
|
|
|
36
|
if ( ref $mac ) { |
617
|
0
|
|
|
|
|
0
|
my $e = 'argument must be a string'; |
618
|
0
|
0
|
|
|
|
0
|
croak "$e\n" if $NetAddr::MAC::die_on_error; |
619
|
0
|
|
|
|
|
0
|
$NetAddr::MAC::errstr = $e; |
620
|
|
|
|
|
|
|
return |
621
|
0
|
|
|
|
|
0
|
} |
622
|
|
|
|
|
|
|
|
623
|
15
|
50
|
|
|
|
38
|
$mac = _mac_to_integers($mac) or return; |
624
|
15
|
|
|
|
|
62
|
return is_broadcast( { mac => $mac } ) |
625
|
|
|
|
|
|
|
|
626
|
|
|
|
|
|
|
} |
627
|
|
|
|
|
|
|
|
628
|
|
|
|
|
|
|
|
629
|
|
|
|
|
|
|
sub mac_is_unicast { |
630
|
|
|
|
|
|
|
|
631
|
15
|
|
|
15
|
1
|
2123
|
my $mac = shift; |
632
|
15
|
50
|
|
|
|
50
|
croak 'please use is_unicast' |
633
|
|
|
|
|
|
|
if ref $mac eq __PACKAGE__; |
634
|
15
|
50
|
|
|
|
36
|
if ( ref $mac ) { |
635
|
0
|
|
|
|
|
0
|
my $e = 'argument must be a string'; |
636
|
0
|
0
|
|
|
|
0
|
croak "$e\n" if $NetAddr::MAC::die_on_error; |
637
|
0
|
|
|
|
|
0
|
$NetAddr::MAC::errstr = $e; |
638
|
|
|
|
|
|
|
return |
639
|
0
|
|
|
|
|
0
|
} |
640
|
|
|
|
|
|
|
|
641
|
15
|
50
|
|
|
|
39
|
$mac = _mac_to_integers($mac) or return; |
642
|
15
|
|
|
|
|
59
|
return is_unicast( { mac => $mac } ) |
643
|
|
|
|
|
|
|
|
644
|
|
|
|
|
|
|
} |
645
|
|
|
|
|
|
|
|
646
|
|
|
|
|
|
|
|
647
|
|
|
|
|
|
|
sub mac_is_vrrp { |
648
|
|
|
|
|
|
|
|
649
|
31
|
|
|
31
|
1
|
4997
|
my $mac = shift; |
650
|
31
|
50
|
|
|
|
100
|
croak 'please use is_vrrp' |
651
|
|
|
|
|
|
|
if ref $mac eq __PACKAGE__; |
652
|
31
|
50
|
|
|
|
81
|
if ( ref $mac ) { |
653
|
0
|
|
|
|
|
0
|
my $e = 'argument must be a string'; |
654
|
0
|
0
|
|
|
|
0
|
croak "$e\n" if $NetAddr::MAC::die_on_error; |
655
|
0
|
|
|
|
|
0
|
$NetAddr::MAC::errstr = $e; |
656
|
|
|
|
|
|
|
|
657
|
|
|
|
|
|
|
return |
658
|
0
|
|
|
|
|
0
|
} |
659
|
|
|
|
|
|
|
|
660
|
31
|
50
|
|
|
|
76
|
$mac = _mac_to_integers($mac) or return; |
661
|
31
|
|
|
|
|
110
|
return is_vrrp( { mac => $mac } ) |
662
|
|
|
|
|
|
|
|
663
|
|
|
|
|
|
|
} |
664
|
|
|
|
|
|
|
|
665
|
|
|
|
|
|
|
|
666
|
|
|
|
|
|
|
|
667
|
|
|
|
|
|
|
sub mac_is_hsrp { |
668
|
|
|
|
|
|
|
|
669
|
31
|
|
|
31
|
1
|
1100
|
my $mac = shift; |
670
|
31
|
50
|
|
|
|
97
|
croak 'please use is_hsrp' |
671
|
|
|
|
|
|
|
if ref $mac eq __PACKAGE__; |
672
|
31
|
50
|
|
|
|
77
|
if ( ref $mac ) { |
673
|
0
|
|
|
|
|
0
|
my $e = 'argument must be a string'; |
674
|
0
|
0
|
|
|
|
0
|
croak "$e\n" if $NetAddr::MAC::die_on_error; |
675
|
0
|
|
|
|
|
0
|
$NetAddr::MAC::errstr = $e; |
676
|
|
|
|
|
|
|
|
677
|
|
|
|
|
|
|
return |
678
|
0
|
|
|
|
|
0
|
} |
679
|
|
|
|
|
|
|
|
680
|
31
|
50
|
|
|
|
89
|
$mac = _mac_to_integers($mac) or return; |
681
|
31
|
|
|
|
|
106
|
return is_hsrp( { mac => $mac } ) |
682
|
|
|
|
|
|
|
|
683
|
|
|
|
|
|
|
} |
684
|
|
|
|
|
|
|
|
685
|
|
|
|
|
|
|
|
686
|
|
|
|
|
|
|
sub mac_is_hsrp2 { |
687
|
|
|
|
|
|
|
|
688
|
31
|
|
|
31
|
1
|
1622
|
my $mac = shift; |
689
|
31
|
50
|
|
|
|
98
|
croak 'please use is_hsrp2' |
690
|
|
|
|
|
|
|
if ref $mac eq __PACKAGE__; |
691
|
31
|
50
|
|
|
|
76
|
if ( ref $mac ) { |
692
|
0
|
|
|
|
|
0
|
my $e = 'argument must be a string'; |
693
|
0
|
0
|
|
|
|
0
|
croak "$e\n" if $NetAddr::MAC::die_on_error; |
694
|
0
|
|
|
|
|
0
|
$NetAddr::MAC::errstr = $e; |
695
|
|
|
|
|
|
|
|
696
|
|
|
|
|
|
|
return |
697
|
0
|
|
|
|
|
0
|
} |
698
|
|
|
|
|
|
|
|
699
|
31
|
50
|
|
|
|
79
|
$mac = _mac_to_integers($mac) or return; |
700
|
31
|
|
|
|
|
109
|
return is_hsrp2( { mac => $mac } ) |
701
|
|
|
|
|
|
|
|
702
|
|
|
|
|
|
|
} |
703
|
|
|
|
|
|
|
|
704
|
|
|
|
|
|
|
|
705
|
|
|
|
|
|
|
sub mac_is_msnlb { |
706
|
|
|
|
|
|
|
|
707
|
31
|
|
|
31
|
1
|
588
|
my $mac = shift; |
708
|
31
|
50
|
|
|
|
105
|
croak 'please use is_msnlb' |
709
|
|
|
|
|
|
|
if ref $mac eq __PACKAGE__; |
710
|
31
|
50
|
|
|
|
75
|
if ( ref $mac ) { |
711
|
0
|
|
|
|
|
0
|
my $e = 'argument must be a string'; |
712
|
0
|
0
|
|
|
|
0
|
croak "$e\n" if $NetAddr::MAC::die_on_error; |
713
|
0
|
|
|
|
|
0
|
$NetAddr::MAC::errstr = $e; |
714
|
|
|
|
|
|
|
|
715
|
|
|
|
|
|
|
return |
716
|
0
|
|
|
|
|
0
|
} |
717
|
|
|
|
|
|
|
|
718
|
31
|
50
|
|
|
|
78
|
$mac = _mac_to_integers($mac) or return; |
719
|
31
|
|
|
|
|
106
|
return is_msnlb( { mac => $mac } ) |
720
|
|
|
|
|
|
|
|
721
|
|
|
|
|
|
|
} |
722
|
|
|
|
|
|
|
|
723
|
|
|
|
|
|
|
|
724
|
|
|
|
|
|
|
sub mac_is_local { |
725
|
|
|
|
|
|
|
|
726
|
20
|
|
|
20
|
1
|
2942
|
my $mac = shift; |
727
|
20
|
50
|
|
|
|
65
|
croak 'please use is_local' |
728
|
|
|
|
|
|
|
if ref $mac eq __PACKAGE__; |
729
|
20
|
50
|
|
|
|
50
|
if ( ref $mac ) { |
730
|
0
|
|
|
|
|
0
|
my $e = 'argument must be a string'; |
731
|
0
|
0
|
|
|
|
0
|
croak "$e\n" if $NetAddr::MAC::die_on_error; |
732
|
0
|
|
|
|
|
0
|
$NetAddr::MAC::errstr = $e; |
733
|
|
|
|
|
|
|
return |
734
|
0
|
|
|
|
|
0
|
} |
735
|
|
|
|
|
|
|
|
736
|
20
|
50
|
|
|
|
51
|
$mac = _mac_to_integers($mac) or return; |
737
|
20
|
|
|
|
|
74
|
return is_local( { mac => $mac } ) |
738
|
|
|
|
|
|
|
|
739
|
|
|
|
|
|
|
} |
740
|
|
|
|
|
|
|
|
741
|
|
|
|
|
|
|
|
742
|
|
|
|
|
|
|
sub mac_is_universal { |
743
|
|
|
|
|
|
|
|
744
|
20
|
|
|
20
|
1
|
2620
|
my $mac = shift; |
745
|
20
|
50
|
|
|
|
96
|
croak 'please use is_universal' |
746
|
|
|
|
|
|
|
if ref $mac eq __PACKAGE__; |
747
|
20
|
50
|
|
|
|
52
|
if ( ref $mac ) { |
748
|
0
|
|
|
|
|
0
|
my $e = 'argument must be a string'; |
749
|
0
|
0
|
|
|
|
0
|
croak "$e\n" if $NetAddr::MAC::die_on_error; |
750
|
0
|
|
|
|
|
0
|
$NetAddr::MAC::errstr = $e; |
751
|
|
|
|
|
|
|
return |
752
|
0
|
|
|
|
|
0
|
} |
753
|
|
|
|
|
|
|
|
754
|
20
|
50
|
|
|
|
51
|
$mac = _mac_to_integers($mac) or return; |
755
|
20
|
|
|
|
|
69
|
return is_universal( { mac => $mac } ) |
756
|
|
|
|
|
|
|
|
757
|
|
|
|
|
|
|
} |
758
|
|
|
|
|
|
|
|
759
|
|
|
|
|
|
|
|
760
|
|
|
|
|
|
|
sub mac_as_basic { |
761
|
|
|
|
|
|
|
|
762
|
1
|
|
|
1
|
1
|
64
|
my $mac = shift; |
763
|
1
|
50
|
|
|
|
4
|
croak 'please use as_basic' |
764
|
|
|
|
|
|
|
if ref $mac eq __PACKAGE__; |
765
|
1
|
50
|
|
|
|
2
|
if ( ref $mac ) { |
766
|
0
|
|
|
|
|
0
|
my $e = 'argument must be a string'; |
767
|
0
|
0
|
|
|
|
0
|
croak "$e\n" if $NetAddr::MAC::die_on_error; |
768
|
0
|
|
|
|
|
0
|
$NetAddr::MAC::errstr = $e; |
769
|
|
|
|
|
|
|
return |
770
|
0
|
|
|
|
|
0
|
} |
771
|
|
|
|
|
|
|
|
772
|
1
|
50
|
|
|
|
3
|
$mac = _mac_to_integers($mac) or return; |
773
|
1
|
|
|
|
|
3
|
return as_basic( { mac => $mac } ) |
774
|
|
|
|
|
|
|
|
775
|
|
|
|
|
|
|
} |
776
|
|
|
|
|
|
|
|
777
|
|
|
|
|
|
|
|
778
|
|
|
|
|
|
|
sub mac_as_bpr { |
779
|
|
|
|
|
|
|
|
780
|
1
|
|
|
1
|
1
|
3
|
my $mac = shift; |
781
|
1
|
50
|
|
|
|
3
|
croak 'please use as_basic' |
782
|
|
|
|
|
|
|
if ref $mac eq __PACKAGE__; |
783
|
1
|
50
|
|
|
|
3
|
if ( ref $mac ) { |
784
|
0
|
|
|
|
|
0
|
my $e = 'argument must be a string'; |
785
|
0
|
0
|
|
|
|
0
|
croak "$e\n" if $NetAddr::MAC::die_on_error; |
786
|
0
|
|
|
|
|
0
|
$NetAddr::MAC::errstr = $e; |
787
|
|
|
|
|
|
|
return |
788
|
0
|
|
|
|
|
0
|
} |
789
|
|
|
|
|
|
|
|
790
|
1
|
50
|
|
|
|
2
|
$mac = _mac_to_integers($mac) or return; |
791
|
1
|
|
|
|
|
4
|
return as_bpr( { mac => $mac } ) |
792
|
|
|
|
|
|
|
|
793
|
|
|
|
|
|
|
} |
794
|
|
|
|
|
|
|
|
795
|
|
|
|
|
|
|
|
796
|
|
|
|
|
|
|
sub mac_as_cisco { |
797
|
|
|
|
|
|
|
|
798
|
1
|
|
|
1
|
1
|
2
|
my $mac = shift; |
799
|
1
|
50
|
|
|
|
4
|
croak 'please use as_cisco' |
800
|
|
|
|
|
|
|
if ref $mac eq __PACKAGE__; |
801
|
1
|
50
|
|
|
|
2
|
if ( ref $mac ) { |
802
|
0
|
|
|
|
|
0
|
my $e = 'argument must be a string'; |
803
|
0
|
0
|
|
|
|
0
|
croak "$e\n" if $NetAddr::MAC::die_on_error; |
804
|
0
|
|
|
|
|
0
|
$NetAddr::MAC::errstr = $e; |
805
|
|
|
|
|
|
|
return |
806
|
0
|
|
|
|
|
0
|
} |
807
|
|
|
|
|
|
|
|
808
|
1
|
50
|
|
|
|
2
|
$mac = _mac_to_integers($mac) or return; |
809
|
1
|
|
|
|
|
3
|
return as_cisco( { mac => $mac } ) |
810
|
|
|
|
|
|
|
|
811
|
|
|
|
|
|
|
} |
812
|
|
|
|
|
|
|
|
813
|
|
|
|
|
|
|
|
814
|
|
|
|
|
|
|
sub mac_as_ieee { |
815
|
|
|
|
|
|
|
|
816
|
1
|
|
|
1
|
1
|
3
|
my $mac = shift; |
817
|
1
|
50
|
|
|
|
3
|
croak 'please use as_ieee' |
818
|
|
|
|
|
|
|
if ref $mac eq __PACKAGE__; |
819
|
1
|
50
|
|
|
|
3
|
if ( ref $mac ) { |
820
|
0
|
|
|
|
|
0
|
my $e = 'argument must be a string'; |
821
|
0
|
0
|
|
|
|
0
|
croak "$e\n" if $NetAddr::MAC::die_on_error; |
822
|
0
|
|
|
|
|
0
|
$NetAddr::MAC::errstr = $e; |
823
|
|
|
|
|
|
|
return |
824
|
0
|
|
|
|
|
0
|
} |
825
|
|
|
|
|
|
|
|
826
|
1
|
50
|
|
|
|
2
|
$mac = _mac_to_integers($mac) or return; |
827
|
1
|
|
|
|
|
4
|
return as_ieee( { mac => $mac } ) |
828
|
|
|
|
|
|
|
|
829
|
|
|
|
|
|
|
} |
830
|
|
|
|
|
|
|
|
831
|
|
|
|
|
|
|
|
832
|
|
|
|
|
|
|
sub mac_as_ipv6_suffix { |
833
|
|
|
|
|
|
|
|
834
|
0
|
|
|
0
|
1
|
0
|
my $mac = shift; |
835
|
0
|
0
|
|
|
|
0
|
croak 'please use as_ipv6_suffix' |
836
|
|
|
|
|
|
|
if ref $mac eq __PACKAGE__; |
837
|
0
|
0
|
|
|
|
0
|
if ( ref $mac ) { |
838
|
0
|
|
|
|
|
0
|
my $e = 'argument must be a string'; |
839
|
0
|
0
|
|
|
|
0
|
croak "$e\n" if $NetAddr::MAC::die_on_error; |
840
|
0
|
|
|
|
|
0
|
$NetAddr::MAC::errstr = $e; |
841
|
|
|
|
|
|
|
return |
842
|
0
|
|
|
|
|
0
|
} |
843
|
|
|
|
|
|
|
|
844
|
0
|
0
|
|
|
|
0
|
$mac = _mac_to_integers($mac) or return; |
845
|
0
|
|
|
|
|
0
|
return as_ipv6_suffix( { mac => $mac } ) |
846
|
|
|
|
|
|
|
|
847
|
|
|
|
|
|
|
} |
848
|
|
|
|
|
|
|
|
849
|
|
|
|
|
|
|
|
850
|
|
|
|
|
|
|
sub mac_as_microsoft { |
851
|
|
|
|
|
|
|
|
852
|
1
|
|
|
1
|
1
|
3
|
my $mac = shift; |
853
|
|
|
|
|
|
|
|
854
|
1
|
50
|
|
|
|
3
|
croak 'please use as_microsoft' |
855
|
|
|
|
|
|
|
if ref $mac eq __PACKAGE__; |
856
|
1
|
50
|
|
|
|
2
|
if ( ref $mac ) { |
857
|
0
|
|
|
|
|
0
|
my $e = 'argument must be a string'; |
858
|
0
|
0
|
|
|
|
0
|
croak "$e\n" if $NetAddr::MAC::die_on_error; |
859
|
0
|
|
|
|
|
0
|
$NetAddr::MAC::errstr = $e; |
860
|
|
|
|
|
|
|
return |
861
|
0
|
|
|
|
|
0
|
} |
862
|
|
|
|
|
|
|
|
863
|
1
|
50
|
|
|
|
2
|
$mac = _mac_to_integers($mac) or return; |
864
|
1
|
|
|
|
|
3
|
return as_microsoft( { mac => $mac } ) |
865
|
|
|
|
|
|
|
|
866
|
|
|
|
|
|
|
} |
867
|
|
|
|
|
|
|
|
868
|
|
|
|
|
|
|
|
869
|
|
|
|
|
|
|
sub mac_as_pgsql { |
870
|
|
|
|
|
|
|
|
871
|
1
|
|
|
1
|
1
|
2
|
my $mac = shift; |
872
|
|
|
|
|
|
|
|
873
|
1
|
50
|
|
|
|
3
|
croak 'please use as_pgsql' |
874
|
|
|
|
|
|
|
if ref $mac eq __PACKAGE__; |
875
|
1
|
50
|
|
|
|
3
|
if ( ref $mac ) { |
876
|
0
|
|
|
|
|
0
|
my $e = 'argument must be a string'; |
877
|
0
|
0
|
|
|
|
0
|
croak "$e\n" if $NetAddr::MAC::die_on_error; |
878
|
0
|
|
|
|
|
0
|
$NetAddr::MAC::errstr = $e; |
879
|
|
|
|
|
|
|
return |
880
|
0
|
|
|
|
|
0
|
} |
881
|
|
|
|
|
|
|
|
882
|
1
|
50
|
|
|
|
3
|
$mac = _mac_to_integers($mac) or return; |
883
|
1
|
|
|
|
|
4
|
return as_pgsql( { mac => $mac } ) |
884
|
|
|
|
|
|
|
|
885
|
|
|
|
|
|
|
} |
886
|
|
|
|
|
|
|
|
887
|
|
|
|
|
|
|
|
888
|
|
|
|
|
|
|
sub mac_as_singledash { |
889
|
|
|
|
|
|
|
|
890
|
1
|
|
|
1
|
1
|
3
|
my $mac = shift; |
891
|
|
|
|
|
|
|
|
892
|
1
|
50
|
|
|
|
5
|
croak 'please use as_singledash' |
893
|
|
|
|
|
|
|
if ref $mac eq __PACKAGE__; |
894
|
1
|
50
|
|
|
|
3
|
if ( ref $mac ) { |
895
|
0
|
|
|
|
|
0
|
my $e = 'argument must be a string'; |
896
|
0
|
0
|
|
|
|
0
|
croak "$e\n" if $NetAddr::MAC::die_on_error; |
897
|
0
|
|
|
|
|
0
|
$NetAddr::MAC::errstr = $e; |
898
|
|
|
|
|
|
|
return |
899
|
0
|
|
|
|
|
0
|
} |
900
|
|
|
|
|
|
|
|
901
|
1
|
50
|
|
|
|
2
|
$mac = _mac_to_integers($mac) or return; |
902
|
1
|
|
|
|
|
3
|
return as_singledash( { mac => $mac } ) |
903
|
|
|
|
|
|
|
|
904
|
|
|
|
|
|
|
} |
905
|
|
|
|
|
|
|
|
906
|
|
|
|
|
|
|
|
907
|
|
|
|
|
|
|
sub mac_as_sun { |
908
|
|
|
|
|
|
|
|
909
|
1
|
|
|
1
|
1
|
2
|
my $mac = shift; |
910
|
|
|
|
|
|
|
|
911
|
1
|
50
|
|
|
|
3
|
croak 'please use as_sun' |
912
|
|
|
|
|
|
|
if ref $mac eq __PACKAGE__; |
913
|
1
|
50
|
|
|
|
2
|
if ( ref $mac ) { |
914
|
0
|
|
|
|
|
0
|
my $e = 'argument must be a string'; |
915
|
0
|
0
|
|
|
|
0
|
croak "$e\n" if $NetAddr::MAC::die_on_error; |
916
|
0
|
|
|
|
|
0
|
$NetAddr::MAC::errstr = $e; |
917
|
|
|
|
|
|
|
return |
918
|
0
|
|
|
|
|
0
|
} |
919
|
|
|
|
|
|
|
|
920
|
1
|
50
|
|
|
|
2
|
$mac = _mac_to_integers($mac) or return; |
921
|
1
|
|
|
|
|
3
|
return as_sun( { mac => $mac } ) |
922
|
|
|
|
|
|
|
|
923
|
|
|
|
|
|
|
} |
924
|
|
|
|
|
|
|
|
925
|
|
|
|
|
|
|
|
926
|
|
|
|
|
|
|
sub mac_as_tokenring { |
927
|
|
|
|
|
|
|
|
928
|
1
|
|
|
1
|
1
|
2
|
my $mac = shift; |
929
|
|
|
|
|
|
|
|
930
|
1
|
50
|
|
|
|
3
|
croak 'please use as_tokenring' |
931
|
|
|
|
|
|
|
if ref $mac eq __PACKAGE__; |
932
|
1
|
50
|
|
|
|
2
|
if ( ref $mac ) { |
933
|
0
|
|
|
|
|
0
|
my $e = 'argument must be a string'; |
934
|
0
|
0
|
|
|
|
0
|
croak "$e\n" if $NetAddr::MAC::die_on_error; |
935
|
0
|
|
|
|
|
0
|
$NetAddr::MAC::errstr = $e; |
936
|
|
|
|
|
|
|
return |
937
|
0
|
|
|
|
|
0
|
} |
938
|
|
|
|
|
|
|
|
939
|
1
|
50
|
|
|
|
3
|
$mac = _mac_to_integers($mac) or return; |
940
|
1
|
|
|
|
|
3
|
return as_tokenring( { mac => $mac } ) |
941
|
|
|
|
|
|
|
|
942
|
|
|
|
|
|
|
} |
943
|
|
|
|
|
|
|
|
944
|
|
|
|
|
|
|
|
945
|
|
|
|
|
|
|
1; |
946
|
|
|
|
|
|
|
|
947
|
|
|
|
|
|
|
__END__ |