blob: 1181dfe574ccfd79748d8e9a06704a5d8caf6070 [file] [log] [blame]
Harald Welte40d56f92014-08-18 19:03:40 +02001#include <stdint.h>
2#include <string.h>
3#include <stdlib.h>
4
5
6int osmo_macaddr_parse(uint8_t *out, const char *in)
7{
8 /* 00:00:00:00:00:00 */
9 char tmp[18];
10 char *tok;
11 unsigned int i = 0;
12
13 if (strlen(in) < 17)
14 return -1;
15
16 strncpy(tmp, in, sizeof(tmp)-1);
17 tmp[sizeof(tmp)-1] = '\0';
18
19 for (tok = strtok(tmp, ":"); tok && (i < 6); tok = strtok(NULL, ":")) {
20 unsigned long ul = strtoul(tok, NULL, 16);
21 out[i++] = ul & 0xff;
22 }
23
24 return 0;
25}