diff options
author | Jo-Philipp Wich <jow@openwrt.org> | 2012-09-28 17:40:38 +0200 |
---|---|---|
committer | Jo-Philipp Wich <jow@openwrt.org> | 2012-09-28 23:16:06 +0300 |
commit | 8370eef2bc724b3c08f8665e3caaaae9b75012f7 (patch) | |
tree | 133faeeaf6f70fd8e9f533cb659647fc407d33f2 | |
parent | 8a671b56edd90d9b19ea4317ce664793ee324cb4 (diff) |
utils.c: add helper function to format mac addresses as strings
-rw-r--r-- | utils.c | 11 | ||||
-rw-r--r-- | utils.h | 2 |
2 files changed, 13 insertions, 0 deletions
@@ -129,3 +129,14 @@ parse_ip_and_netmask(int af, const char *str, void *addr, unsigned int *netmask) return inet_pton(af, astr, addr); } + +char * +format_macaddr(uint8_t *mac) +{ + static char str[sizeof("ff:ff:ff:ff:ff:ff ")]; + + snprintf(str, sizeof(str), "%02x:%02x:%02x:%02x:%02x:%02x", + mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); + + return str; +} @@ -114,4 +114,6 @@ unsigned int parse_netmask_string(const char *str, bool v6); bool split_netmask(char *str, unsigned int *netmask, bool v6); int parse_ip_and_netmask(int af, const char *str, void *addr, unsigned int *netmask); +char * format_macaddr(uint8_t *mac); + #endif |