summaryrefslogtreecommitdiff
path: root/src/sockets.cpp
diff options
context:
space:
mode:
authorAdam <Adam@anope.org>2012-11-05 22:17:47 -0500
committerAdam <Adam@anope.org>2012-11-06 11:02:12 -0500
commit53b2bdfe5e157a9e5ca5d08873edebcd04511ae1 (patch)
treef94c8603ffe475405ea668c629eddd7c8ba0891e /src/sockets.cpp
parent27ab6a686cb271ea8eae7a243906af5bebeb83d7 (diff)
Use std::tr1::unordered_map for a few of the larger maps
Diffstat (limited to 'src/sockets.cpp')
-rw-r--r--src/sockets.cpp38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/sockets.cpp b/src/sockets.cpp
index 5cf567de5..861df6976 100644
--- a/src/sockets.cpp
+++ b/src/sockets.cpp
@@ -295,6 +295,44 @@ bool cidr::operator<(const cidr &other) const
}
}
+bool cidr::operator==(const cidr &other) const
+{
+ return !(*this < other) && !(other < *this);
+}
+
+bool cidr::operator!=(const cidr &other) const
+{
+ return !(*this == other);
+}
+
+size_t cidr::hash::operator()(const cidr &s) const
+{
+ switch (s.addr.sa.sa_family)
+ {
+ case AF_INET:
+ {
+ unsigned int m = 0xFFFFFFFFU >> (32 - s.cidr_len);
+ return s.addr.sa4.sin_addr.s_addr & m;
+ }
+ case AF_INET6:
+ {
+ size_t h = 0;
+
+ for (int i = 0; i < s.cidr_len / 8; ++i)
+ h ^= (s.addr.sa6.sin6_addr.s6_addr[i] << ((i * 8) % sizeof(size_t)));
+
+ int remaining = s.cidr_len % 8;
+ unsigned char m = 0xFF << (8 - remaining);
+
+ h ^= s.addr.sa6.sin6_addr.s6_addr[s.cidr_len / 8] & m;
+
+ return h;
+ }
+ default:
+ throw CoreException("Unknown AFTYPE for cidr");
+ }
+}
+
/** Receive something from the buffer
* @param s The socket
* @param buf The buf to read to