mirror of
https://github.com/tribufu/rust-gamedig
synced 2026-06-01 09:42:41 +00:00
merge: Douile fork + local (broken af)
This commit is contained in:
parent
8d17ca4e48
commit
49096e46bb
9 changed files with 852 additions and 519 deletions
41
crates/lib/src/capture/writer.rs
Normal file
41
crates/lib/src/capture/writer.rs
Normal 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(())
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue