Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 9f32fc0

Browse files
Jason2866mathieucarbou
andauthoredMay 30, 2024
fix(net): Fix IPv4 address construction from ip_addr_t and comparison
Co-authored-by: Mathieu Carbou <mathieu.carbou@gmail.com>
1 parent c82366b commit 9f32fc0

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed
 

‎cores/esp32/IPAddress.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ IPAddress &IPAddress::operator=(const IPAddress &address) {
266266
}
267267

268268
bool IPAddress::operator==(const IPAddress &addr) const {
269-
return (addr._type == _type) && (memcmp(addr._address.bytes, _address.bytes, sizeof(_address.bytes)) == 0);
269+
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);
270270
}
271271

272272
bool IPAddress::operator==(const uint8_t *addr) const {
@@ -395,6 +395,7 @@ IPAddress &IPAddress::from_ip_addr_t(const ip_addr_t *addr) {
395395
#endif /* LWIP_IPV6_SCOPES */
396396
} else {
397397
_type = IPv4;
398+
memset(_address.bytes, 0, sizeof(_address.bytes));
398399
_address.dword[IPADDRESS_V4_DWORD_INDEX] = addr->u_addr.ip4.addr;
399400
}
400401
return *this;

0 commit comments

Comments
 (0)
Please sign in to comment.