From 6c98a5b3b7ba9a8fe2b2b620bd7317c6f30c38b5 Mon Sep 17 00:00:00 2001 From: Hendrik van Essen Date: Sun, 13 Mar 2022 13:51:12 +0100 Subject: [PATCH] sys/net/network_layer/ipv4/addr: add ipv4_addr_print function --- sys/include/net/ipv4/addr.h | 7 ++++ sys/net/network_layer/ipv4/addr/ipv4_addr.c | 41 +++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 sys/net/network_layer/ipv4/addr/ipv4_addr.c diff --git a/sys/include/net/ipv4/addr.h b/sys/include/net/ipv4/addr.h index 76222e4e47c7..30cc5fcb3c07 100644 --- a/sys/include/net/ipv4/addr.h +++ b/sys/include/net/ipv4/addr.h @@ -101,6 +101,13 @@ ipv4_addr_t *ipv4_addr_from_str(ipv4_addr_t *result, const char *addr); ipv4_addr_t *ipv4_addr_from_buf(ipv4_addr_t *result, const char *addr, size_t addr_len); +/** + * @brief Print IPv4 address to stdout + * + * @param[in] addr Pointer to ipv6_addr_t to print + */ +void ipv4_addr_print(const ipv4_addr_t *addr); + #ifdef __cplusplus } #endif diff --git a/sys/net/network_layer/ipv4/addr/ipv4_addr.c b/sys/net/network_layer/ipv4/addr/ipv4_addr.c new file mode 100644 index 000000000000..8d0c5b17fbdf --- /dev/null +++ b/sys/net/network_layer/ipv4/addr/ipv4_addr.c @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2022 Freie Universität Berlin + * + * This file is subject to the terms and conditions of the GNU Lesser General + * Public License v2.1. See the file LICENSE in the top level directory for + * more details. + */ + +/** + * @{ + * + * @file + * + * @author Hendrik van Essen + */ + +#include +#include +#include +#include + +#include "fmt.h" +#include "kernel_defines.h" +#include "net/ipv4/addr.h" + +void ipv4_addr_print(const ipv4_addr_t *addr) +{ + assert(addr); + char addr_str[IPV4_ADDR_MAX_STR_LEN]; + ipv4_addr_to_str(addr_str, addr, sizeof(addr_str)); + + if (IS_USED(MODULE_FMT)) { + print_str(addr_str); + } else { + printf("%s", addr_str); + } +} + +/** + * @} + */