]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/socket.cpp
Fix segfault on 'cant open logfile' on startup, on trying to call Exit. instead just...
[user/henk/code/inspircd.git] / src / socket.cpp
index 03477645b2a5eca10bd1ae29fc399796fb1a07f3..976c0585b439b2f5b70ea23a1e92a15f8d6ab537 100644 (file)
@@ -85,6 +85,8 @@ void ListenSocket::HandleEvent(EventType et, int errornum)
                length = sizeof(sockaddr_in);
        }
 
+       void* m_acceptEvent = NULL;
+       GetExt("windows_acceptevent", m_acceptEvent);
        incomingSockfd = _accept (this->GetFd(), (sockaddr*)client, &length);
 
        if ((incomingSockfd > -1) && (!_getsockname(incomingSockfd, sock_us, &uslen)))
@@ -131,19 +133,19 @@ void ListenSocket::HandleEvent(EventType et, int errornum)
 /* Match raw bytes using CIDR bit matching, used by higher level MatchCIDR() */
 bool irc::sockets::MatchCIDRBits(unsigned char* address, unsigned char* mask, unsigned int mask_bits)
 {
-       unsigned int modulus = mask_bits % 8; /* Number of whole bytes in the mask */
-       unsigned int divisor = mask_bits / 8; /* Remaining bits in the mask after whole bytes are dealt with */
+       unsigned int divisor = mask_bits / 8; /* Number of whole bytes in the mask */
+       unsigned int modulus = mask_bits % 8; /* Remaining bits in the mask after whole bytes are dealt with */
 
-       /* First compare the whole bytes, if they dont match, return false */
-       if (memcmp(address, mask, divisor))
-               return false;
-
-       /* Now if there are any remainder bits, we compare them with logic AND */
+       /* First (this is faster) compare the odd bits with logic ops */
        if (modulus)
                if ((address[divisor] & inverted_bits[modulus]) != (mask[divisor] & inverted_bits[modulus]))
                        /* If they dont match, return false */
                        return false;
 
+       /* Secondly (this is slower) compare the whole bytes */
+       if (memcmp(address, mask, divisor))
+               return false;
+
        /* The address matches the mask, to mask_bits bits of mask */
        return true;
 }