net: lwm2m: remove IP CONFIG checks in lwm2m_sprint_ip_addr()
CONFIG_NET_IPV* checks are not needed in lwm2m_sprint_ip_addr(). The functions used are always available. Worse, having these checks forces the need to enable CONFIG_NET_IPV4 or IPV6 when it's not really needed (LwM2M could be using an offloaded IP stack). NOTE: Also fixes an issue where a NULL is returned when the IP address is unknown. This usually ends up with a crash/abort in the logging code. Fixes: https://github.com/zephyrproject-rtos/zephyr/issues/17401 Signed-off-by: Michael Scott <mike@foundries.io>
This commit is contained in:
parent
868cd477d5
commit
05cc5ae92c
1 changed files with 3 additions and 5 deletions
|
@ -178,21 +178,19 @@ char *lwm2m_sprint_ip_addr(const struct sockaddr *addr)
|
|||
{
|
||||
static char buf[NET_IPV6_ADDR_LEN];
|
||||
|
||||
#if defined(CONFIG_NET_IPV6)
|
||||
if (addr->sa_family == AF_INET6) {
|
||||
return net_addr_ntop(AF_INET6, &net_sin6(addr)->sin6_addr,
|
||||
buf, sizeof(buf));
|
||||
}
|
||||
#endif
|
||||
#if defined(CONFIG_NET_IPV4)
|
||||
|
||||
if (addr->sa_family == AF_INET) {
|
||||
return net_addr_ntop(AF_INET, &net_sin(addr)->sin_addr,
|
||||
buf, sizeof(buf));
|
||||
}
|
||||
#endif
|
||||
|
||||
LOG_ERR("Unknown IP address family:%d", addr->sa_family);
|
||||
return NULL;
|
||||
strcpy(buf, "unk");
|
||||
return buf;
|
||||
}
|
||||
|
||||
static u8_t to_hex_digit(u8_t digit)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue