diff options
-rw-r--r-- | include/Makefile.am | 1 | ||||
-rw-r--r-- | include/osmocom/core/macaddr.h | 6 | ||||
-rw-r--r-- | src/Makefile.am | 3 | ||||
-rw-r--r-- | src/macaddr.c | 25 |
4 files changed, 34 insertions, 1 deletions
diff --git a/include/Makefile.am b/include/Makefile.am index 74396de0..3046758a 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -21,6 +21,7 @@ nobase_include_HEADERS = \ osmocom/core/linuxrbtree.h \ osmocom/core/logging.h \ osmocom/core/loggingrb.h \ + osmocom/core/macaddr.h \ osmocom/core/msgb.h \ osmocom/core/panic.h \ osmocom/core/prim.h \ diff --git a/include/osmocom/core/macaddr.h b/include/osmocom/core/macaddr.h new file mode 100644 index 00000000..517977bb --- /dev/null +++ b/include/osmocom/core/macaddr.h @@ -0,0 +1,6 @@ +#ifndef _OSMO_MACADDR_H +#define _OSMO_MACADDR_H + +int osmo_macaddr_parse(uint8_t *out, const char *in); + +#endif diff --git a/src/Makefile.am b/src/Makefile.am index e68c29ac..841f6725 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -13,7 +13,8 @@ libosmocore_la_SOURCES = timer.c select.c signal.c msgb.c bits.c \ logging.c logging_syslog.c rate_ctr.c \ gsmtap_util.c crc16.c panic.c backtrace.c \ conv.c application.c rbtree.c strrb.c \ - loggingrb.c crc8gen.c crc16gen.c crc32gen.c crc64gen.c + loggingrb.c crc8gen.c crc16gen.c crc32gen.c crc64gen.c \ + macaddr.c BUILT_SOURCES = crc8gen.c crc16gen.c crc32gen.c crc64gen.c 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; +} |