Harald Welte | 40d56f9 | 2014-08-18 19:03:40 +0200 | [diff] [blame^] | 1 | #include <stdint.h> |
| 2 | #include <string.h> |
| 3 | #include <stdlib.h> |
| 4 | |
| 5 | |
| 6 | int 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 | } |