Skip to content

Commit

Permalink
display mac address for the selected interface
Browse files Browse the repository at this point in the history
  • Loading branch information
pythops committed Sep 12, 2024
1 parent 5fbf555 commit 7f8bd04
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
23 changes: 22 additions & 1 deletion oryx-tui/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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])
};
Expand All @@ -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(
Expand Down Expand Up @@ -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::<Vec<String>>()
.join(" "),
),
]),
Row::new(vec![
Span::styled("Direction", Style::new().bold()),
Span::from(
Expand Down
7 changes: 7 additions & 0 deletions oryx-tui/src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
13 changes: 12 additions & 1 deletion oryx-tui/src/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -18,6 +22,7 @@ pub struct NetworkInterface {
pub name: String,
pub is_up: bool,
pub addresses: Vec<IpAddr>,
pub mac_address: Option<String>,
}

impl NetworkInterface {
Expand All @@ -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,
});
}

Expand Down

0 comments on commit 7f8bd04

Please sign in to comment.