From f8ca9e22cc2c82d800c13e9a856bee01d777b9bb Mon Sep 17 00:00:00 2001 From: brain Date: Fri, 4 Aug 2006 19:32:11 +0000 Subject: Fix global session checks git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@4715 e03df62e-2008-0410-955e-edbf42e46eb7 --- include/users.h | 6 +++++- src/users.cpp | 47 ++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 51 insertions(+), 2 deletions(-) diff --git a/include/users.h b/include/users.h index 743ea6c8a..0b9599548 100644 --- a/include/users.h +++ b/include/users.h @@ -282,10 +282,14 @@ class userrec : public connection */ int GetProtocolFamily(); - /** Get IP string from sockaddr + /** Get IP string from sockaddr, using static internal buffer */ const char* GetIPString(); + /** Get IP string from sockaddr, using caller-specified buffer + */ + const char* GetIPString(char* buf); + /* Write error string */ std::string WriteError; diff --git a/src/users.cpp b/src/users.cpp index 3a7eca81f..7ed5e2fd6 100644 --- a/src/users.cpp +++ b/src/users.cpp @@ -917,13 +917,15 @@ void AddClient(int socket, int port, bool iscached, insp_inaddr ip) long FindMatchingGlobal(userrec* user) { + char u1[1024]; + char u2[1024]; long x = 0; for (user_hash::const_iterator a = clientlist.begin(); a != clientlist.end(); a++) { /* 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())) + if (!strcasecmp(a->second->GetIPString(u1), user->GetIPString(u2))) x++; } return x; @@ -1232,3 +1234,46 @@ const char* userrec::GetIPString() return ""; } +const char* userrec::GetIPString(char* buf) +{ + static char temp[1024]; + + if (this->ip == NULL) + { + *buf = 0; + return buf; + } + + switch (this->GetProtocolFamily()) + { +#ifdef SUPPORT_IP6LINKS + case AF_INET6: + { + sockaddr_in6* sin = (sockaddr_in6*)this->ip; + inet_ntop(sin->sin6_family, &sin->sin6_addr, buf, sizeof(buf)); + /* IP addresses starting with a : on irc are a Bad Thing (tm) */ + if (*buf == ':') + { + strlcpy(&temp[1], buf, sizeof(temp)); + *temp = '0'; + strlcpy(buf, temp, sizeof(temp)); + } + return buf; + } + break; +#endif + case AF_INET: + { + sockaddr_in* sin = (sockaddr_in*)this->ip; + inet_ntop(sin->sin_family, &sin->sin_addr, buf, sizeof(buf)); + return buf; + } + break; + + default: + log(DEBUG,"Ut oh, '%s' has an unknown protocol family!",this->nick); + break; + } + return ""; +} + -- cgit v1.2.3