pub struct Ipv4Range { /* private fields */ }
Expand description
A range of IPv4 addresses with a common prefix
Implementations§
Source§impl Ipv4Range
impl Ipv4Range
Sourcepub fn new(addr: Ipv4Addr, bits: u8) -> Self
pub fn new(addr: Ipv4Addr, bits: u8) -> Self
Create an IPv4 range with the given base address and netmask prefix length.
§Example
Create the subnet 192.168.0.0/24 with Ipv4Range::new("192.168.0.0".parse().unwrap(), 24)
Sourcepub fn local_subnet_10() -> Self
pub fn local_subnet_10() -> Self
Returns the local network subnet 10.0.0.0/8
Sourcepub fn local_subnet_172(block: u8) -> Self
pub fn local_subnet_172(block: u8) -> Self
Returns a local network subnet 172.(16 | x).0.0/16 where x is a 4-bit number given by
block
§Panics
If block & 0xf0 != 0
Sourcepub fn local_subnet_192(block: u8) -> Self
pub fn local_subnet_192(block: u8) -> Self
Returns the local subnet 192.168.x.0/24 where x is given by block
.
Sourcepub fn random_local_subnet() -> Self
pub fn random_local_subnet() -> Self
Returns a random local network subnet from one of the ranges 10.0.0.0, 172.16.0.0 or 192.168.0.0
Sourcepub fn netmask_prefix_length(&self) -> u8
pub fn netmask_prefix_length(&self) -> u8
Get the number of netmask prefix bits
Sourcepub fn base_addr(&self) -> Ipv4Addr
pub fn base_addr(&self) -> Ipv4Addr
Get the base address of the range, ie. the lowest IP address which is part of the range.
Sourcepub fn gateway_addr(&self) -> Ipv4Addr
pub fn gateway_addr(&self) -> Ipv4Addr
Get a default IP address for the range’s gateway. This is one higher than the base address of the range. eg. for 10.0.0.0/8, the default address for the gateway will be 10.0.0.1
Sourcepub fn broadcast_addr(&self) -> Ipv4Addr
pub fn broadcast_addr(&self) -> Ipv4Addr
Get the broadcast address, ie. the highest IP address which is part of the range.
Sourcepub fn random_client_addr(&self) -> Ipv4Addr
pub fn random_client_addr(&self) -> Ipv4Addr
Get a random IP address from the range which is not the base address or the default for the gateway address.
Sourcepub fn address_for(&self, device: u32) -> Ipv4Addr
pub fn address_for(&self, device: u32) -> Ipv4Addr
Generate an IP address for a device.