Skip to content
Snippets Groups Projects
Commit f7822c0c authored by Benny Baumann's avatar Benny Baumann
Browse files

add: Implement socketaddress comparison operators

parent 8d4a8ae3
No related branches found
No related tags found
1 merge request!1First unit tests
......@@ -149,6 +149,31 @@ COMPILER_RESTORE("-Weffc++");
return len;
}
inline bool operator==(const socketaddr& _other) const {
if (!(this->family() == _other.family())) {
return false;
}
switch (_other.family()) {
case AF_INET:
return (((sockaddr_in*) &this->addr)->sin_addr.s_addr == ((sockaddr_in*) &_other.addr)->sin_addr.s_addr)
&& (((sockaddr_in*) &this->addr)->sin_port == ((sockaddr_in*) &_other.addr)->sin_port);
case AF_INET6:
return 0 == memcmp(&((sockaddr_in6*) &this->addr)->sin6_addr, &((sockaddr_in6*) &_other.addr)->sin6_addr, sizeof(in6_addr))
&& (((sockaddr_in6*) &this->addr)->sin6_port == ((sockaddr_in6*) &_other.addr)->sin6_port);
default:
return
this->len == _other.len &&
0 == memcmp(&this->addr, &_other.addr, this->len);
}
return true;
}
inline bool operator!=(const socketaddr& _other) const {
return !(*this == _other);
}
std::string str() const {
std::ostringstream oss;
oss << "SocketAddress: ";
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment