A stack which works with or without an Mbed os library. Provides IPv4 or IPv6 with a full 1500 byte buffer.

Dependents:   oldheating gps motorhome heating

Revision:
195:bd5b123143ca
Parent:
172:9bc3c7b2cca1
--- a/eth/mac.c	Thu Mar 04 12:08:14 2021 +0000
+++ b/eth/mac.c	Sun Apr 18 19:04:48 2021 +0000
@@ -32,6 +32,50 @@
     return true;
 }
 
+void MacParse(const char *text, char *mac)
+{
+    MacClear(mac);
+    int field = 0;
+    int byte = 0;
+    while(true)
+    {
+        switch (*text)
+        {
+            case ':':
+                mac[field] = byte;
+                field++;
+                if (field > 6) return;
+                byte = 0;
+                break;
+            case '0': byte <<= 4; byte |= 0; break;
+            case '1': byte <<= 4; byte |= 1; break;
+            case '2': byte <<= 4; byte |= 2; break;
+            case '3': byte <<= 4; byte |= 3; break;
+            case '4': byte <<= 4; byte |= 4; break;
+            case '5': byte <<= 4; byte |= 5; break;
+            case '6': byte <<= 4; byte |= 6; break;
+            case '7': byte <<= 4; byte |= 7; break;
+            case '8': byte <<= 4; byte |= 8; break;
+            case '9': byte <<= 4; byte |= 9; break;
+            case 'a':
+            case 'A': byte <<= 4; byte |= 10; break;
+            case 'b':
+            case 'B': byte <<= 4; byte |= 11; break;
+            case 'c':
+            case 'C': byte <<= 4; byte |= 12; break;
+            case 'd':
+            case 'D': byte <<= 4; byte |= 13; break;
+            case 'e':
+            case 'E': byte <<= 4; byte |= 14; break;
+            case 'f':
+            case 'F': byte <<= 4; byte |= 15; break;
+            case 0:
+                mac[field] = byte;
+                return;
+        }
+        text++;
+    }
+}
 int MacToString(const char* mac, int size, char* text)
 {
     return snprintf(text, size, "%02x:%02x:%02x:%02x:%02x:%02x", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);