fixed some potential issues with MAC addresses

added corresponding test-cases
switched to newer version of tinyxml due to some issues
adjusted affected code-parts accordingly
for better re-use, moved ceiling-calculation to a new class
some minor fixes
new helper methods
worked on wifi-opt
This commit is contained in:
2017-03-20 11:19:57 +01:00
parent d065015f7d
commit 06e0e0a5aa
20 changed files with 1486 additions and 676 deletions

View File

@@ -24,7 +24,7 @@ private:
} fields;
/** store as 64-bit integer */
uint64_t mac;
uint64_t mac = 0;
public:
@@ -61,8 +61,8 @@ public:
fields.h5 = hexWordToInt(str[ 0], str[ 1]);
fields.h4 = hexWordToInt(str[ 2], str[ 3]);
fields.h3 = hexWordToInt(str[ 4], str[ 5]);
fields.h2 = hexWordToInt(str[ 6], str[7]);
fields.h1 = hexWordToInt(str[8], str[9]);
fields.h2 = hexWordToInt(str[ 6], str[ 7]);
fields.h1 = hexWordToInt(str[ 8], str[ 9]);
fields.h0 = hexWordToInt(str[10], str[11]);
}
else{
@@ -89,7 +89,9 @@ public:
/** get the mac address as a long-int value */
uint64_t asLong() const {
return mac;
// even if we initialized all 8 bytes with zero
// we mask the 2 unsued bytes to be absolutely safe
return mac & 0x0000FFFFFFFFFFFF;
}
/** equal? */
@@ -105,13 +107,19 @@ public:
private:
/** convert the given hex char [0-F] to an integer [0-15] */
static uint8_t hexCharToInt(const char _hex) {
// to upper case
const char hex = (_hex >= 'a') ? (_hex - ('a' - 'A')) : (_hex);
static uint8_t hexCharToInt(const char hex) {
// convert
return (hex - '0' < 10) ? (hex - '0') : (hex - 'A' + 10);
if (hex >= '0' && hex <= '9') { // digits
return (hex - '0');
} else if (hex >= 'a' && hex <= 'f') { // lower case
return (hex - 'a' + 10);
} else if (hex >= 'A' && hex <= 'F') { // upper case
return (hex - 'A' + 10);
}
// found an invalid character
throw Exception("invalid character within MAC address");
}