Struct netsim::SubnetV4
[−]
[src]
pub struct SubnetV4 { /* fields omitted */ }
An Ipv4 subnet
Methods
impl SubnetV4
[src]
pub fn new(addr: Ipv4Addr, bits: u8) -> SubnetV4
[src]
Create a subnet with the given base IP address and number of netmask bits.
Example
Create the subnet 192.168.0.0/24 with SubnetV4::new(ipv4!("192.168.0.0"), 24)
pub fn global() -> SubnetV4
[src]
Return the global subnet, eg. 0.0.0.0/0
pub fn local_10() -> SubnetV4
[src]
Returns the local network subnet 10.0.0.0/8
pub fn local_172(block: u8) -> SubnetV4
[src]
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
pub fn local_192(block: u8) -> SubnetV4
[src]
Returns the local subnet 192.168.x.0/24 where x is given by block
.
pub fn random_local() -> SubnetV4
[src]
Returns a random local network from one of the ranges 10.0.0.0, 172.16.0.0 or 192.168.0.0
pub fn netmask(&self) -> Ipv4Addr
[src]
Get the netmask as an IP address
pub fn netmask_bits(&self) -> u8
[src]
Get the number of netmask bits
pub fn base_addr(&self) -> Ipv4Addr
[src]
Get the base address of the subnet, ie. the lowest IP address which is part of the subnet.
pub fn gateway_ip(&self) -> Ipv4Addr
[src]
Get a default IP address for the subnet's gateway. This is one higher than the base address of the subnet. eg. for 10.0.0.0/8, the default address for the gateway will be 10.0.0.1
pub fn random_client_addr(&self) -> Ipv4Addr
[src]
Get a random IP address from the subnet which is not the base address or the default for the gateway address.
pub fn contains(&self, ip: Ipv4Addr) -> bool
[src]
Check whether this subnet contains the given IP address
pub fn split(self, num: u32) -> Vec<SubnetV4>
[src]
Trait Implementations
impl Clone for SubnetV4
[src]
fn clone(&self) -> SubnetV4
[src]
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl Copy for SubnetV4
[src]
impl Debug for SubnetV4
[src]
fn fmt(&self, f: &mut Formatter) -> Result
[src]
Formats the value using the given formatter. Read more