Skip to content

UdpContext::setMulticastInterface(): fix for IPv6 #5743

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

Merged
merged 2 commits into from
Feb 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cores/esp8266/AddrList.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ struct netifWrapper
String toString() const { return addr().toString(); }

// related to legacy address (_num=0, ipv4)
IPAddress ipv4 () const { return _netif->ip_addr; }
IPAddress netmask () const { return _netif->netmask; }
IPAddress gw () const { return _netif->gw; }

Expand Down
31 changes: 31 additions & 0 deletions libraries/ESP8266WiFi/src/include/UdpContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ void esp_schedule();
#include <assert.h>
}

#include <AddrList.h>

#define GET_UDP_HDR(pb) (reinterpret_cast<udp_hdr*>(((uint8_t*)((pb)->payload)) - UDP_HLEN))

class UdpContext
Expand Down Expand Up @@ -107,6 +109,33 @@ class UdpContext
udp_disconnect(_pcb);
}

#if LWIP_IPV6

void setMulticastInterface(IPAddress addr)
{
// Per 'udp_set_multicast_netif_addr()' signature and comments
// in lwIP sources:
// An IPv4 address designating a specific interface must be used.
// When an IPv6 address is given, the matching IPv4 in the same
// interface must be selected.

if (!addr.isV4())
{
for (auto a: addrList)
if (a.addr() == addr)
{
// found the IPv6 address,
// redirect parameter to IPv4 address in this interface
addr = a.ipv4();
break;
}
assert(addr.isV4());
}
udp_set_multicast_netif_addr(_pcb, ip_2_ip4((const ip_addr_t*)addr));
}

#else // !LWIP_IPV6

void setMulticastInterface(const IPAddress& addr)
{
#if LWIP_VERSION_MAJOR == 1
Expand All @@ -116,6 +145,8 @@ class UdpContext
#endif
}

#endif // !LWIP_IPV6

void setMulticastTTL(int ttl)
{
#ifdef LWIP_MAYBE_XCC
Expand Down