Skip to content

Commit

Permalink
fix(net): Fix IPv4 address construction from ip_addr_t and comparison (
Browse files Browse the repository at this point in the history
  • Loading branch information
mathieucarbou committed May 30, 2024
1 parent 79b8350 commit 0866fd5
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion cores/esp32/IPAddress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 0866fd5

Please sign in to comment.