From 7f8bd0414afa65ea74b1754138386a92048bc98d Mon Sep 17 00:00:00 2001 From: pythops Date: Thu, 12 Sep 2024 13:20:41 +0200 Subject: [PATCH] display mac address for the selected interface --- oryx-tui/src/app.rs | 23 ++++++++++++++++++++++- oryx-tui/src/handler.rs | 7 +++++++ oryx-tui/src/interface.rs | 13 ++++++++++++- 3 files changed, 41 insertions(+), 2 deletions(-) diff --git a/oryx-tui/src/app.rs b/oryx-tui/src/app.rs index 7b85048..f33ee53 100644 --- a/oryx-tui/src/app.rs +++ b/oryx-tui/src/app.rs @@ -168,7 +168,7 @@ impl App { let (settings_block, mode_block) = { let chunks = Layout::default() .direction(Direction::Vertical) - .constraints([Constraint::Length(7), Constraint::Fill(1)]) + .constraints([Constraint::Length(8), Constraint::Fill(1)]) .split(frame.area()); (chunks[0], chunks[1]) }; @@ -190,6 +190,16 @@ impl App { Span::styled("Name", Style::new().bold()), Span::from(self.interface.selected_interface.name.clone()), ]), + Row::new(vec![ + Span::styled("Mac", Style::new().bold()), + Span::from( + self.interface + .selected_interface + .mac_address + .clone() + .unwrap_or("-".to_string()), + ), + ]), Row::new(vec![ Span::styled("IPv4", Style::new().bold()), Span::from( @@ -256,6 +266,17 @@ impl App { .join(" "), ), ]), + Row::new(vec![ + Span::styled("Link", Style::new().bold()), + Span::from( + self.link_filter + .applied_protocols + .iter() + .map(|filter| filter.to_string()) + .collect::>() + .join(" "), + ), + ]), Row::new(vec![ Span::styled("Direction", Style::new().bold()), Span::from( diff --git a/oryx-tui/src/handler.rs b/oryx-tui/src/handler.rs index 209f921..a100d3d 100644 --- a/oryx-tui/src/handler.rs +++ b/oryx-tui/src/handler.rs @@ -363,13 +363,20 @@ pub fn handle_key_events( KeyCode::Char('f') => { if app.focused_block != FocusedBlock::Help && app.start_sniffing { app.update_filters = true; + app.focused_block = FocusedBlock::NetworkFilter; + app.network_filter.selected_protocols = app.network_filter.applied_protocols.clone(); + app.transport_filter.selected_protocols = app.transport_filter.applied_protocols.clone(); + + app.link_filter.selected_protocols = app.link_filter.applied_protocols.clone(); + app.traffic_direction_filter.selected_direction = app.traffic_direction_filter.applied_direction.clone(); + app.network_filter.state = TableState::default().with_selected(0); } } diff --git a/oryx-tui/src/interface.rs b/oryx-tui/src/interface.rs index 9fa7b8d..b640f9f 100644 --- a/oryx-tui/src/interface.rs +++ b/oryx-tui/src/interface.rs @@ -7,7 +7,11 @@ use ratatui::{ Frame, }; -use std::net::{IpAddr, Ipv4Addr, Ipv6Addr}; +use std::{ + fs::{self}, + net::{IpAddr, Ipv4Addr, Ipv6Addr}, + path::PathBuf, +}; use std::ffi::CStr; @@ -18,6 +22,7 @@ pub struct NetworkInterface { pub name: String, pub is_up: bool, pub addresses: Vec, + pub mac_address: Option, } impl NetworkInterface { @@ -38,11 +43,17 @@ impl NetworkInterface { let cstr_name = CStr::from_ptr(ifa_name); let interface_name = cstr_name.to_str().unwrap(); + let interface_path = PathBuf::from("/sys/class/net") + .join(interface_name) + .join("address"); + let mac_address = fs::read_to_string(interface_path).ok(); + if !interfaces.iter().any(|i| i.name == interface_name) { interfaces.push(NetworkInterface { name: interface_name.to_string(), addresses: Vec::new(), is_up: (ifa_flags as i32 & IFF_UP) != 0, + mac_address, }); }