- if (!match->hostname[strspn(match->hostname, "0123456789.")]) {
- char ipmask[16];
- unsigned long matchip = ntohl(match->ip.s_addr);
- /* raw IP address.. use up to first three octets of IP */
- switch (das->discrim->domain_depth) {
- default:
- snprintf(ipmask, sizeof(ipmask), "%lu.%lu.%lu.*", (matchip>>24)&255, (matchip>>16)&255, (matchip>>8)&255);
- break;
- case 2:
- snprintf(ipmask, sizeof(ipmask), "%lu.%lu.*", (matchip>>24)&255, (matchip>>16)&255);
- break;
- case 1:
- snprintf(ipmask, sizeof(ipmask), "%lu.*", (matchip>>24)&255);
- break;
- }
+ if (irc_pton(&ip, NULL, match->hostname)) {
+ if (irc_in_addr_is_ipv4(ip)) {
+ unsigned long matchip = ntohl(ip.in6_32[3]);
+ /* raw IP address.. use up to first three octets of IP */
+ switch (das->discrim->domain_depth) {
+ default:
+ snprintf(ipmask, sizeof(ipmask), "%lu.%lu.%lu.*", (matchip>>24)&255, (matchip>>16)&255, (matchip>>8)&255);
+ break;
+ case 2:
+ snprintf(ipmask, sizeof(ipmask), "%lu.%lu.*", (matchip>>24)&255, (matchip>>16)&255);
+ break;
+ case 1:
+ snprintf(ipmask, sizeof(ipmask), "%lu.*", (matchip>>24)&255);
+ break;
+ }
+ } else if (irc_in_addr_is_ipv6(ip)) {
+ switch (das->discrim->domain_depth) {
+ case 1: depth = 16; goto ipv6_pfx;
+ case 2: depth = 24; goto ipv6_pfx;
+ case 3: depth = 32; goto ipv6_pfx;
+ default: depth = das->discrim->domain_depth;
+ ipv6_pfx:
+ irc_ntop_mask(ipmask, sizeof(ipmask), &ip, depth);
+ }
+ } else safestrncpy(ipmask, match->hostname, sizeof(ipmask));
+ ipmask[sizeof(ipmask) - 1] = '\0';