diff --git a/libraries/ESP8266WiFi/src/include/UdpContext.h b/libraries/ESP8266WiFi/src/include/UdpContext.h index 7102c682f5..2bd1782e52 100644 --- a/libraries/ESP8266WiFi/src/include/UdpContext.h +++ b/libraries/ESP8266WiFi/src/include/UdpContext.h @@ -167,6 +167,26 @@ class UdpContext #endif // !LWIP_IPV6 + /* + * Add a netif (by its index) as the multicast interface + */ + void setMulticastInterface(netif* p_pNetIf) + { +#if LWIP_VERSION_MAJOR == 1 + udp_set_multicast_netif_addr(_pcb, (p_pNetIf ? p_pNetIf->ip_addr : ip_addr_any)); +#else + udp_set_multicast_netif_index(_pcb, (p_pNetIf ? netif_get_index(p_pNetIf) : NETIF_NO_INDEX)); +#endif + } + + /* + * Allow access to pcb to change eg. options + */ + udp_pcb* pcb(void) + { + return _pcb; + } + void setMulticastTTL(int ttl) { #ifdef LWIP_MAYBE_XCC @@ -205,6 +225,11 @@ class UdpContext return (pos <= _rx_buf->tot_len); } + netif* getInputNetif() const + { + return _currentAddr.input_netif; + } + CONST IPAddress& getRemoteAddress() CONST { return _currentAddr.srcaddr; @@ -269,7 +294,6 @@ class UdpContext // ref'ing it to prevent release from the below pbuf_free(deleteme) pbuf_ref(_rx_buf); } - // remove the already-consumed head of the chain pbuf_free(deleteme); _rx_buf_offset = 0; @@ -464,11 +488,12 @@ class UdpContext return; } } - #if LWIP_VERSION_MAJOR == 1 #define TEMPDSTADDR (¤t_iphdr_dest) + #define TEMPINPUTNETIF (current_netif) #else #define TEMPDSTADDR (ip_current_dest_addr()) + #define TEMPINPUTNETIF (ip_current_input_netif()) #endif // chain this helper pbuf first @@ -496,7 +521,7 @@ class UdpContext return; } // construct in place - new(PBUF_ALIGNER(pb_helper->payload)) AddrHelper(srcaddr, TEMPDSTADDR, srcport); + new(PBUF_ALIGNER(pb_helper->payload)) AddrHelper(srcaddr, TEMPDSTADDR, srcport, TEMPINPUTNETIF); pb_helper->flags = PBUF_HELPER_FLAG; // mark helper pbuf // chain it pbuf_cat(_rx_buf, pb_helper); @@ -510,6 +535,7 @@ class UdpContext _currentAddr.srcaddr = srcaddr; _currentAddr.dstaddr = TEMPDSTADDR; _currentAddr.srcport = srcport; + _currentAddr.input_netif = TEMPINPUTNETIF; DEBUGV(":urn %d\r\n", pb->tot_len); _first_buf_taken = false; @@ -522,6 +548,7 @@ class UdpContext } #undef TEMPDSTADDR + #undef TEMPINPUTNETIF } @@ -633,10 +660,11 @@ class UdpContext { IPAddress srcaddr, dstaddr; int16_t srcport; + netif* input_netif; AddrHelper() { } - AddrHelper(const ip_addr_t* src, const ip_addr_t* dst, uint16_t srcport): - srcaddr(src), dstaddr(dst), srcport(srcport) { } + AddrHelper(const ip_addr_t* src, const ip_addr_t* dst, uint16_t srcport, netif* input_netif): + srcaddr(src), dstaddr(dst), srcport(srcport), input_netif(input_netif) { } }; AddrHelper _currentAddr;