From 969dc987ac0b7404420b36a7d2d944821c5d27aa Mon Sep 17 00:00:00 2001 From: David Woodhouse Date: Mon, 2 Sep 2024 13:12:04 +0100 Subject: [PATCH] Use IPADDR6_INIT() macro to set connecting IPv6 address If LwIP is built with LWIP_IPV6_SCOPES, there is a 'zone' member in struct ip6_addr which was not being initialized correctly, leading to routing failures. The tcp_connect() call would return ERR_RTE and we would completely fail to report that error. All the user would see is 'Connecting to MQTT...' over and over again. --- src/AsyncTCP.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/AsyncTCP.cpp b/src/AsyncTCP.cpp index df0739b..b1d5e37 100644 --- a/src/AsyncTCP.cpp +++ b/src/AsyncTCP.cpp @@ -729,9 +729,8 @@ bool AsyncClient::connect(IPAddress ip, uint16_t port){ #if LWIP_IPV6 bool AsyncClient::connect(IPv6Address ip, uint16_t port){ - ip_addr_t addr; - addr.type = IPADDR_TYPE_V6; - memcpy(addr.u_addr.ip6.addr, static_cast(ip), sizeof(uint32_t) * 4); + auto ipaddr = static_cast(ip); + ip_addr_t addr = IPADDR6_INIT(ipaddr[0], ipaddr[1], ipaddr[2], ipaddr[3]); return _connect(addr, port); }