From 37b8dc17bccabda6b835a077e8b8e65c2ffadedd Mon Sep 17 00:00:00 2001 From: Jukka Rissanen Date: Sun, 24 Sep 2023 22:03:47 +0300 Subject: [PATCH] net: socket: Allow same port if different address family It is always possible to bind to same port if the sockets are in different address family. Signed-off-by: Jukka Rissanen --- subsys/net/ip/net_context.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/subsys/net/ip/net_context.c b/subsys/net/ip/net_context.c index 5bd4122efc6..7875d6e3bc3 100644 --- a/subsys/net/ip/net_context.c +++ b/subsys/net/ip/net_context.c @@ -132,7 +132,8 @@ static int check_used_port(enum net_ip_protocol proto, if (IS_ENABLED(CONFIG_NET_IPV6) && local_addr->sa_family == AF_INET6) { - if (net_sin6_ptr(&contexts[i].local)->sin6_addr == NULL) { + if (net_sin6_ptr(&contexts[i].local)->sin6_addr == NULL || + net_sin6_ptr(&contexts[i].local)->sin6_family != AF_INET6) { continue; } @@ -187,7 +188,8 @@ static int check_used_port(enum net_ip_protocol proto, } } else if (IS_ENABLED(CONFIG_NET_IPV4) && local_addr->sa_family == AF_INET) { - if (net_sin_ptr(&contexts[i].local)->sin_addr == NULL) { + if (net_sin_ptr(&contexts[i].local)->sin_addr == NULL || + net_sin_ptr(&contexts[i].local)->sin_family != AF_INET) { continue; }