From b8c3c5d25b84b358fc93eea0e885372dcad01480 Mon Sep 17 00:00:00 2001 From: brain Date: Fri, 4 Aug 2006 11:03:21 +0000 Subject: Safety wrapper defines for ipv6 code on ipv4 ircds git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@4697 e03df62e-2008-0410-955e-edbf42e46eb7 --- src/dns.cpp | 7 ++++++- src/users.cpp | 25 +++++++++++-------------- 2 files changed, 17 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/dns.cpp b/src/dns.cpp index 42db21424..0a22b28d8 100644 --- a/src/dns.cpp +++ b/src/dns.cpp @@ -453,7 +453,7 @@ int DNS::GetNameForce(const char *ip, ForceProtocol fp) DNSHeader h; int id; int length; - +#ifdef SUPPORT_IP6LINKS if (fp == PROTOCOL_IPV6) { in6_addr i; @@ -466,6 +466,7 @@ int DNS::GetNameForce(const char *ip, ForceProtocol fp) return -1; } else +#endif { in_addr i; if (inet_aton(ip, &i)) @@ -493,6 +494,7 @@ int DNS::GetNameForce(const char *ip, ForceProtocol fp) void DNS::MakeIP6Int(char* query, const in6_addr *ip) { +#ifdef SUPPORT_IP6LINKS const char* hex = "0123456789abcdef"; for (int index = 31; index >= 0; index--) /* for() loop steps twice per byte */ { @@ -505,6 +507,9 @@ void DNS::MakeIP6Int(char* query, const in6_addr *ip) *query++ = '.'; /* Seperator */ } strcpy(query,"ip6.arpa"); /* Suffix the string */ +#else + *query = 0; +#endif } /* Return the next id which is ready, and the result attached to it */ diff --git a/src/users.cpp b/src/users.cpp index 85d64d462..74f70b458 100644 --- a/src/users.cpp +++ b/src/users.cpp @@ -895,20 +895,11 @@ long FindMatchingGlobal(userrec* user) long x = 0; for (user_hash::const_iterator a = clientlist.begin(); a != clientlist.end(); a++) { -#ifdef IPV6 - /* I dont think theres any faster way of matching two ipv6 addresses than memcmp - * Let me know if you think of one. - */ - in6_addr* s1 = &(((sockaddr_in6*)&a->second->ip)->sin6_addr); - in6_addr* s2 = &(((sockaddr_in6*)&user->ip)->sin6_addr); - if (!memcmp(s1->s6_addr, s2->s6_addr, sizeof(in6_addr))) - x++; -#else - in_addr* s1 = &((sockaddr_in*)&a->second->ip)->sin_addr; - in_addr* s2 = &((sockaddr_in*)&user->ip)->sin_addr; - if (s1->s_addr == s2->s_addr) - x++; -#endif + /* We have to match ip's as strings - we don't know what protocol + * a remote user may be using + */ + if (!strcasecmp(a->second->GetIPString(), user->GetIPString())) + x++; } return x; } @@ -1111,6 +1102,7 @@ void userrec::SetSockAddr(int protocol_family, const char* ip, int port) { switch (protocol_family) { +#ifdef SUPPORT_IP6LINKS case AF_INET6: { sockaddr_in6* sin = (sockaddr_in6*)&this->ip; @@ -1119,6 +1111,7 @@ void userrec::SetSockAddr(int protocol_family, const char* ip, int port) inet_pton(AF_INET6, ip, &sin->sin6_addr); } break; +#endif case AF_INET: { sockaddr_in* sin = (sockaddr_in*)&this->ip; @@ -1137,12 +1130,14 @@ int userrec::GetPort() { switch (this->GetProtocolFamily()) { +#ifdef SUPPORT_IP6LINKS case AF_INET6: { sockaddr_in6* sin = (sockaddr_in6*)&this->ip; return sin->sin6_port; } break; +#endif case AF_INET: { sockaddr_in* sin = (sockaddr_in*)&this->ip; @@ -1168,6 +1163,7 @@ const char* userrec::GetIPString() switch (this->GetProtocolFamily()) { +#ifdef SUPPORT_IP6LINKS case AF_INET6: { sockaddr_in6* sin = (sockaddr_in6*)&this->ip; @@ -1175,6 +1171,7 @@ const char* userrec::GetIPString() return buf; } break; +#endif case AF_INET: { sockaddr_in* sin = (sockaddr_in*)&this->ip; -- cgit v1.2.3