@@ -57,6 +57,14 @@ struct pbuf {
57
57
#define s6_addr32 un.u32_addr
58
58
#endif // CONFIG_IDF_TARGET_LINUX
59
59
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
+
60
68
static void delete_socket (int sock )
61
69
{
62
70
close (sock );
@@ -326,10 +334,6 @@ void sock_recv_task(void *arg)
326
334
static void mdns_networking_init (void )
327
335
{
328
336
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
- }
333
337
s_run_sock_recv_task = true;
334
338
xTaskCreate ( sock_recv_task , "mdns recv task" , 3 * 1024 , NULL , 5 , NULL );
335
339
}
@@ -362,16 +366,18 @@ static bool create_pcb(mdns_if_t tcpip_if, mdns_ip_protocol_t ip_protocol)
362
366
ESP_LOGE (TAG , "Failed to add ipv6 multicast group for protocol %d" , ip_protocol );
363
367
}
364
368
s_interfaces [tcpip_if ].proto |= (ip_protocol == MDNS_IP_PROTOCOL_V4 ? PROTO_IPV4 : PROTO_IPV6 );
369
+ s_interfaces [tcpip_if ].sock = sock ;
365
370
return true;
366
371
}
367
372
368
373
esp_err_t _mdns_pcb_init (mdns_if_t tcpip_if , mdns_ip_protocol_t ip_protocol )
369
374
{
370
- mdns_networking_init ();
371
375
ESP_LOGI (TAG , "_mdns_pcb_init(tcpip_if=%d, ip_protocol=%d)" , tcpip_if , ip_protocol );
372
376
if (!create_pcb (tcpip_if , ip_protocol )) {
373
377
return ESP_FAIL ;
374
378
}
379
+
380
+ mdns_networking_init ();
375
381
return ESP_OK ;
376
382
}
377
383
0 commit comments