mirror of
https://github.com/tribufu/rust-gamedig
synced 2026-06-01 09:42:41 +00:00
refactor: clean up
This commit is contained in:
parent
3d47180e85
commit
0543cabce2
6 changed files with 137 additions and 171 deletions
|
|
@ -1,25 +1,24 @@
|
|||
pub(crate) mod packet;
|
||||
mod pcap;
|
||||
pub mod writer;
|
||||
pub(crate) mod writer;
|
||||
|
||||
use pcap_file::pcapng::PcapNgBlock;
|
||||
use writer::Writer;
|
||||
use self::{pcap::Pcap, writer::Writer};
|
||||
use pcap_file::pcapng::{blocks::interface_description::InterfaceDescriptionBlock, PcapNgBlock, PcapNgWriter};
|
||||
use std::path::PathBuf;
|
||||
|
||||
use self::pcap::Pcap;
|
||||
|
||||
pub fn setup_capture(file_name: Option<String>) {
|
||||
if let Some(file_name) = file_name {
|
||||
pub fn setup_capture(file_path: Option<PathBuf>) {
|
||||
if let Some(file_path) = file_path {
|
||||
let file = std::fs::OpenOptions::new()
|
||||
.create_new(true)
|
||||
.write(true)
|
||||
.open(file_name)
|
||||
.open(file_path.with_extension("pcap"))
|
||||
.unwrap();
|
||||
|
||||
let mut pcap_writer = pcap_file::pcapng::PcapNgWriter::new(file).unwrap();
|
||||
let mut pcap_writer = PcapNgWriter::new(file).unwrap();
|
||||
|
||||
// Write headers
|
||||
let _ = pcap_writer.write_block(
|
||||
&pcap_file::pcapng::blocks::interface_description::InterfaceDescriptionBlock {
|
||||
let _ = pcap_writer.write_block(
|
||||
&InterfaceDescriptionBlock {
|
||||
linktype: pcap_file::DataLink::ETHERNET,
|
||||
snaplen: 0xFFFF,
|
||||
options: vec![],
|
||||
|
|
@ -30,6 +29,7 @@ pub fn setup_capture(file_name: Option<String>) {
|
|||
let writer = Box::new(Pcap::new(pcap_writer));
|
||||
attach(writer)
|
||||
} else {
|
||||
// If no file path is provided
|
||||
// Do nothing
|
||||
}
|
||||
}
|
||||
|
|
@ -37,7 +37,7 @@ pub fn setup_capture(file_name: Option<String>) {
|
|||
/// Attaches a writer to the capture module.
|
||||
///
|
||||
/// # Errors
|
||||
/// Returns an `io::Error` if the writer is already set.
|
||||
/// Returns an Error if the writer is already set.
|
||||
fn attach(writer: Box<dyn Writer + Send + Sync>) {
|
||||
crate::socket::capture::set_writer(writer);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue