@@ -242,6 +242,9 @@ typedef struct {
242
242
struct tcpip_api_call_data call ;
243
243
tcpip_adapter_if_t tcpip_if ;
244
244
mdns_ip_protocol_t ip_protocol ;
245
+ struct pbuf * pbt ;
246
+ const ip_addr_t * ip ;
247
+ uint16_t port ;
245
248
esp_err_t err ;
246
249
} mdns_api_call_t ;
247
250
@@ -277,7 +280,7 @@ esp_err_t _mdns_pcb_init(tcpip_adapter_if_t tcpip_if, mdns_ip_protocol_t ip_prot
277
280
.tcpip_if = tcpip_if ,
278
281
.ip_protocol = ip_protocol
279
282
};
280
- tcpip_api_call (_mdns_pcb_init_api , ( struct tcpip_api_call_data * ) & msg );
283
+ tcpip_api_call (_mdns_pcb_init_api , & msg . call );
281
284
return msg .err ;
282
285
}
283
286
@@ -287,29 +290,44 @@ esp_err_t _mdns_pcb_deinit(tcpip_adapter_if_t tcpip_if, mdns_ip_protocol_t ip_pr
287
290
.tcpip_if = tcpip_if ,
288
291
.ip_protocol = ip_protocol
289
292
};
290
- tcpip_api_call (_mdns_pcb_deinit_api , ( struct tcpip_api_call_data * ) & msg );
293
+ tcpip_api_call (_mdns_pcb_deinit_api , & msg . call );
291
294
return msg .err ;
292
295
}
293
296
294
- size_t _mdns_udp_pcb_write ( tcpip_adapter_if_t tcpip_if , mdns_ip_protocol_t ip_protocol , const ip_addr_t * ip , uint16_t port , uint8_t * data , size_t len )
297
+ static err_t _mdns_udp_pcb_write_api ( struct tcpip_api_call_data * api_call_msg )
295
298
{
296
- struct netif * netif = NULL ;
297
299
void * nif = NULL ;
298
- esp_err_t err = tcpip_adapter_get_netif (tcpip_if , & nif );
299
- netif = (struct netif * )nif ;
300
+ mdns_api_call_t * msg = (mdns_api_call_t * )api_call_msg ;
301
+ mdns_pcb_t * _pcb = & _mdns_server -> interfaces [msg -> tcpip_if ].pcbs [msg -> ip_protocol ];
302
+ esp_err_t err = tcpip_adapter_get_netif (msg -> tcpip_if , & nif );
300
303
if (err ) {
301
- return 0 ;
304
+ msg -> err = err ;
305
+ return err ;
302
306
}
307
+ err = udp_sendto_if (_pcb -> pcb , msg -> pbt , msg -> ip , msg -> port , (struct netif * )nif );
308
+ pbuf_free (msg -> pbt );
309
+ msg -> err = err ;
310
+ return err ;
311
+ }
303
312
313
+ size_t _mdns_udp_pcb_write (tcpip_adapter_if_t tcpip_if , mdns_ip_protocol_t ip_protocol , const ip_addr_t * ip , uint16_t port , uint8_t * data , size_t len )
314
+ {
304
315
struct pbuf * pbt = pbuf_alloc (PBUF_TRANSPORT , len , PBUF_RAM );
305
316
if (pbt == NULL ) {
306
317
return 0 ;
307
318
}
308
319
memcpy ((uint8_t * )pbt -> payload , data , len );
309
320
310
- err = udp_sendto_if (_mdns_server -> interfaces [tcpip_if ].pcbs [ip_protocol ].pcb , pbt , ip , port , netif );
311
- pbuf_free (pbt );
312
- if (err ) {
321
+ mdns_api_call_t msg = {
322
+ .tcpip_if = tcpip_if ,
323
+ .ip_protocol = ip_protocol ,
324
+ .pbt = pbt ,
325
+ .ip = ip ,
326
+ .port = port
327
+ };
328
+ tcpip_api_call (_mdns_udp_pcb_write_api , & msg .call );
329
+
330
+ if (msg .err ) {
313
331
return 0 ;
314
332
}
315
333
return len ;
0 commit comments