Skip to content

Commit

Permalink
update export
Browse files Browse the repository at this point in the history
  • Loading branch information
pythops committed Sep 11, 2024
1 parent 06c7024 commit 1b59ccb
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 35 deletions.
46 changes: 28 additions & 18 deletions oryx-tui/src/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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, "-"
)?;
}
},
}
}

Expand Down
34 changes: 17 additions & 17 deletions oryx-tui/src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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,
)?;
}
}
}
}
}
Expand Down

0 comments on commit 1b59ccb

Please sign in to comment.