From 3b23b3a69d71a862dfe7fca1b53b673dc868ffa5 Mon Sep 17 00:00:00 2001
From: wanfeng <wanfeng@kylinos.cn>
Date: Fri, 10 May 2024 15:11:12 +0800
Subject: [PATCH] allow membership to register multiple times

---
 src/api/sockets.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/api/sockets.c b/src/api/sockets.c
index 04df15a..5a72b62 100644
--- a/src/api/sockets.c
+++ b/src/api/sockets.c
@@ -4501,7 +4501,7 @@ lwip_socket_register_membership(int s, unsigned int if_idx, const ip4_addr_t *mu
 #else
   for (i = 0; i < LWIP_SOCKET_MAX_MEMBERSHIPS; i++) {
 #endif
-    if (socket_ipv4_multicast_memberships[i].sock == NULL) {
+    if (socket_ipv4_multicast_memberships[i].sock == NULL || (socket_ipv4_multicast_memberships[i].sock == sock)) {
       socket_ipv4_multicast_memberships[i].sock = sock;
       socket_ipv4_multicast_memberships[i].if_idx = if_idx;
       ip4_addr_copy(socket_ipv4_multicast_memberships[i].multi_addr, *multi_addr);
@@ -4617,7 +4617,7 @@ lwip_socket_register_mld6_membership(int s, unsigned int if_idx, const ip6_addr_
 #else
   for (i = 0; i < LWIP_SOCKET_MAX_MEMBERSHIPS; i++) {
 #endif
-    if (socket_ipv6_multicast_memberships[i].sock == NULL) {
+    if (socket_ipv6_multicast_memberships[i].sock == NULL || (socket_ipv6_multicast_memberships[i].sock == sock)) {
       socket_ipv6_multicast_memberships[i].sock   = sock;
       socket_ipv6_multicast_memberships[i].if_idx = (u8_t)if_idx;
       ip6_addr_copy(socket_ipv6_multicast_memberships[i].multi_addr, *multi_addr);
-- 
2.25.1

