diff --git a/subsys/mgmt/mcumgr/transport/Kconfig b/subsys/mgmt/mcumgr/transport/Kconfig index a892caee8d6b69..90bd158ed161ea 100644 --- a/subsys/mgmt/mcumgr/transport/Kconfig +++ b/subsys/mgmt/mcumgr/transport/Kconfig @@ -51,6 +51,7 @@ config MCUMGR_TRANSPORT_NETBUF_SIZE config MCUMGR_TRANSPORT_NETBUF_MIN_USER_DATA_SIZE int default 24 if MCUMGR_TRANSPORT_UDP && NET_IPV6 + default 20 if MCUMGR_TRANSPORT_UDP && MCUMGR_TRANSPORT_UDP_IPV4 && NET_SOCKETS_PACKET default 8 if MCUMGR_TRANSPORT_UDP && MCUMGR_TRANSPORT_UDP_IPV4 default 8 if MCUMGR_TRANSPORT_BT default 4 diff --git a/subsys/mgmt/mcumgr/transport/src/smp_udp.c b/subsys/mgmt/mcumgr/transport/src/smp_udp.c index 77734889ac86a1..60ed9816ed26d1 100644 --- a/subsys/mgmt/mcumgr/transport/src/smp_udp.c +++ b/subsys/mgmt/mcumgr/transport/src/smp_udp.c @@ -164,6 +164,7 @@ static int create_socket(enum proto_type proto, int *sock) int tmp_sock; int err; struct sockaddr *addr; + socklen_t addr_len = 0; #ifdef CONFIG_MCUMGR_TRANSPORT_UDP_IPV4 struct sockaddr_in addr4; @@ -175,6 +176,7 @@ static int create_socket(enum proto_type proto, int *sock) #ifdef CONFIG_MCUMGR_TRANSPORT_UDP_IPV4 if (proto == PROTOCOL_IPV4) { + addr_len = sizeof(struct sockaddr_in); memset(&addr4, 0, sizeof(addr4)); addr4.sin_family = AF_INET; addr4.sin_port = htons(CONFIG_MCUMGR_TRANSPORT_UDP_PORT); @@ -185,6 +187,7 @@ static int create_socket(enum proto_type proto, int *sock) #ifdef CONFIG_MCUMGR_TRANSPORT_UDP_IPV6 if (proto == PROTOCOL_IPV6) { + addr_len = sizeof(struct sockaddr_in6); memset(&addr6, 0, sizeof(addr6)); addr6.sin6_family = AF_INET6; addr6.sin6_port = htons(CONFIG_MCUMGR_TRANSPORT_UDP_PORT); @@ -203,7 +206,7 @@ static int create_socket(enum proto_type proto, int *sock) return -err; } - if (zsock_bind(tmp_sock, addr, sizeof(*addr)) < 0) { + if (zsock_bind(tmp_sock, addr, addr_len) < 0) { err = errno; LOG_ERR("Could not bind to receive socket (%s), err: %i", smp_udp_proto_to_name(proto), err);