- if (inet_pton(AF_INET6, address_copy.c_str(), &address_in6) > 0)
- {
- if (inet_pton(AF_INET6, cidr_copy.c_str(), &mask_in6) > 0)
- {
- memcpy(&addr_raw, &address_in6.s6_addr, 16);
- memcpy(&mask_raw, &mask_in6.s6_addr, 16);
-
- if (bits > 128)
- bits = 128;
- }
- else
- {
- /* The address was valid ipv6, but the mask
- * that goes with it wasnt.
- */
- return false;
- }
- }
- else
-#endif
- if (inet_pton(AF_INET, address_copy.c_str(), &address_in4) > 0)
- {
- if (inet_pton(AF_INET, cidr_copy.c_str(), &mask_in4) > 0)
- {
- memcpy(&addr_raw, &address_in4.s_addr, 4);
- memcpy(&mask_raw, &mask_in4.s_addr, 4);
-
- if (bits > 32)
- bits = 32;
- }
- else
- {
- /* The address was valid ipv4,
- * but the mask that went with it wasnt.
- */
- return false;
- }
- }
- else
- {
- /* The address was neither ipv4 or ipv6 */
- return false;
- }