From 1b59ccb084317d4cec94d6f7a11879794185b0f0 Mon Sep 17 00:00:00 2001 From: pythops Date: Wed, 11 Sep 2024 19:36:47 +0200 Subject: [PATCH] update export --- oryx-tui/src/export.rs | 46 +++++++++++++++++++++++++---------------- oryx-tui/src/handler.rs | 34 +++++++++++++++--------------- 2 files changed, 45 insertions(+), 35 deletions(-) diff --git a/oryx-tui/src/export.rs b/oryx-tui/src/export.rs index abd1497..4f735fc 100644 --- a/oryx-tui/src/export.rs +++ b/oryx-tui/src/export.rs @@ -3,10 +3,11 @@ use std::io::prelude::*; use std::os::unix::fs::chown; use oryx_common::ip::IpPacket; +use oryx_common::AppPacket; use crate::app::AppResult; -pub fn export(packets: &[IpPacket]) -> AppResult<()> { +pub fn export(packets: &[AppPacket]) -> AppResult<()> { let uid = unsafe { libc::geteuid() }; let oryx_export_dir = dirs::home_dir().unwrap().join("oryx"); @@ -34,27 +35,36 @@ pub fn export(packets: &[IpPacket]) -> AppResult<()> { )?; for packet in packets { match packet { - IpPacket::Tcp(p) => { + AppPacket::Arp(p) => { writeln!( file, - "{:39} {:<11} {:39} {:<11} TCP", - p.src_ip, p.src_port, p.dst_ip, p.dst_port - )?; - } - IpPacket::Udp(p) => { - writeln!( - file, - "{:39} {:<11} {:39} {:<11} UDP", - p.src_ip, p.src_port, p.dst_ip, p.dst_port - )?; - } - IpPacket::Icmp(p) => { - writeln!( - file, - "{:39} {:^11} {:39} {:^11} ICMP", - p.src_ip, "-", p.dst_ip, "-" + "{:39} {:^11} {:39} {:^11} ARP", + p.src_mac, "-", p.dst_mac, "-" )?; } + AppPacket::Ip(packet) => match packet { + IpPacket::Tcp(p) => { + writeln!( + file, + "{:39} {:<11} {:39} {:<11} TCP", + p.src_ip, p.src_port, p.dst_ip, p.dst_port + )?; + } + IpPacket::Udp(p) => { + writeln!( + file, + "{:39} {:<11} {:39} {:<11} UDP", + p.src_ip, p.src_port, p.dst_ip, p.dst_port + )?; + } + IpPacket::Icmp(p) => { + writeln!( + file, + "{:39} {:^11} {:39} {:^11} ICMP", + p.src_ip, "-", p.dst_ip, "-" + )?; + } + }, } } diff --git a/oryx-tui/src/handler.rs b/oryx-tui/src/handler.rs index 048e879..209f921 100644 --- a/oryx-tui/src/handler.rs +++ b/oryx-tui/src/handler.rs @@ -5,6 +5,7 @@ use crate::{ app::{App, AppResult, FocusedBlock, Mode}, ebpf::Ebpf, event::Event, + export::export, filters::{ direction::TrafficDirection, link::{LinkProtocol, NB_LINK_PROTOCOL}, @@ -386,23 +387,22 @@ pub fn handle_key_events( sender, )?; } else { - // match export(&app.packets) { - //TODO: later - // Ok(_) => { - // Notification::send( - // "Packets exported to ~/oryx/capture file".to_string(), - // NotificationLevel::Info, - // sender, - // )?; - // } - // Err(e) => { - // Notification::send( - // e.to_string(), - // NotificationLevel::Error, - // sender, - // )?; - // } - // } + match export(&app.packets) { + Ok(_) => { + Notification::send( + "Packets exported to ~/oryx/capture file".to_string(), + NotificationLevel::Info, + sender, + )?; + } + Err(e) => { + Notification::send( + e.to_string(), + NotificationLevel::Error, + sender, + )?; + } + } } } }