Skip to content

Commit ee9b04f

Browse files
antmakdavid-cermak
authored andcommitted
fix(mdns): socket networking to init interfaces properly
1 parent d238e93 commit ee9b04f

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

components/mdns/mdns_networking_socket.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,14 @@ struct pbuf {
5757
#define s6_addr32 un.u32_addr
5858
#endif // CONFIG_IDF_TARGET_LINUX
5959

60+
static void __attribute__((constructor)) ctor_networking_socket(void)
61+
{
62+
for (int i = 0; i < sizeof(s_interfaces) / sizeof(s_interfaces[0]); ++i) {
63+
s_interfaces[i].sock = -1;
64+
s_interfaces[i].proto = 0;
65+
}
66+
}
67+
6068
static void delete_socket(int sock)
6169
{
6270
close(sock);
@@ -326,10 +334,6 @@ void sock_recv_task(void *arg)
326334
static void mdns_networking_init(void)
327335
{
328336
if (s_run_sock_recv_task == false) {
329-
for (int i = 0; i < sizeof(s_interfaces) / sizeof(s_interfaces[0]); ++i) {
330-
s_interfaces[i].sock = -1;
331-
s_interfaces[i].proto = 0;
332-
}
333337
s_run_sock_recv_task = true;
334338
xTaskCreate( sock_recv_task, "mdns recv task", 3 * 1024, NULL, 5, NULL );
335339
}
@@ -362,16 +366,18 @@ static bool create_pcb(mdns_if_t tcpip_if, mdns_ip_protocol_t ip_protocol)
362366
ESP_LOGE(TAG, "Failed to add ipv6 multicast group for protocol %d", ip_protocol);
363367
}
364368
s_interfaces[tcpip_if].proto |= (ip_protocol == MDNS_IP_PROTOCOL_V4 ? PROTO_IPV4 : PROTO_IPV6);
369+
s_interfaces[tcpip_if].sock = sock;
365370
return true;
366371
}
367372

368373
esp_err_t _mdns_pcb_init(mdns_if_t tcpip_if, mdns_ip_protocol_t ip_protocol)
369374
{
370-
mdns_networking_init();
371375
ESP_LOGI(TAG, "_mdns_pcb_init(tcpip_if=%d, ip_protocol=%d)", tcpip_if, ip_protocol);
372376
if (!create_pcb(tcpip_if, ip_protocol)) {
373377
return ESP_FAIL;
374378
}
379+
380+
mdns_networking_init();
375381
return ESP_OK;
376382
}
377383

0 commit comments

Comments
 (0)