*pbits = bits;
return pos;
case '.':
+ if (++dots > 3)
+ return 0;
if (input[++pos] == '.')
return 0;
- ip |= part << (24 - 8 * dots++);
+ ip |= part << (32 - 8 * dots);
part = 0;
if (input[pos] == '*') {
- while (input[++pos] == '*') ;
+ while (input[++pos] == '*' || input[pos] == '.') ;
if (input[pos] != '\0')
return 0;
if (pbits)
*pbits = part;
goto finish;
case '*':
- while (input[++pos] == '*') ;
+ while (input[++pos] == '*' || input[pos] == ':') ;
if (input[pos] != '\0' || colon < 8)
return 0;
if (pbits)
default:
return 0;
}
+ if (input[pos] != '\0')
+ return 0;
finish:
if (colon < 8) {
unsigned int jj;
if (curr_zeros > max_zeros) {
max_start = ii - curr_zeros;
max_zeros = curr_zeros;
- curr_zeros = 0;
}
/* Print the rest of the address */
for (ii = zero; ii < 8; ) {
}
}
+/** Test whether an address matches the most significant bits of a mask.
+ * @param[in] addr Address to test.
+ * @param[in] mask Address to test against.
+ * @param[in] bits Number of bits to test.
+ * @return 0 on mismatch, 1 if bits < 128 and all bits match; -1 if
+ * bits == 128 and all bits match.
+ */
+int ipmask_check(const struct irc_in_addr *addr, const struct irc_in_addr *mask, unsigned char bits)
+{
+ int k;
+
+ for (k = 0; k < 8; k++) {
+ if (bits < 16)
+ return !(htons(addr->in6_16[k] ^ mask->in6_16[k]) >> (16-bits));
+ if (addr->in6_16[k] != mask->in6_16[k])
+ return 0;
+ if (!(bits -= 16))
+ return 1;
+ }
+ return -1;
+}