IPv6 support

u_int8_t
mask2prefixlen(in_addr_t ina)
{
        if (ina == 0)
                return (0);
        else
                return (33 - ffs(ntohl(ina)));
}

u_int8_t
mask2prefixlen6(struct sockaddr_in6 *sa_in6)
{
        u_int8_t         l = 0, i, len;

        /*
         * sin6_len is the size of the sockaddr so substract the offset of
         * the possibly truncated sin6_addr struct.
         */
        len = sa_in6->sin6_len -
            (u_int8_t)(&((struct sockaddr_in6 *)NULL)->sin6_addr);
        for (i = 0; i < len; i++) {
                /* this "beauty" is adopted from sbin/route/show.c ... */
                switch (sa_in6->sin6_addr.s6_addr[i]) {
                case 0xff:
                        l += 8;
                        break;
                case 0xfe:
                        l += 7;
                        return (l);
                case 0xfc:
                        l += 6;
                        return (l);
                case 0xf8:
                        l += 5;
                        return (l);
                case 0xf0:
                        l += 4;
                        return (l);
                case 0xe0:
                        l += 3;
                        return (l);
                case 0xc0:
                        l += 2;
                        return (l);
                case 0x80:
                        l += 1;
                        return (l);
                case 0x00:
                        return (l);
                default:
                        fatalx("non continuous inet6 netmask");
                }
        }

        return (l);
}