From 77bb25dac53ec90f559773a44262eef605ef40aa Mon Sep 17 00:00:00 2001 From: Kevin Schoedel Date: Fri, 22 Oct 2021 18:04:03 -0400 Subject: [PATCH] Fix IPv6-only builds where platform LwIP has IPv4 #### Problem When LwIP is configured for IPv6 only, its type `ip_addr_t` is identical to `ip6_addr_t`; otherwise they are different. PR #10791 made the incorrect assumption that we would never build CHIP without IPv4 when then platform LwIP is configured with IPv4, and left out the constructor overload necessary for that case. #### Change overview Enable the `ip_addr_t` constructor if `LWIP_IPV4` is true. #### Testing Built ``` scripts/build/build_examples.py \ --target esp32-m5stack-all-clusters-ipv6only build` ``` --- src/inet/IPAddress.cpp | 6 +++++- src/inet/IPAddress.h | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/inet/IPAddress.cpp b/src/inet/IPAddress.cpp index 73808abf261586..2005359bfbb96f 100644 --- a/src/inet/IPAddress.cpp +++ b/src/inet/IPAddress.cpp @@ -76,7 +76,7 @@ IPAddress::IPAddress(const ip6_addr_t & ipv6Addr) memcpy(Addr, &ipv6Addr, sizeof(ipv6Addr)); } -#if INET_CONFIG_ENABLE_IPV4 +#if INET_CONFIG_ENABLE_IPV4 || LWIP_IPV4 IPAddress::IPAddress(const ip4_addr_t & ipv4Addr) { @@ -106,6 +106,10 @@ IPAddress::IPAddress(const ip_addr_t & addr) } } +#endif // INET_CONFIG_ENABLE_IPV4 || LWIP_IPV4 + +#if INET_CONFIG_ENABLE_IPV4 + ip4_addr_t IPAddress::ToIPv4() const { ip4_addr_t ipAddr; diff --git a/src/inet/IPAddress.h b/src/inet/IPAddress.h index dd2236649e7920..a688efb543ab29 100644 --- a/src/inet/IPAddress.h +++ b/src/inet/IPAddress.h @@ -147,7 +147,7 @@ class DLL_EXPORT IPAddress #if CHIP_SYSTEM_CONFIG_USE_LWIP explicit IPAddress(const ip6_addr_t & ipv6Addr); -#if INET_CONFIG_ENABLE_IPV4 +#if INET_CONFIG_ENABLE_IPV4 || LWIP_IPV4 explicit IPAddress(const ip4_addr_t & ipv4Addr); explicit IPAddress(const ip_addr_t & addr); #endif // INET_CONFIG_ENABLE_IPV4