Add func for convert string to MAC address. Signed-off-by: Vadim Kochan <vadi...@gmail.com> --- str.c | 25 +++++++++++++++++++++++++ str.h | 1 + 2 files changed, 26 insertions(+)
diff --git a/str.c b/str.c index e4d8722..a3421b0 100644 --- a/str.c +++ b/str.c @@ -7,6 +7,7 @@ #include <stdio.h> #include <string.h> #include <stdarg.h> +#include <arpa/inet.h> #include "str.h" #include "die.h" @@ -129,3 +130,27 @@ void argv_free(char **argv) free(tmp); } + +int str2mac(const char *str, uint8_t *mac) +{ + int i, count; + unsigned int tmp[6]; + + if (!str) + return -1; + + count = sscanf(str, "%02X:%02X:%02X:%02X:%02X:%02X", + &tmp[0], &tmp[1], &tmp[2], &tmp[3], &tmp[4], &tmp[5]); + + if (count != 6) + count = sscanf(str, "%02x:%02x:%02x:%02x:%02x:%02x", + &tmp[0], &tmp[1], &tmp[2], &tmp[3], &tmp[4], &tmp[5]); + + if (count != 6) + return -1; + + for (i = 0; i < 6; i++) + mac[i] = (uint8_t)tmp[i]; + + return 0; +} diff --git a/str.h b/str.h index 3ffb2b9..21051ad 100644 --- a/str.h +++ b/str.h @@ -11,5 +11,6 @@ extern noinline void *xmemset(void *s, int c, size_t n); extern char *argv2str(int startind, int argc, char **argv); extern char **argv_insert(char **argv, size_t *count, const char *str); extern void argv_free(char **argv); +extern int str2mac(const char *str, uint8_t *mac); #endif /* STR_H */ -- 2.6.3 -- You received this message because you are subscribed to the Google Groups "netsniff-ng" group. To unsubscribe from this group and stop receiving emails from it, send an email to netsniff-ng+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.