CapNetAgent

Struct CapNetAgent 

Source
pub struct CapNetAgent(/* private fields */);
Expand description

A connection to the Casper cap_net(3) service.

Implementations§

Source§

impl CapNetAgent

Source

pub fn bind<F>(&mut self, sock: &F, addr: &dyn SockaddrLike) -> Result<()>
where F: AsFd,

A low-level bind(2) workalike, but in capability mode.

§Examples
use std::{
    os::fd::AsRawFd,
    str::FromStr
};
use capsicum::casper::Casper;
use capsicum_net::CasperExt;
use nix::sys::socket::{
    AddressFamily, SockaddrIn, SockaddrLike, SockFlag,
    SockType, socket
};

// Safe if we are single-threaded
let mut casper = unsafe { Casper::new().unwrap() };
let mut cap_net = casper.net().unwrap();
let s = socket(AddressFamily::Inet, SockType::Stream, SockFlag::empty(),
    None).unwrap();
let addr = SockaddrIn::from_str("127.0.0.1:8081").unwrap();
cap_net.bind(&s, &addr).unwrap();
Source

pub fn connect<F>(&mut self, sock: &F, addr: &dyn SockaddrLike) -> Result<()>
where F: AsFd,

A low-level connect(2) workalike, but in capability mode.

§Examples
use std::{
    os::fd::AsRawFd,
    str::FromStr
};
use capsicum::casper::Casper;
use capsicum_net::CasperExt;
use nix::sys::socket::{
    AddressFamily, SockaddrIn, SockaddrLike, SockFlag,
    SockType, socket
};

// Safe if we are single-threaded
let mut casper = unsafe { Casper::new().unwrap() };
let mut cap_net = casper.net().unwrap();
let s = socket(AddressFamily::Inet, SockType::Stream, SockFlag::empty(),
    None).unwrap();
let addr = SockaddrIn::from_str("8.8.8.8:53").unwrap();
cap_net.connect(&s, &addr).unwrap();
Source

pub fn limit(&mut self, flags: LimitFlags) -> Limit<'_>

Return an opaque handle used to further limit the capabilities of the cap_net service.

Each time a Limit is constructed and applied it can reduce, but never enlarge, the service’s capabilities.

§Example
use std::{
    os::fd::AsRawFd,
    str::FromStr
};
use capsicum::casper::Casper;
use capsicum_net::{CasperExt, LimitFlags};
use nix::sys::socket::{SockaddrIn, SockaddrLike};

let mut casper = unsafe { Casper::new().unwrap() };
let mut cap_net = casper.net().unwrap();
let mut limit = cap_net.limit(LimitFlags::BIND);
let addr = SockaddrIn::from_str("127.0.0.1:8083").unwrap();
limit.bind(&addr);
limit.limit();
// Now the service will refuse attempts to bind to any other address or
// port.

Trait Implementations§

Source§

impl Debug for CapNetAgent

Source§

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

Formats the value using the given formatter. Read more

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> 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, 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.