Implement SockAddr operator<() and operator==()

pull/1261/head
Stephen Shelton 4 years ago
parent 1c7d57f207
commit 0a40892867
No known key found for this signature in database
GPG Key ID: EE4BADACCE8B631C

@ -117,13 +117,13 @@ namespace llarp
bool bool
IpAddress::operator<(const IpAddress& other) const IpAddress::operator<(const IpAddress& other) const
{ {
throw std::runtime_error("FIXME - IpAddress::operator<()"); return createSockAddr() < other.createSockAddr();
} }
bool bool
IpAddress::operator==(const IpAddress& other) const IpAddress::operator==(const IpAddress& other) const
{ {
throw std::runtime_error("FIXME - IpAddress::operator==()"); return createSockAddr() == other.createSockAddr();
} }
std::ostream& std::ostream&

@ -147,6 +147,29 @@ namespace llarp
return &m_addr; return &m_addr;
} }
bool
SockAddr::operator<(const SockAddr& other) const
{
return (m_addr.sin6_addr.s6_addr < other.m_addr.sin6_addr.s6_addr);
}
bool
SockAddr::operator==(const SockAddr& other) const
{
if (m_addr.sin6_family != other.m_addr.sin6_family)
return false;
if (getPort() != other.getPort())
return false;
return (
0
== memcmp(
m_addr.sin6_addr.s6_addr,
other.m_addr.sin6_addr.s6_addr,
sizeof(m_addr.sin6_addr.s6_addr)));
}
void void
SockAddr::fromString(std::string_view str) SockAddr::fromString(std::string_view str)
{ {

@ -39,6 +39,12 @@ namespace llarp
operator const sockaddr*() const; operator const sockaddr*() const;
operator const sockaddr_in6*() const; operator const sockaddr_in6*() const;
bool
operator<(const SockAddr& other) const;
bool
operator==(const SockAddr& other) const;
void void
fromString(std::string_view str); fromString(std::string_view str);

Loading…
Cancel
Save