[][src]Struct bdrck::net::IpNet

pub struct IpNet { /* fields omitted */ }

An IpNet represents an IP network. Networks are typically identified in CIDR notation, like (for example) "192.0.0.0/24".

Methods

impl IpNet[src]

pub fn get_ip(&self) -> IpAddr[src]

Return the network IP. This address will have been normalized, such that any non-masked bits will have been turned off during construction.

pub fn get_mask(&self) -> &[u8][src]

Return the network mask, as a byte slice. This slice will always be 16 bytes long, even if this is an IPv4 network.

pub fn apply_mask(&self, ip: IpAddr, invert: bool, set: bool) -> IpAddr[src]

Apply this network's mask to the given IP address, returning the modified copy.

The "default" behavior is when invert=false and set=false. In this case, any bits which are "0" in the mask are turned off in the given IP address' bytes.

If invert=true, then each bit in the mask is flipped before it is applied - in other words, we apply the inverse mask.

If set=true, then we switch from bitwise AND to bitwise OR, meaning instead of the behavior described above, any bits which are "1" in the mask are turned on in the IP address, and other bits are left unchanged.

pub fn get_one_bits(&self) -> usize[src]

Returns the number of "1" bits in this network's mask. Although the mask is always 16 bytes long, for IPv4 networks only the last 4 bytes of the mask are considered.

pub fn is_canonical(&self) -> bool[src]

Returns whether or not this network's mask is "canonical" - i.e., if all of its mask's "1" bits are contiguous (no "0" bits in-between them).

pub fn netmask(&self) -> IpAddr[src]

Return the netmask IP address for this network.

pub fn broadcast(&self) -> IpAddr[src]

Return the broadcast IP address for this network.

pub fn contains(&self, ip: IpAddr, strict: bool) -> bool[src]

Return whether or not the given IP address is contained within this network. If strict=true, then the "network address" and "broadcast address" are both not considered to be "within" this network (this is useful if you want to check if the given IP address is actually usable for a host on the network).

pub fn increment_in(&self, ip: IpAddr, strict: bool) -> Option<IpAddr>[src]

Increment the given IP address as if with increment_ip(), but returning None if the resulting IP address does not lie within this network. The "strict" parameter behaves as IpNet::contains() describes.

pub fn first(&self) -> Option<IpAddr>[src]

Return the first IP address which falls within this network.

pub fn last(&self) -> IpAddr[src]

Return the last non-broadcast IP address which falls within this network.

Trait Implementations

impl Clone for IpNet[src]

impl Copy for IpNet[src]

impl Debug for IpNet[src]

impl<'de> Deserialize<'de> for IpNet[src]

impl Display for IpNet[src]

impl Eq for IpNet[src]

impl FromStr for IpNet[src]

type Err = Error

The associated error which can be returned from parsing.

impl Hash for IpNet[src]

impl PartialEq<IpNet> for IpNet[src]

impl Serialize for IpNet[src]

impl StructuralEq for IpNet[src]

impl StructuralPartialEq for IpNet[src]

Auto Trait Implementations

impl RefUnwindSafe for IpNet

impl Send for IpNet

impl Sync for IpNet

impl Unpin for IpNet

impl UnwindSafe for IpNet

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> DeserializeOwned for T where
    T: Deserialize<'de>, 
[src]

impl<Q, K> Equivalent<K> for Q where
    K: Borrow<Q> + ?Sized,
    Q: Eq + ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,