+int mask_match(char *mask, struct UserNode *user) {
+ char usermask[NICKLEN+USERLEN+HOSTLEN+3];
+ char matchmask[strlen(mask)+3];
+ strcpy(matchmask, mask);
+ char *host = strchr(mask, '@');
+ if(host) {
+ struct IPNode *ip = createIPNode(host);
+ int bits = (ip->flags & IPNODE_IS_IPV6 ? 128 : 32);
+ if((host = strchr(host, '/'))) {
+ bits = atoi(host+1);
+ }
+ if(ip && user->ip&& !ipmatch(user->ip, ip, bits)) {
+ host[1] = '*';
+ host[2] = '\0';
+ }
+ }
+ sprintf(usermask, "%s!%s@%s", user->nick, user->ident, user->host);
+ return match(matchmask, usermask);
+}
+
+static unsigned long crc_table[256];
+
+static void crc32_init() {
+ unsigned long crc;
+ int i, j;
+ for(i = 0; i < 256; i++) {
+ crc = i;
+ for(j = 8; j > 0; j--) {
+ if(crc & 1)
+ crc = (crc >> 1) ^ 0xEDB88320L;
+ else
+ crc >>= 1;
+ }
+ crc_table[i] = crc;
+ }
+}
+
+unsigned long crc32(const char *text) {
+ register unsigned long crc = 0xFFFFFFFF;
+ unsigned int c, i = 0;
+ while((c = (unsigned int)text[i++]) != 0)
+ crc = ((crc >> 8) & 0x00FFFFFF) ^ crc_table[(crc^c) & 0xFF];
+ return (crc^0xFFFFFFFF);
+}
+
+int stricmp (const char *s1, const char *s2) {
+ return stricmplen(s1, s2, -1);
+}
+
+int stricmplen(const char *s1, const char *s2, int len) {
+ if (s1 == NULL)
+ return (s2 == NULL ? 0 : -(*s2));
+ if (s2 == NULL)
+ return *s1;
+ char c1, c2;
+ int i = 0;
+ while ((c1 = tolower(*s1)) == (c2 = tolower(*s2))) {
+ if (*s1 == '\0')
+ break;
+ i++;
+ s1++;
+ s2++;
+ if(len != -1 && i == len) break;
+ }
+ return c1 - c2;
+}
+