From c73befbc9341a26d53868ea1d8a9576a8b70e21b Mon Sep 17 00:00:00 2001 From: SkuldNorniern Date: Mon, 11 Mar 2024 09:49:17 +0900 Subject: [PATCH] feat: overhaul interface, error --- src/net/interface.rs | 7 ++----- src/net/mod.rs | 36 +++++++++++++++++++++++++++++++++--- 2 files changed, 35 insertions(+), 8 deletions(-) diff --git a/src/net/interface.rs b/src/net/interface.rs index 6cac518..1f56a39 100644 --- a/src/net/interface.rs +++ b/src/net/interface.rs @@ -1,7 +1,7 @@ -extern crate pcap; +use std::time::Instant; + use pcap::Device; use pnet::datalink::{self, NetworkInterface}; -use std::time::Instant; pub fn get_interface(device_name: &str) -> Device { let start = Instant::now(); @@ -62,9 +62,6 @@ pub fn get_default_interface_name(interfaces: &[NetworkInterface]) -> String { .clone() }*/ -pub fn list_interfaces() -> Vec { - datalink::interfaces() -} pub fn list_interface_names() { let interfaces = Device::list(); /*let mut interface_names: Vec = Vec::new(); diff --git a/src/net/mod.rs b/src/net/mod.rs index c15a9e0..6a94278 100644 --- a/src/net/mod.rs +++ b/src/net/mod.rs @@ -1,6 +1,6 @@ +//mod fluereflow +pub mod capture; pub mod errors; -//mod fluereflow; -mod capture; mod flows; // mod interface; pub mod live_fluereflow; @@ -12,7 +12,6 @@ pub mod types; //pub use flows::packet_capture; pub use capture::find_device; -pub use capture::list_devices; pub use capture::CaptureDevice; pub use capture::DeviceError; // pub use interface::list_interface_names; @@ -20,3 +19,34 @@ pub use capture::DeviceError; pub use offline_fluereflows::fluereflow_fileparse; pub use packet_pcap::pcap_capture; //pub use types::FluereRecord; + +use std::fmt::{Display, Formatter, Result as FmtResult}; + +use pcap::Error; + +#[derive(Debug)] +pub enum NetError { + DeviceError(DeviceError), + PcapError(Error), +} + +impl From for NetError { + fn from(err: DeviceError) -> Self { + NetError::DeviceError(err) + } +} + +impl From for NetError { + fn from(err: Error) -> Self { + NetError::PcapError(err) + } +} + +impl Display for NetError { + fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult { + match self { + NetError::DeviceError(err) => err.fmt(f), + NetError::PcapError(err) => err.fmt(f), + } + } +}