Struct subnetwork::Ipv4
source · pub struct Ipv4 { /* private fields */ }Implementations§
source§impl Ipv4
impl Ipv4
sourcepub fn new(address: Ipv4Addr) -> Result<Ipv4, AddrParseError>
pub fn new(address: Ipv4Addr) -> Result<Ipv4, AddrParseError>
Constructs a new Ipv4 from a given Ipv4Addr.
sourcepub fn from(address: &str) -> Result<Ipv4, AddrParseError>
pub fn from(address: &str) -> Result<Ipv4, AddrParseError>
Constructs a new Ipv4 from a given &str.
sourcepub fn iter(&self, netmask: usize) -> Ipv4Pool ⓘ
pub fn iter(&self, netmask: usize) -> Ipv4Pool ⓘ
Returns an Ipv4 iterator over the addresses contained in the network.
Example
use subnetwork::Ipv4;
fn main() {
let ipv4 = Ipv4::from("192.168.1.1").unwrap();
for i in ipv4.iter(24) {
println!("{:?}", i);
}
}sourcepub fn within_from_str(
&self,
subnet_address: &str
) -> Result<bool, InvalidInputError>
pub fn within_from_str( &self, subnet_address: &str ) -> Result<bool, InvalidInputError>
Check if the ip is within a subnet.
Example
use subnetwork::Ipv4;
fn main() {
let ipv4 = Ipv4::from("192.168.1.1").unwrap();
let ret = ipv4.within_from_str("192.168.1.0/24").unwrap();
assert_eq!(ret, true);
}sourcepub fn within(&self, subnet_address: Ipv4Pool) -> bool
pub fn within(&self, subnet_address: Ipv4Pool) -> bool
Check if the ip is within a subnet.
Example
use subnetwork::{Ipv4, Ipv4Pool};
fn main() {
let ipv4 = Ipv4::from("192.168.1.1").unwrap();
let ipv4_pool = Ipv4Pool::from("192.168.1.0/24").unwrap();
let ret = ipv4.within(ipv4_pool);
assert_eq!(ret, true);
}sourcepub fn network(&self, netmask: usize) -> Ipv4Addr
pub fn network(&self, netmask: usize) -> Ipv4Addr
Returns the address of the network denoted by this Ipv4.
This means the lowest possible IP address inside of the network.
sourcepub fn broadcast(&self, netmask: usize) -> Ipv4Addr
pub fn broadcast(&self, netmask: usize) -> Ipv4Addr
Returns the broadcasting address of this Ipv4.
This means the highest possible IP address inside of the network.
sourcepub fn size(&self, netmask: usize) -> usize
pub fn size(&self, netmask: usize) -> usize
Returns the number of possible host addresses in this Ipv4 (include 0 and 255)
Trait Implementations§
impl Copy for Ipv4
Auto Trait Implementations§
impl RefUnwindSafe for Ipv4
impl Send for Ipv4
impl Sync for Ipv4
impl Unpin for Ipv4
impl UnwindSafe for Ipv4
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more