From 0866fd5898b673a9213727d5aa45f451d5bc4b72 Mon Sep 17 00:00:00 2001 From: Mathieu Carbou Date: Thu, 30 May 2024 00:06:00 +0200 Subject: [PATCH] fix(net): Fix IPv4 address construction from ip_addr_t and comparison (#9724) --- cores/esp32/IPAddress.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cores/esp32/IPAddress.cpp b/cores/esp32/IPAddress.cpp index 1db800a4bfa..b4fc4c3f7e0 100644 --- a/cores/esp32/IPAddress.cpp +++ b/cores/esp32/IPAddress.cpp @@ -266,7 +266,7 @@ IPAddress &IPAddress::operator=(const IPAddress &address) { } bool IPAddress::operator==(const IPAddress &addr) const { - return (addr._type == _type) && (memcmp(addr._address.bytes, _address.bytes, sizeof(_address.bytes)) == 0); + return (addr._type == _type) && (_type == IPType::IPv4 ? addr._address.dword[IPADDRESS_V4_DWORD_INDEX] == _address.dword[IPADDRESS_V4_DWORD_INDEX] : memcmp(addr._address.bytes, _address.bytes, sizeof(_address.bytes)) == 0); } bool IPAddress::operator==(const uint8_t *addr) const { @@ -395,6 +395,7 @@ IPAddress &IPAddress::from_ip_addr_t(const ip_addr_t *addr) { #endif /* LWIP_IPV6_SCOPES */ } else { _type = IPv4; + memset(_address.bytes, 0, sizeof(_address.bytes)); _address.dword[IPADDRESS_V4_DWORD_INDEX] = addr->u_addr.ip4.addr; } return *this;