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 | |
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')
-rw-r--r-- | src/dns.cpp | 2 | ||||
-rw-r--r-- | src/socket.cpp | 11 |
2 files changed, 12 insertions, 1 deletions
diff --git a/src/dns.cpp b/src/dns.cpp index ef9ac12bf..945e1fb15 100644 --- a/src/dns.cpp +++ b/src/dns.cpp @@ -578,7 +578,7 @@ DNSResult DNS::GetResult() * * -- Thanks jilles for pointing this one out. */ - if (memcmp(&from, &myserver, sizeof(irc::sockets::sockaddrs))) + if (from != myserver) { ServerInstance->Logs->Log("RESOLVER",DEBUG,"Got a result from the wrong server! Bad NAT or DNS forging attempt? '%s' != '%s'", from.str().c_str(), myserver.str().c_str()); 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; |