I would like to interpret a mac string formatted like 00:11:22:33:44:55
as 6 binary bytes i.e. 0x00, 0x11, 0x22, 0x33, 0x44, 0x55.
I've attemped to accomplish this with following code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
void main (void)
{
char mac[16]={0};
char binmac[8]={0};
char* pEnd;
strcpy(mac,"00:11:22:33:44:55");
printf("mac %s\n", mac);
binmac[0] = strtol (mac, &pEnd, 16);
binmac[1] = strtol (pEnd+1, &pEnd, 16);
binmac[2] = strtol (pEnd+1, &pEnd, 16);
binmac[3] = strtol (pEnd+1, &pEnd, 16);
binmac[4] = strtol (pEnd+1, &pEnd, 16);
binmac[5] = strtol (pEnd+1, NULL, 16);
printf ("binmac 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x\n",binmac[0], binmac[1], binmac[2], binmac[3], binmac[4], binmac[5]);
}
But the result I get doesn't look right:
mac 00:11:22:33:44:55
binmac 0x00 0x11 0x22 0x33 0x44 0x05
I'm wondering why the last byte doesn't get interpreted correctly. Thanks