From b67aeecee71480d77403c861aaefe37b4e43eb80 Mon Sep 17 00:00:00 2001 From: WanqQixiang Date: Wed, 10 Jan 2024 17:21:43 +0800 Subject: [PATCH] fix(mdns): fix the logic of creating pcb for networking socket --- .../mdns/examples/query_advertise/pytest_mdns.py | 1 + components/mdns/mdns_networking_socket.c | 14 +++----------- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/components/mdns/examples/query_advertise/pytest_mdns.py b/components/mdns/examples/query_advertise/pytest_mdns.py index e78e094dd7a..f8c9eacb13d 100644 --- a/components/mdns/examples/query_advertise/pytest_mdns.py +++ b/components/mdns/examples/query_advertise/pytest_mdns.py @@ -64,6 +64,7 @@ def mdns_server(esp_host, events): sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1) + sock.setsockopt(socket.SOL_SOCKET, socket.SO_BINDTODEVICE, 'eth0\0'.encode('utf-8')) sock.setblocking(False) sock.bind((UDP_IP, UDP_PORT)) mreq = struct.pack('4sl', socket.inet_aton(MCAST_GRP), socket.INADDR_ANY) diff --git a/components/mdns/mdns_networking_socket.c b/components/mdns/mdns_networking_socket.c index 8411e26e6d7..a99a9cc2d9f 100644 --- a/components/mdns/mdns_networking_socket.c +++ b/components/mdns/mdns_networking_socket.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -352,17 +352,9 @@ static bool create_pcb(mdns_if_t tcpip_if, mdns_ip_protocol_t ip_protocol) } int sock = s_interfaces[tcpip_if].sock; esp_netif_t *netif = _mdns_get_esp_netif(tcpip_if); - if (sock >= 0) { - mdns_ip_protocol_t other_ip_proto = ip_protocol == MDNS_IP_PROTOCOL_V4 ? MDNS_IP_PROTOCOL_V6 : MDNS_IP_PROTOCOL_V4; - int err = join_mdns_multicast_group(sock, netif, other_ip_proto); - if (err < 0) { - ESP_LOGE(TAG, "Failed to add ipv6 multicast group for protocol %d", ip_protocol); - return false; - } - s_interfaces[tcpip_if].proto |= (other_ip_proto == MDNS_IP_PROTOCOL_V4 ? PROTO_IPV4 : PROTO_IPV6); - return true; + if (sock < 0) { + sock = create_socket(netif); } - sock = create_socket(netif); if (sock < 0) { ESP_LOGE(TAG, "Failed to create the socket!"); return false;