Skip to content

Commit

Permalink
Net: Proper CService deserialization + GetIn6Addr return false if add…
Browse files Browse the repository at this point in the history
…r isn't an IPv6 addr
  • Loading branch information
furszy committed Aug 10, 2021
1 parent 86d73fb commit ed5abe1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
15 changes: 14 additions & 1 deletion src/netaddress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ bool operator==(const CNetAddr& a, const CNetAddr& b)

bool operator!=(const CNetAddr& a, const CNetAddr& b)
{
return (memcmp(a.ip, b.ip, 16) != 0);
return a.m_net != b.m_net || (memcmp(a.ip, b.ip, 16) != 0);
}

bool operator<(const CNetAddr& a, const CNetAddr& b)
Expand All @@ -334,8 +334,21 @@ bool CNetAddr::GetInAddr(struct in_addr* pipv4Addr) const
return true;
}

/**
* Try to get our IPv6 address.
*
* @param[out] pipv6Addr The in6_addr struct to which to copy.
*
* @returns Whether or not the operation was successful, in particular, whether
* or not our address was an IPv6 address.
*
* @see CNetAddr::IsIPv6()
*/
bool CNetAddr::GetIn6Addr(struct in6_addr* pipv6Addr) const
{
if (!IsIPv6()) {
return false;
}
memcpy(pipv6Addr, ip, 16);
return true;
}
Expand Down
6 changes: 5 additions & 1 deletion src/netaddress.h
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,11 @@ class CService : public CNetAddr
CService(const struct in6_addr& ipv6Addr, uint16_t port);
CService(const struct sockaddr_in6& addr);

SERIALIZE_METHODS(CService, obj) { READWRITE(obj.ip, Using<BigEndianFormatter<2>>(obj.port)); }
SERIALIZE_METHODS(CService, obj)
{
READWRITEAS(CNetAddr, obj);
READWRITE(Using<BigEndianFormatter<2>>(obj.port));
}
};

#endif // PIVX_NETADDRESS_H

0 comments on commit ed5abe1

Please sign in to comment.