1mod packet;
2mod lib_version;
3mod interf_desc;
4mod data_link;
5mod err;
6
7use crate::traits::Library;
8use crate::{wpcap, pcap, pfring};
9use std::sync::Arc;
10
11
12pub use self::lib_version::LibraryVersion;
13pub use self::packet::{Packet, OwnedPacket, BorrowedPacket};
14pub use self::interf_desc::InterfaceDescription;
15pub use self::data_link::DataLink;
16pub use self::err::Error;
17
18
19
20pub fn open_best_library() -> Result<Box<dyn Library>, Error> {
37 if let Ok(l) = pfring::Library::open_default_paths() {
38 return Ok(Box::new(l));
39 }
40 if let Ok(l) = wpcap::Library::open_default_paths() {
41 return Ok(Box::new(l));
42 }
43 match pcap::Library::open_default_paths() {
44 Ok(l) => Ok(Box::new(l)),
45 Err(e) => Err(e)
46 }
47}
48
49pub fn open_best_library_arc() -> Result<Arc<dyn Library>, Error> {
51 if let Ok(l) = pfring::Library::open_default_paths() {
52 return Ok(Arc::new(l));
53 }
54 if let Ok(l) = wpcap::Library::open_default_paths() {
55 return Ok(Arc::new(l));
56 }
57 match pcap::Library::open_default_paths() {
58 Ok(l) => Ok(Arc::new(l)),
59 Err(e) => Err(e)
60 }
61}
62
63#[derive(Copy, Clone, Debug)]
65pub struct Stats {
66 pub received: u64,
68 pub dropped: u64
70}
71