From 2ebabdd43845facbda90dc8429f3c8f29bc4cbce Mon Sep 17 00:00:00 2001 From: Marco Cadetg Date: Mon, 30 Jun 2025 14:31:43 +0200 Subject: [PATCH] adding interface name to TUI --- src/app.rs | 16 ++++++++++++++-- src/network/capture.rs | 6 ++++-- src/ui.rs | 15 +++++++++++---- 3 files changed, 29 insertions(+), 8 deletions(-) diff --git a/src/app.rs b/src/app.rs index baeec24..561b71a 100644 --- a/src/app.rs +++ b/src/app.rs @@ -93,6 +93,9 @@ pub struct App { /// Loading state is_loading: Arc, + + /// Current network interface name + current_interface: Arc>>, } impl App { @@ -111,6 +114,7 @@ impl App { service_lookup: Arc::new(service_lookup), stats: Arc::new(AppStats::default()), is_loading: Arc::new(AtomicBool::new(true)), + current_interface: Arc::new(RwLock::new(None)), }) } @@ -177,11 +181,14 @@ impl App { let should_stop = Arc::clone(&self.should_stop); let stats = Arc::clone(&self.stats); + let current_interface = Arc::clone(&self.current_interface); thread::spawn(move || { match setup_packet_capture(capture_config) { - Ok(capture) => { - info!("Packet capture started successfully"); + Ok((capture, device_name)) => { + // Store the actual interface name being used + *current_interface.write().unwrap() = Some(device_name.clone()); + info!("Packet capture started successfully on interface: {}", device_name); let mut reader = PacketReader::new(capture); let mut packets_read = 0u64; let mut last_log = Instant::now(); @@ -525,6 +532,11 @@ impl App { self.is_loading.load(Ordering::Relaxed) } + /// Get the current network interface name + pub fn get_current_interface(&self) -> Option { + self.current_interface.read().unwrap().clone() + } + /// Stop all threads gracefully pub fn stop(&self) { info!("Stopping application"); diff --git a/src/network/capture.rs b/src/network/capture.rs index e77e793..9fc2077 100644 --- a/src/network/capture.rs +++ b/src/network/capture.rs @@ -132,7 +132,7 @@ fn find_best_device() -> Result { } /// Setup packet capture with the given configuration -pub fn setup_packet_capture(config: CaptureConfig) -> Result> { +pub fn setup_packet_capture(config: CaptureConfig) -> Result<(Capture, String)> { // Find the capture device let device = find_capture_device(&config.interface)?; @@ -142,6 +142,8 @@ pub fn setup_packet_capture(config: CaptureConfig) -> Result> { device.desc.as_deref().unwrap_or("no description") ); + let device_name = device.name.clone(); + // Create capture handle let mut cap = Capture::from_device(device)? .promisc(config.promiscuous) @@ -161,7 +163,7 @@ pub fn setup_packet_capture(config: CaptureConfig) -> Result> { // Note: We're not setting non-blocking mode as we're using timeout instead - Ok(cap) + Ok((cap, device_name)) } /// Find a capture device by name or return the default diff --git a/src/ui.rs b/src/ui.rs index d8d3029..a6b16da 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -82,7 +82,7 @@ pub fn draw( draw_tabs(f, ui_state, chunks[0]); match ui_state.selected_tab { - 0 => draw_overview(f, ui_state, connections, stats, chunks[1])?, + 0 => draw_overview(f, ui_state, connections, stats, app, chunks[1])?, 1 => draw_connection_details(f, ui_state, connections, chunks[1])?, 2 => draw_help(f, chunks[1])?, _ => {} @@ -124,6 +124,7 @@ fn draw_overview( ui_state: &UIState, connections: &[Connection], stats: &AppStats, + app: &App, area: Rect, ) -> Result<()> { let chunks = Layout::default() @@ -132,7 +133,7 @@ fn draw_overview( .split(area); draw_connections_list(f, ui_state, connections, chunks[0]); - draw_stats_panel(f, connections, stats, chunks[1])?; + draw_stats_panel(f, connections, stats, app, chunks[1])?; Ok(()) } @@ -235,13 +236,14 @@ fn draw_stats_panel( f: &mut Frame, connections: &[Connection], stats: &AppStats, + app: &App, area: Rect, ) -> Result<()> { let chunks = Layout::default() .direction(Direction::Vertical) .constraints([ - Constraint::Length(8), // Connection stats - Constraint::Min(0), // Traffic stats + Constraint::Length(10), // Connection stats (increased for interface line) + Constraint::Min(0), // Traffic stats ]) .split(area); @@ -255,7 +257,12 @@ fn draw_stats_panel( .filter(|c| c.protocol == Protocol::UDP) .count(); + let interface_name = app.get_current_interface() + .unwrap_or_else(|| "Unknown".to_string()); + let conn_stats_text: Vec = vec![ + Line::from(format!("Interface: {}", interface_name)), + Line::from(""), Line::from(format!("TCP Connections: {}", tcp_count)), Line::from(format!("UDP Connections: {}", udp_count)), Line::from(format!("Total Connections: {}", connections.len())),