[][src]Trait rawsock::traits::Library

pub trait Library: Send + Sync {
    fn default_paths() -> &'static [&'static str]
    where
        Self: Sized
;
fn open(path: &str) -> Result<Self, Error>
    where
        Self: Sized
;
fn open_interface<'a>(
        &'a self,
        name: &str
    ) -> Result<Box<dyn DynamicInterface<'a> + 'a>, Error>;
fn open_interface_arc<'a>(
        &'a self,
        name: &str
    ) -> Result<Arc<dyn DynamicInterface<'a> + 'a>, Error>;
fn all_interfaces(&self) -> Result<Vec<InterfaceDescription>, Error>;
fn version(&self) -> LibraryVersion; fn open_default_paths() -> Result<Self, Error>
    where
        Self: Sized
, { ... }
fn open_paths<'b, T>(paths: T) -> Result<Self, Error>
    where
        Self: Sized,
        T: IntoIterator<Item = &'b str>
, { ... } }

Trait for structures representing opened packet capture libraries.

There are several libraries that can be used among different platforms. For example pcap.so, wpcap.dll or pfring.so. This trait provides a consistent interface to all of them.

Required methods

fn default_paths() -> &'static [&'static str] where
    Self: Sized

Returns list of default paths to the library on the given platform.

fn open(path: &str) -> Result<Self, Error> where
    Self: Sized

Opens library by checking the provided path to it.

fn open_interface<'a>(
    &'a self,
    name: &str
) -> Result<Box<dyn DynamicInterface<'a> + 'a>, Error>

Opens interface (network card or network device) with the provided name.

You can obtain names of available devices by calling the all_interfaces() function.

fn open_interface_arc<'a>(
    &'a self,
    name: &str
) -> Result<Arc<dyn DynamicInterface<'a> + 'a>, Error>

fn all_interfaces(&self) -> Result<Vec<InterfaceDescription>, Error>

Obtains list of available network interfaces.

Each of returned interface names can be further used to open interfaces.

Note: each library may support different set of interfaces. This is because different libraries support different network interface types and some of them add to the list virtual interfaces (such as pcap "any" interface or pfring "zc:eth0"). The same function called with pcap library will return different set of interfaces than run with pfring. However in both cases the returned interface list will be supported by currently used library.

Example

extern crate rawsock;
use rawsock::open_best_library;
use rawsock::traits::Library;

fn main(){
    let lib = open_best_library().expect("Could not open any library.");
    let interfs = lib.all_interfaces().expect("Could not obtain interface list");
    for interf in &interfs{
        println!("Found interface: {}", &interf.name);
    }
    let interf = lib.open_interface(&interfs.first().unwrap().name)
        .expect("Could not open interface");
    // do something with the interface
}

fn version(&self) -> LibraryVersion

Returns library version

Loading content...

Provided methods

fn open_default_paths() -> Result<Self, Error> where
    Self: Sized

Opens this library by searching for most common paths and names fro the given platform

fn open_paths<'b, T>(paths: T) -> Result<Self, Error> where
    Self: Sized,
    T: IntoIterator<Item = &'b str>, 

Opens library searching in the list of provided paths.

Loading content...

Implementors

impl Library for rawsock::pcap::Library[src]

impl Library for rawsock::pfring::Library[src]

impl Library for rawsock::wpcap::Library[src]

Loading content...