diff options
author | Daniel De Graaf <danieldg@inspircd.org> | 2010-04-26 19:08:39 -0500 |
---|---|---|
committer | Daniel De Graaf <danieldg@inspircd.org> | 2010-04-26 19:08:43 -0500 |
commit | dc203f9f201e5a49677d3982f0b6c7d8610cc484 (patch) | |
tree | bd8b210c43ff5ac16167e56d76589425a5428cab /src/socket.cpp | |
parent | 1ac8c54574d2d68674ce0f3a5b15dce5d330049b (diff) |
Define comparator for irc::sockets::sockaddrs
This only compares IP/port, which ignores IPv6 flow information and
scope ID, which aren't important in testing for equality.
Diffstat (limited to 'src/socket.cpp')
-rw-r--r-- | src/socket.cpp | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/socket.cpp b/src/socket.cpp index 3ee996193..a04523ddf 100644 --- a/src/socket.cpp +++ b/src/socket.cpp @@ -239,6 +239,17 @@ int irc::sockets::sockaddrs::sa_size() const return 0; } +bool irc::sockets::sockaddrs::operator==(const irc::sockets::sockaddrs& other) const +{ + if (sa.sa_family != other.sa.sa_family) + return false; + if (sa.sa_family == AF_INET) + return (in4.sin_port == other.in4.sin_port) && (in4.sin_addr.s_addr == other.in4.sin_addr.s_addr); + if (sa.sa_family == AF_INET6) + return (in6.sin6_port == other.in6.sin6_port) && !memcmp(in6.sin6_addr.s6_addr, other.in6.sin6_addr.s6_addr, 16); + return !memcmp(this, &other, sizeof(*this)); +} + static void sa2cidr(irc::sockets::cidr_mask& cidr, const irc::sockets::sockaddrs& sa, int range) { const unsigned char* base; |