Skip to content

Commit ed5abe1

Browse files
committed
Net: Proper CService deserialization + GetIn6Addr return false if addr isn't an IPv6 addr
1 parent 86d73fb commit ed5abe1

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

src/netaddress.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ bool operator==(const CNetAddr& a, const CNetAddr& b)
318318

319319
bool operator!=(const CNetAddr& a, const CNetAddr& b)
320320
{
321-
return (memcmp(a.ip, b.ip, 16) != 0);
321+
return a.m_net != b.m_net || (memcmp(a.ip, b.ip, 16) != 0);
322322
}
323323

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

337+
/**
338+
* Try to get our IPv6 address.
339+
*
340+
* @param[out] pipv6Addr The in6_addr struct to which to copy.
341+
*
342+
* @returns Whether or not the operation was successful, in particular, whether
343+
* or not our address was an IPv6 address.
344+
*
345+
* @see CNetAddr::IsIPv6()
346+
*/
337347
bool CNetAddr::GetIn6Addr(struct in6_addr* pipv6Addr) const
338348
{
349+
if (!IsIPv6()) {
350+
return false;
351+
}
339352
memcpy(pipv6Addr, ip, 16);
340353
return true;
341354
}

src/netaddress.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,11 @@ class CService : public CNetAddr
223223
CService(const struct in6_addr& ipv6Addr, uint16_t port);
224224
CService(const struct sockaddr_in6& addr);
225225

226-
SERIALIZE_METHODS(CService, obj) { READWRITE(obj.ip, Using<BigEndianFormatter<2>>(obj.port)); }
226+
SERIALIZE_METHODS(CService, obj)
227+
{
228+
READWRITEAS(CNetAddr, obj);
229+
READWRITE(Using<BigEndianFormatter<2>>(obj.port));
230+
}
227231
};
228232

229233
#endif // PIVX_NETADDRESS_H

0 commit comments

Comments
 (0)