]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Change sprintf to snprintf, just in case; Update comments.
authorom <om@e03df62e-2008-0410-955e-edbf42e46eb7>
Sat, 12 Jul 2008 15:42:30 +0000 (15:42 +0000)
committerom <om@e03df62e-2008-0410-955e-edbf42e46eb7>
Sat, 12 Jul 2008 15:42:30 +0000 (15:42 +0000)
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@9985 e03df62e-2008-0410-955e-edbf42e46eb7

src/users.cpp

index a660fe6ac63ed273121a87425dac43e111172b2b..268c61b3b783eecf8e0e5c01193fb683bc860bc1 100644 (file)
@@ -1162,7 +1162,7 @@ const char* User::GetCIDRMask(int range)
                        /* And finally, zero the extra bits required. */
                        v6.s6_addr[15 - bytestozero] = (v6.s6_addr[15 - bytestozero] >> extrabits) << extrabits;
 
-                       sprintf(buf, "%s/%d", inet_ntop(AF_INET6, &v6, buffer, 40), range);
+                       snprintf(buf, 44, "%s/%d", inet_ntop(AF_INET6, &v6, buffer, 40), range);
                        return buf;
                }
                break;
@@ -1181,7 +1181,10 @@ const char* User::GetCIDRMask(int range)
                        sin = (sockaddr_in*)this->ip;
                        v4.s_addr = sin->sin_addr.s_addr;
 
-                       /* (32 - range) is the number of bits we are *ignoring*. We shift this left and then right to wipe off these bits. */
+                       /* To create the CIDR mask we want to set all the bits after 'range' bits of the address
+                        * to zero. This means the last (32 - range) bits of the address must be set to zero.
+                        * This is done by shifting the value right and then back left by (32 - range) bits.
+                        */
                        if(range > 0)
                        {
                                temp = ntohl(v4.s_addr);
@@ -1197,7 +1200,7 @@ const char* User::GetCIDRMask(int range)
                                v4.s_addr = 0;
                        }
 
-                       sprintf(buf, "%s/%d", inet_ntop(AF_INET, &v4, buffer, 16), range);
+                       snprintf(buf, 44, "%s/%d", inet_ntop(AF_INET, &v4, buffer, 16), range);
                        return buf;
                }
                break;