- hostname = inet_ntoa(user->ip);
- } else if ((options & GENMASK_BYIP) || !hostname[strspn(hostname, "0123456789.")]) {
- /* Should generate an IP-based hostmask. By popular acclaim, a /16
- * hostmask is used by default. */
- unsigned masked_ip, mask, masklen;
- masklen = 16;
- mask = ~0 << masklen;
- masked_ip = ntohl(user->ip.s_addr) & mask;
- hostname = alloca(32);
- if (options & GENMASK_X3MASK) {
- sprintf(hostname, "%d.%d.%d.%d/%d", (masked_ip>>24)&0xFF, (masked_ip>>16)&0xFF, (masked_ip>>8)&0xFF, masked_ip&0xFF, masklen);
+ hostname = (char*)irc_ntoa(&user->ip);
+ } else if ((options & GENMASK_BYIP) || irc_pton(&ip, NULL, hostname)) {
+ /* Should generate an IP-based hostmask. */
+ hostname = alloca(IRC_NTOP_MAX_SIZE);
+ hostname[IRC_NTOP_MAX_SIZE-1] = '\0';
+ if (irc_in_addr_is_ipv4(user->ip)) {
+ /* By popular acclaim, a /16 hostmask is used. */
+ sprintf(hostname, "%d.%d.*", user->ip.in6_8[12], user->ip.in6_8[13]);
+ } else if (irc_in_addr_is_ipv6(user->ip)) {
+ /* Who knows what the default mask should be? Use a /48 to start with. */
+ sprintf(hostname, "%x:%x:%x:*", user->ip.in6[0], user->ip.in6[1], user->ip.in6[2]);