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

net: Add INET_ADDRSTRLEN and use it at least in net_config #9818

Closed
Closed
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
3 changes: 3 additions & 0 deletions include/net/net_ip.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,10 @@ struct net_addr {
extern const struct in6_addr in6addr_any;
Copy link
Member

Choose a reason for hiding this comment

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

The commit message is way to long and describes things that are not relevant to this pr.
It should be enough to just say

POSIX defines INET_ADDRSTRLEN and INET6_ADDRSTRLEN as max sizes of
textual form of IP addresses (including terminating NUL):
http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/netinet_in.h.html

We already define INET6_ADDRSTRLEN, so it makes sense to define
INET_ADDRSTRLEN too.

The rest of the story is irrelevant to this change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The rest of the story is irrelevant to this change.

It's relevant, if you take into account that this patch not just introduces INET_ADDRSTRLEN, but tries to replace NET_IPV*_ADDR_LEN with INET*_ADDRSTRLEN.

But I get a hint from you and @ozhuraki's comments that adding it should be split from an attempt to switch to it. Will prepare a new PR then.

extern const struct in6_addr in6addr_loopback;

/* Defined by POSIX. INET6_ADDRSTRLEN accounts for mapped IPv4 addresses. */
#define INET_ADDRSTRLEN 16
#define INET6_ADDRSTRLEN 46

#define NET_IPV6_ADDR_LEN sizeof("xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx")
#define NET_IPV4_ADDR_LEN sizeof("xxx.xxx.xxx.xxx")

Expand Down
12 changes: 6 additions & 6 deletions subsys/net/lib/config/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ static void ipv4_addr_add_handler(struct net_mgmt_event_callback *cb,
struct net_if *iface)
{
#if defined(CONFIG_NET_DEBUG_APP) && CONFIG_SYS_LOG_NET_LEVEL > 2
char hr_addr[NET_IPV4_ADDR_LEN];
char hr_addr[INET_ADDRSTRLEN];
#endif
int i;

Expand All @@ -60,16 +60,16 @@ static void ipv4_addr_add_handler(struct net_mgmt_event_callback *cb,
#if defined(CONFIG_NET_DEBUG_APP) && CONFIG_SYS_LOG_NET_LEVEL > 2
NET_INFO("IPv4 address: %s",
net_addr_ntop(AF_INET, &if_addr->address.in_addr,
hr_addr, NET_IPV4_ADDR_LEN));
hr_addr, sizeof(hr_addr)));
NET_INFO("Lease time: %u seconds",
iface->config.dhcpv4.lease_time);
NET_INFO("Subnet: %s",
net_addr_ntop(AF_INET,
&iface->config.ip.ipv4->netmask,
hr_addr, NET_IPV4_ADDR_LEN));
hr_addr, sizeof(hr_addr)));
NET_INFO("Router: %s",
net_addr_ntop(AF_INET, &iface->config.ip.ipv4->gw,
hr_addr, NET_IPV4_ADDR_LEN));
hr_addr, sizeof(hr_addr)));
#endif
break;
}
Expand Down Expand Up @@ -103,7 +103,7 @@ static void setup_dhcpv4(struct net_if *iface)
static void setup_ipv4(struct net_if *iface)
{
#if defined(CONFIG_NET_DEBUG_APP) && CONFIG_SYS_LOG_NET_LEVEL > 2
char hr_addr[NET_IPV4_ADDR_LEN];
char hr_addr[INET_ADDRSTRLEN];
#endif
struct in_addr addr;

Expand Down Expand Up @@ -135,7 +135,7 @@ static void setup_ipv4(struct net_if *iface)

#if defined(CONFIG_NET_DEBUG_APP) && CONFIG_SYS_LOG_NET_LEVEL > 2
NET_INFO("IPv4 address: %s",
net_addr_ntop(AF_INET, &addr, hr_addr, NET_IPV4_ADDR_LEN));
net_addr_ntop(AF_INET, &addr, hr_addr, sizeof(hr_addr)));
#endif

if (sizeof(CONFIG_NET_CONFIG_MY_IPV4_NETMASK) > 1) {
Expand Down