Skip to content
Browse files

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

Fixes: #17401

Signed-off-by: Michael Scott <>
  • Loading branch information...
mike-scott authored and jukkar committed Jul 8, 2019
1 parent 868cd47 commit 05cc5ae92c89c8e269af073d80196b60f38dccd0
Showing with 3 additions and 5 deletions.
  1. +3 −5 subsys/net/lib/lwm2m/lwm2m_engine.c
@@ -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));
#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));

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)

0 comments on commit 05cc5ae

Please sign in to comment.
You can’t perform that action at this time.