MCPcopy Create free account
hub / github.com/SmingHub/Sming / MacAddress

Method MacAddress

Sming/Wiring/MacAddress.cpp:26–50  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

24#include <Data/HexString.h>
25
26MacAddress::MacAddress(const String& s)
27{
28 // Maximum length with 2 hex digits per octet plus optional separator
29 bool sep;
30 if(s.length() == 12) {
31 sep = false;
32 } else if(s.length() == 17) {
33 sep = true;
34 } else {
35 return;
36 }
37 auto str = s.c_str();
38 Octets res{};
39 for(unsigned i = 0; i < 6; ++i) {
40 if(sep && i != 5 && strchr(_F(":-.,/ "), str[2]) == nullptr) {
41 return;
42 }
43 if(!isxdigit(str[0]) || !isxdigit(str[1])) {
44 return;
45 }
46 res[i] = (unhex(str[0]) << 4) | unhex(str[1]);
47 str += 2 + unsigned(sep);
48 }
49 memcpy(octets, res, sizeof(res));
50}
51
52uint8_t& MacAddress::operator[](unsigned index)
53{

Callers

nothing calls this directly

Calls 3

unhexFunction · 0.50
lengthMethod · 0.45
c_strMethod · 0.45

Tested by

no test coverage detected