- const char* p = ip.c_str();
- int num_dots = 0;
- int num_seps = 0;
- int not_numbers = false;
- int not_hex = false;
-
- if (*p)
- {
- if (*p == '.')
- throw CoreException("The value of "+key+" is not an IP address");
-
- for (const char* ptr = p; *ptr; ++ptr)
- {
- if (*ptr != ':' && *ptr != '.')
- {
- if (*ptr < '0' || *ptr > '9')
- not_numbers = true;
- if ((*ptr < '0' || *ptr > '9') && (toupper(*ptr) < 'A' || toupper(*ptr) > 'F'))
- not_hex = true;
- }
- switch (*ptr)
- {
- case ' ':
- throw CoreException("The value of "+key+" is not an IP address");
- case '.':
- num_dots++;
- break;
- case ':':
- num_seps++;
- break;
- }
- }
-
- if (num_dots > 3)
- throw CoreException("The value of "+key+" is an IPv4 address with too many fields!");
-
- if (num_seps > 8)
- throw CoreException("The value of "+key+" is an IPv6 address with too many fields!");
-
- if (num_seps == 0 && num_dots < 3)
- throw CoreException("The value of "+key+" looks to be a malformed IPv4 address");
-
- if (num_seps == 0 && num_dots == 3 && not_numbers)
- throw CoreException("The value of "+key+" contains non-numeric characters in an IPv4 address");
-
- if (num_seps != 0 && not_hex)
- throw CoreException("The value of "+key+" contains non-hexdecimal characters in an IPv6 address");
-
- if (num_seps != 0 && num_dots != 3 && num_dots != 0)
- throw CoreException("The value of "+key+" is a malformed IPv6 4in6 address");
- }
+ irc::sockets::sockaddrs dummy;
+ if (!irc::sockets::aptosa(ip, 0, dummy))
+ throw CoreException("The value of "+key+" is not an IP address");