FIX IPv4-ONLY AsyncUDP::listenMulticast() for receiving IPv6 #11443
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description of Change
AsyncUDP::listenMulticast() properly receives packets sent to IPv4 multicast addresses like 239.1.2.3, but it is not receiving packets sent to IPv6 multicast addresses like ff12::6ood:cafe.
The root cause is a bit hidden: listen(NULL, port) would match AsyncUDP::listen(const ip_addr_t *addr, uint16_t port), which calls _udp_bind(_pcb, addr, port), which uses the lwIP API to call udp_bind(struct udp_pcb *pcb, const ip_addr_t *ipaddr, u16_t port) at the end. If lwIP has LWIP_IPV4 enabled, it checks if ipaddr == NULL and sets it to IP4_ADDR_ANY. So an IPv6 address is never bound.
This fix checks the IP address passed to AsyncUDP::listenMulticast(). If it is an IPv6 address, it constructs and passes the IPv6 any address (::); otherwise (IPv4), it constructs and passes the IPv4 any address (0.0.0.0).
Tests scenarios
Heltec v3
Related links
Fix #9970