Skip to content

Commit

Permalink
feat: overhaul interface, error
Browse files Browse the repository at this point in the history
  • Loading branch information
SkuldNorniern committed Mar 13, 2024
1 parent e51ae3a commit c73befb
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 8 deletions.
7 changes: 2 additions & 5 deletions src/net/interface.rs
Original file line number Diff line number Diff line change
@@ -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();
Expand Down Expand Up @@ -62,9 +62,6 @@ pub fn get_default_interface_name(interfaces: &[NetworkInterface]) -> String {
.clone()
}*/

pub fn list_interfaces() -> Vec<NetworkInterface> {
datalink::interfaces()
}
pub fn list_interface_names() {
let interfaces = Device::list();
/*let mut interface_names: Vec<String> = Vec::new();
Expand Down
36 changes: 33 additions & 3 deletions src/net/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//mod fluereflow
pub mod capture;
pub mod errors;
//mod fluereflow;
mod capture;
mod flows;
// mod interface;
pub mod live_fluereflow;
Expand All @@ -12,11 +12,41 @@ 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;
// pub use interface::list_interfaces;
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<DeviceError> for NetError {
fn from(err: DeviceError) -> Self {
NetError::DeviceError(err)
}
}

impl From<Error> 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),
}
}
}

0 comments on commit c73befb

Please sign in to comment.