Line data Source code
1 : /// Provides utilities for normalizing MAC addresses for vendor lookup.
2 : class VendorTable {
3 : /// Hex lengths of the IEEE assignment blocks, most specific first: MA-S and
4 : /// IAB (4.5 octets), MA-M (3.5 octets), then MA-L (3 octets).
5 : static const List<int> prefixLengths = [9, 7, 6];
6 :
7 : /// Normalizes a MAC address to upper-case hex with no separators.
8 : ///
9 : /// Accepts colon, dash and dot separated MACs as well as raw hex strings.
10 2 : static String normalizedHex(String macAddress) =>
11 6 : macAddress.replaceAll(RegExp('[^0-9a-fA-F]'), '').toUpperCase();
12 :
13 : /// Normalizes a MAC address to its upper-case, separator-free MA-L prefix.
14 : ///
15 : /// Returns the whole input when it is shorter than 3 octets. Use
16 : /// [normalizedHex] when the full address is needed, since MA-M, MA-S and IAB
17 : /// blocks are longer than 6 characters.
18 1 : static String noColonString(String macAddress) {
19 1 : final String hex = normalizedHex(macAddress);
20 3 : return hex.length > 6 ? hex.substring(0, 6) : hex;
21 : }
22 : }
|