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
impl PfrAddr
Sourcepub fn new_host(addr: IpAddr) -> PfrAddr
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}
Trait Implementations§
impl StructuralPartialEq for PfrAddr
Auto Trait Implementations§
impl Freeze for PfrAddr
impl RefUnwindSafe for PfrAddr
impl Send for PfrAddr
impl Sync for PfrAddr
impl Unpin for PfrAddr
impl UnwindSafe for PfrAddr
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