use std::net::{
IpAddr,
Ipv4Addr,
Ipv6Addr,
};
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
pub enum Family {
Ipv4,
Ipv6,
}
impl Family {
#[allow(clippy::len_without_is_empty)]
pub const fn len(&self) -> u8 {
match self {
Self::Ipv4 => 32,
Self::Ipv6 => 128,
}
}
pub const fn unspecified_address(&self) -> IpAddr {
match self {
Self::Ipv4 => IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)),
Self::Ipv6 => IpAddr::V6(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 0)),
}
}
pub const fn loopback_address(&self) -> IpAddr {
match self {
Self::Ipv4 => IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)),
Self::Ipv6 => IpAddr::V6(Ipv6Addr::new(0, 0, 0, 0, 0, 0, 0, 1)),
}
}
}