Skip to content

Commit 4b2bf45

Browse files
authored
Additions to UdpContext needed for LEAmDNS2 (#7048)
* Addition to UdpContext needed for LEAmDNS2
1 parent 2d58be7 commit 4b2bf45

File tree

1 file changed

+33
-5
lines changed

1 file changed

+33
-5
lines changed

libraries/ESP8266WiFi/src/include/UdpContext.h

+33-5
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,26 @@ class UdpContext
167167

168168
#endif // !LWIP_IPV6
169169

170+
/*
171+
* Add a netif (by its index) as the multicast interface
172+
*/
173+
void setMulticastInterface(netif* p_pNetIf)
174+
{
175+
#if LWIP_VERSION_MAJOR == 1
176+
udp_set_multicast_netif_addr(_pcb, (p_pNetIf ? p_pNetIf->ip_addr : ip_addr_any));
177+
#else
178+
udp_set_multicast_netif_index(_pcb, (p_pNetIf ? netif_get_index(p_pNetIf) : NETIF_NO_INDEX));
179+
#endif
180+
}
181+
182+
/*
183+
* Allow access to pcb to change eg. options
184+
*/
185+
udp_pcb* pcb(void)
186+
{
187+
return _pcb;
188+
}
189+
170190
void setMulticastTTL(int ttl)
171191
{
172192
#ifdef LWIP_MAYBE_XCC
@@ -205,6 +225,11 @@ class UdpContext
205225
return (pos <= _rx_buf->tot_len);
206226
}
207227

228+
netif* getInputNetif() const
229+
{
230+
return _currentAddr.input_netif;
231+
}
232+
208233
CONST IPAddress& getRemoteAddress() CONST
209234
{
210235
return _currentAddr.srcaddr;
@@ -269,7 +294,6 @@ class UdpContext
269294
// ref'ing it to prevent release from the below pbuf_free(deleteme)
270295
pbuf_ref(_rx_buf);
271296
}
272-
// remove the already-consumed head of the chain
273297
pbuf_free(deleteme);
274298

275299
_rx_buf_offset = 0;
@@ -464,11 +488,12 @@ class UdpContext
464488
return;
465489
}
466490
}
467-
468491
#if LWIP_VERSION_MAJOR == 1
469492
#define TEMPDSTADDR (&current_iphdr_dest)
493+
#define TEMPINPUTNETIF (current_netif)
470494
#else
471495
#define TEMPDSTADDR (ip_current_dest_addr())
496+
#define TEMPINPUTNETIF (ip_current_input_netif())
472497
#endif
473498

474499
// chain this helper pbuf first
@@ -496,7 +521,7 @@ class UdpContext
496521
return;
497522
}
498523
// construct in place
499-
new(PBUF_ALIGNER(pb_helper->payload)) AddrHelper(srcaddr, TEMPDSTADDR, srcport);
524+
new(PBUF_ALIGNER(pb_helper->payload)) AddrHelper(srcaddr, TEMPDSTADDR, srcport, TEMPINPUTNETIF);
500525
pb_helper->flags = PBUF_HELPER_FLAG; // mark helper pbuf
501526
// chain it
502527
pbuf_cat(_rx_buf, pb_helper);
@@ -510,6 +535,7 @@ class UdpContext
510535
_currentAddr.srcaddr = srcaddr;
511536
_currentAddr.dstaddr = TEMPDSTADDR;
512537
_currentAddr.srcport = srcport;
538+
_currentAddr.input_netif = TEMPINPUTNETIF;
513539

514540
DEBUGV(":urn %d\r\n", pb->tot_len);
515541
_first_buf_taken = false;
@@ -522,6 +548,7 @@ class UdpContext
522548
}
523549

524550
#undef TEMPDSTADDR
551+
#undef TEMPINPUTNETIF
525552

526553
}
527554

@@ -633,10 +660,11 @@ class UdpContext
633660
{
634661
IPAddress srcaddr, dstaddr;
635662
int16_t srcport;
663+
netif* input_netif;
636664

637665
AddrHelper() { }
638-
AddrHelper(const ip_addr_t* src, const ip_addr_t* dst, uint16_t srcport):
639-
srcaddr(src), dstaddr(dst), srcport(srcport) { }
666+
AddrHelper(const ip_addr_t* src, const ip_addr_t* dst, uint16_t srcport, netif* input_netif):
667+
srcaddr(src), dstaddr(dst), srcport(srcport), input_netif(input_netif) { }
640668
};
641669
AddrHelper _currentAddr;
642670

0 commit comments

Comments
 (0)