summaryrefslogtreecommitdiffstats
path: root/src/macaddr.c
diff options
context:
space:
mode:
authorHarald Welte <laforge@gnumonks.org>2014-08-18 19:03:40 +0200
committerHarald Welte <laforge@gnumonks.org>2014-08-18 19:03:40 +0200
commit40d56f96b907f8afb717a5d33fd72bee0f6ad1fb (patch)
tree81801f9af9ca2f3caf45279d72a6d0c1e155a403 /src/macaddr.c
parentcc27fa6479efd446065d691d888d1729bc1be2c8 (diff)
osmocore: Add function osmo_macaddr_parse() to parse ETH MAC address
Diffstat (limited to 'src/macaddr.c')
-rw-r--r--src/macaddr.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/macaddr.c b/src/macaddr.c
new file mode 100644
index 00000000..1181dfe5
--- /dev/null
+++ b/src/macaddr.c
@@ -0,0 +1,25 @@
+#include <stdint.h>
+#include <string.h>
+#include <stdlib.h>
+
+
+int osmo_macaddr_parse(uint8_t *out, const char *in)
+{
+ /* 00:00:00:00:00:00 */
+ char tmp[18];
+ char *tok;
+ unsigned int i = 0;
+
+ if (strlen(in) < 17)
+ return -1;
+
+ strncpy(tmp, in, sizeof(tmp)-1);
+ tmp[sizeof(tmp)-1] = '\0';
+
+ for (tok = strtok(tmp, ":"); tok && (i < 6); tok = strtok(NULL, ":")) {
+ unsigned long ul = strtoul(tok, NULL, 16);
+ out[i++] = ul & 0xff;
+ }
+
+ return 0;
+}