mirror of
https://github.com/esp8266/Arduino.git
synced 2025-06-06 05:21:22 +03:00
UdpContext::setMulticastInterface(): fix for IPv6 (#5743)
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.
fix e3bc3c226b (r32235572)
This commit is contained in:
parent
82487e5d96
commit
1959311180
@ -118,6 +118,7 @@ struct netifWrapper
|
|||||||
String toString() const { return addr().toString(); }
|
String toString() const { return addr().toString(); }
|
||||||
|
|
||||||
// related to legacy address (_num=0, ipv4)
|
// related to legacy address (_num=0, ipv4)
|
||||||
|
IPAddress ipv4 () const { return _netif->ip_addr; }
|
||||||
IPAddress netmask () const { return _netif->netmask; }
|
IPAddress netmask () const { return _netif->netmask; }
|
||||||
IPAddress gw () const { return _netif->gw; }
|
IPAddress gw () const { return _netif->gw; }
|
||||||
|
|
||||||
|
@ -30,6 +30,8 @@ void esp_schedule();
|
|||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#include <AddrList.h>
|
||||||
|
|
||||||
#define GET_UDP_HDR(pb) (reinterpret_cast<udp_hdr*>(((uint8_t*)((pb)->payload)) - UDP_HLEN))
|
#define GET_UDP_HDR(pb) (reinterpret_cast<udp_hdr*>(((uint8_t*)((pb)->payload)) - UDP_HLEN))
|
||||||
|
|
||||||
class UdpContext
|
class UdpContext
|
||||||
@ -107,6 +109,33 @@ public:
|
|||||||
udp_disconnect(_pcb);
|
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)
|
void setMulticastInterface(const IPAddress& addr)
|
||||||
{
|
{
|
||||||
#if LWIP_VERSION_MAJOR == 1
|
#if LWIP_VERSION_MAJOR == 1
|
||||||
@ -116,6 +145,8 @@ public:
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif // !LWIP_IPV6
|
||||||
|
|
||||||
void setMulticastTTL(int ttl)
|
void setMulticastTTL(int ttl)
|
||||||
{
|
{
|
||||||
#ifdef LWIP_MAYBE_XCC
|
#ifdef LWIP_MAYBE_XCC
|
||||||
|
Loading…
x
Reference in New Issue
Block a user