Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sys/net/network_layer/ipv4/addr: add ipv4_addr_print function #18694

Merged
merged 1 commit into from
Oct 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions sys/include/net/ipv4/addr.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
41 changes: 41 additions & 0 deletions sys/net/network_layer/ipv4/addr/ipv4_addr.c
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>
*/

#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>

#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));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is this function implemented? Wouldn't it make sense to add ipv4_addr_print() there as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ipv4_addr_to_str can be found in net/ipv4/addr.h like ipv6_addr_to_str can be found in net/ipv6/addr.h. I'm just placing the IPv4 variants relative to their respective IPv6 counterparts ;)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In net/ipv6/addr.h there is just the definition of ipv4_addr_to_str(), but I now saw, that they are in their own compile unit ipv6_addr_to_str.c. So nvm.


if (IS_USED(MODULE_FMT)) {
print_str(addr_str);
} else {
printf("%s", addr_str);
}
}

/**
* @}
*/