PfrAddr

Struct PfrAddr 

Source
pub struct PfrAddr {
    pub addr: IpAddr,
    pub ifname: String,
    pub subnet: u8,
}
Expand description

A Rust-friendly wrapper #[repr(C)] struct pfr_addr

Fields§

§addr: IpAddr§ifname: String§subnet: u8

Implementations§

Source§

impl PfrAddr

Source

pub fn new(addr: IpAddr, subnet: u8) -> PfrAddr

Constructs a PfrAddr from an IP and subnet

Source

pub fn new_host(addr: IpAddr) -> PfrAddr

Constructs a PfrAddr from a host IP

Examples found in repository?
examples/my_table.rs (line 12)
6fn main() -> Result<(), Box<dyn Error>> {
7    let fd = fs::OpenOptions::new()
8        .write(true)
9        .open("/dev/pf")?;
10
11    let mut addrs = vec![
12        PfrAddr::new_host(IpAddr::V4("127.0.0.1".parse()?)),
13        PfrAddr::new_host(IpAddr::V4("127.0.0.2".parse()?)),
14        PfrAddr::new_host(IpAddr::V4("127.0.0.3".parse()?)),
15        PfrAddr::new_host(IpAddr::V6("::1".parse()?)),
16    ];
17
18    let mut table = PfTable::new("my_table");
19
20    // Add a list of addresses to table
21    table.add_addrs(&fd, addrs.clone())?;
22
23    // Delete a list of addresses from table
24    let last = addrs.pop().unwrap();
25    table.del_addrs(&fd, vec![last])?;
26
27    // Print contents of table
28    for addr in table.get_addrs(&fd)? {
29        println!("{}", addr);
30    }
31
32    // Clear all addresses from table
33    table.clr_addrs(&fd)?;
34
35    Ok(())
36}
Source

pub fn default() -> PfrAddr

Constructs a PfrAddr with default values

Trait Implementations§

Source§

impl Clone for PfrAddr

Source§

fn clone(&self) -> PfrAddr

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for PfrAddr

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for PfrAddr

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for PfrAddr

Source§

fn eq(&self, other: &PfrAddr) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Translate<pfr_addr> for PfrAddr

Source§

fn update(&mut self, c: pfr_addr) -> Result<(), PfError>

Will fail if address family or ifname contain invalid data

Source§

fn translate(&self) -> Result<pfr_addr, PfError>

Fails if length of ifname is longer than or equal to IFNAMSIZ

Source§

impl StructuralPartialEq for PfrAddr

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.