Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Additions to UdpContext needed for LEAmDNS2 #7048

Merged
merged 8 commits into from
Feb 24, 2020
38 changes: 33 additions & 5 deletions libraries/ESP8266WiFi/src/include/UdpContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 ? ip_2_ip4(p_pNetIf->ip_addr) : ip_addr_any));
d-a-v marked this conversation as resolved.
Show resolved Hide resolved
#else
udp_set_multicast_netif_index(_pcb, (p_pNetIf ? netif_get_index(p_pNetIf) : 0));
#endif
}

/*
* Allow access to pcb to change eg. options
*/
udp_pcb* pcb(void)
{
return _pcb;
}

void setMulticastTTL(int ttl)
{
#ifdef LWIP_MAYBE_XCC
Expand Down Expand Up @@ -205,6 +225,11 @@ class UdpContext
return (pos <= _rx_buf->len);
}

netif* getInputNetif() const
{
return _currentAddr.input_netif;
}

CONST IPAddress& getRemoteAddress() CONST
{
return _currentAddr.srcaddr;
Expand Down Expand Up @@ -265,7 +290,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;
Expand Down Expand Up @@ -454,11 +478,12 @@ class UdpContext
return;
}
}

#if LWIP_VERSION_MAJOR == 1
#define TEMPDSTADDR (&current_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
Expand Down Expand Up @@ -486,7 +511,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);
Expand All @@ -500,6 +525,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;
Expand All @@ -512,6 +538,7 @@ class UdpContext
}

#undef TEMPDSTADDR
#undef TEMPINPUTNETIF

}

Expand Down Expand Up @@ -539,10 +566,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;

Expand Down