summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/socket.h7
-rw-r--r--src/dns.cpp2
-rw-r--r--src/socket.cpp11
3 files changed, 17 insertions, 3 deletions
diff --git a/include/socket.h b/include/socket.h
index 91a10d1f9..b09581cd6 100644
--- a/include/socket.h
+++ b/include/socket.h
@@ -44,7 +44,8 @@ namespace irc
*/
namespace sockets
{
- union CoreExport sockaddrs {
+ union CoreExport sockaddrs
+ {
struct sockaddr sa;
struct sockaddr_in in4;
struct sockaddr_in6 in6;
@@ -56,9 +57,11 @@ namespace irc
std::string addr() const;
/** Return human-readable IP/port pair */
std::string str() const;
+ bool operator==(const sockaddrs& other) const;
+ inline bool operator!=(const sockaddrs& other) const { return !(*this == other); }
};
- struct cidr_mask
+ struct CoreExport cidr_mask
{
/** Type, AF_INET or AF_INET6 */
unsigned char type;
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;