use super::funejson::Value; use super::net_ipv4_parse_ipv4::parse_ipv4; /// The prefix length of a dotted-quad mask; a mask with a gap in its one bits is refused. /// /// # Panics /// Panics on text that is not a dotted quad, or a non-contiguous mask. pub fn netmask_to_prefix(netmask: &str) -> i64 { let value = parse_ipv4(netmask); let host_part = 4294967295 - value + 1; for prefix in 0..=32i64 { if (1i64 << (32 - prefix)) == host_part { return prefix; } } panic!("\"{}\" is not a contiguous netmask", netmask); } pub fn fune_vector(args: &[Value]) -> Value { Value::Int(netmask_to_prefix(args[0].as_str())) }