Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 7b85dd0

Browse filesBrowse files
nikiwaibelNiki W. Waibel
authored and
Niki W. Waibel
committed
fix(libraries/asyncudp): IPv4 ONLY listenMulticast()
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).
1 parent 31d22e6 commit 7b85dd0
Copy full SHA for 7b85dd0

File tree

Expand file treeCollapse file tree

1 file changed

+14
-1
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+14
-1
lines changed

‎libraries/AsyncUDP/src/AsyncUDP.cpp

Copy file name to clipboardExpand all lines: libraries/AsyncUDP/src/AsyncUDP.cpp
+14-1Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,8 @@ static esp_err_t joinMulticastGroup(const ip_addr_t *addr, bool join, tcpip_adap
682682
}
683683

684684
bool AsyncUDP::listenMulticast(const ip_addr_t *addr, uint16_t port, uint8_t ttl, tcpip_adapter_if_t tcpip_if) {
685+
ip_addr_t bind_addr;
686+
685687
if (!ip_addr_ismulticast(addr)) {
686688
return false;
687689
}
@@ -690,7 +692,18 @@ bool AsyncUDP::listenMulticast(const ip_addr_t *addr, uint16_t port, uint8_t ttl
690692
return false;
691693
}
692694

693-
if (!listen(NULL, port)) {
695+
#if CONFIG_LWIP_IPV6
696+
if (IP_IS_V6(addr)) {
697+
IP_SET_TYPE(&bind_addr, IPADDR_TYPE_V6);
698+
ip6_addr_set_any(&bind_addr.u_addr.ip6);
699+
} else {
700+
#endif
701+
IP_SET_TYPE(&bind_addr, IPADDR_TYPE_V4);
702+
ip4_addr_set_any(&bind_addr.u_addr.ip4);
703+
#if CONFIG_LWIP_IPV6
704+
}
705+
#endif
706+
if (!listen(&bind_addr, port)) {
694707
return false;
695708
}
696709

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.