From 44e985bf8cb16181f04508263992380563be9f0a Mon Sep 17 00:00:00 2001 From: Kaspar Schleiser Date: Fri, 5 Feb 2016 10:12:02 +0100 Subject: [PATCH] sys: net: ipv6: add print_ipv6_addr() --- sys/include/net/ipv6/addr.h | 7 +++++++ sys/net/network_layer/ipv6/addr/ipv6_addr.c | 19 +++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/sys/include/net/ipv6/addr.h b/sys/include/net/ipv6/addr.h index 373d2654d5..c0c187a107 100644 --- a/sys/include/net/ipv6/addr.h +++ b/sys/include/net/ipv6/addr.h @@ -709,6 +709,13 @@ static inline int ipv6_addr_split_iface(char *addr_str) return ipv6_addr_split(addr_str, '%', -1); } +/** + * @brief Print IPv6 address to stdout + * + * @param[in] addr Pointer to ipv6_addr_t to print + */ +void ipv6_addr_print(const ipv6_addr_t *addr); + #ifdef __cplusplus } #endif diff --git a/sys/net/network_layer/ipv6/addr/ipv6_addr.c b/sys/net/network_layer/ipv6/addr/ipv6_addr.c index b26ba56555..8627e99b83 100644 --- a/sys/net/network_layer/ipv6/addr/ipv6_addr.c +++ b/sys/net/network_layer/ipv6/addr/ipv6_addr.c @@ -14,11 +14,18 @@ * @author Martine Lenders */ +#include #include #include #include "net/ipv6/addr.h" +#ifdef MODULE_FMT +#include "fmt.h" +#else +#include +#endif + bool ipv6_addr_equal(const ipv6_addr_t *a, const ipv6_addr_t *b) { return (a->u64[0].u64 == b->u64[0].u64) && @@ -122,6 +129,18 @@ int ipv6_addr_split(char *addr_str, char seperator, int _default) return _default; } +void ipv6_addr_print(const ipv6_addr_t *addr) +{ + assert(addr); + char addr_str[IPV6_ADDR_MAX_STR_LEN]; + ipv6_addr_to_str(addr_str, addr, sizeof(addr_str)); +#ifdef MODULE_FMT + print_str(addr_str); +#else + printf("%s", addr_str); +#endif +} + /** * @} */