merge: Douile fork + local (broken af)

This commit is contained in:
Cain 2024-01-12 07:57:16 +00:00 committed by Douile
parent 8d17ca4e48
commit 49096e46bb
No known key found for this signature in database
GPG key ID: E048586A5FF6585C
9 changed files with 852 additions and 519 deletions

View file

@ -0,0 +1,41 @@
use std::io::Write;
use crate::{
capture::packet::{CapturePacket, Protocol},
GDResult,
};
use super::pcap::Pcap;
use lazy_static::lazy_static;
use std::sync::Mutex;
lazy_static! {
pub(crate) static ref CAPTURE_WRITER: Mutex<Option<Box<dyn Writer + Send + Sync>>> = Mutex::new(None);
}
pub trait Writer {
fn write(&mut self, packet: &CapturePacket, data: &[u8]) -> crate::GDResult<()>;
fn new_connect(&mut self, packet: &CapturePacket) -> crate::GDResult<()>;
}
impl<W: Write> Writer for Pcap<W> {
fn write(&mut self, info: &CapturePacket, data: &[u8]) -> GDResult<()> {
self.write_transport_packet(info, data);
Ok(())
}
fn new_connect(&mut self, packet: &CapturePacket) -> GDResult<()> {
match packet.protocol {
Protocol::TCP => {
self.write_tcp_handshake(packet);
}
Protocol::UDP => {}
}
self.state.stream_count = self.state.stream_count.wrapping_add(1);
Ok(())
}
}