mirror of
https://github.com/Tribufu/rust-gamedig
synced 2026-08-10 07:31:07 +00:00
chore: format
This commit is contained in:
parent
1991c9f5eb
commit
b49525543d
5 changed files with 101 additions and 93 deletions
|
|
@ -38,6 +38,4 @@ pub fn setup_capture(file_path: Option<PathBuf>) {
|
|||
///
|
||||
/// # Errors
|
||||
/// Returns an Error if the writer is already set.
|
||||
fn attach(writer: Box<dyn Writer + Send + Sync>) {
|
||||
crate::socket::capture::set_writer(writer);
|
||||
}
|
||||
fn attach(writer: Box<dyn Writer + Send + Sync>) { crate::socket::capture::set_writer(writer); }
|
||||
|
|
|
|||
|
|
@ -31,7 +31,8 @@ pub(crate) enum Protocol {
|
|||
|
||||
/// Trait for handling different types of IP addresses (IPv4, IPv6).
|
||||
pub(crate) trait IpAddress: Sized {
|
||||
/// Creates an instance from a standard `IpAddr`, returning `None` if the types are incompatible.
|
||||
/// Creates an instance from a standard `IpAddr`, returning `None` if the
|
||||
/// types are incompatible.
|
||||
fn from_std(ip: IpAddr) -> Option<Self>;
|
||||
}
|
||||
|
||||
|
|
@ -67,12 +68,15 @@ impl CapturePacket<'_> {
|
|||
(local, remote)
|
||||
}
|
||||
|
||||
/// Retrieves IP addresses of a specific type (IPv4 or IPv6) based on the packet's direction.
|
||||
/// Retrieves IP addresses of a specific type (IPv4 or IPv6) based on the
|
||||
/// packet's direction.
|
||||
///
|
||||
/// Panics if the IP type of the addresses does not match the requested type.
|
||||
/// Panics if the IP type of the addresses does not match the requested
|
||||
/// type.
|
||||
///
|
||||
/// Returns:
|
||||
/// - (T, T): Tuple of (source IP, destination IP) of the specified type in order.
|
||||
/// - (T, T): Tuple of (source IP, destination IP) of the specified type in
|
||||
/// order.
|
||||
pub(super) fn ipvt_by_direction<T: IpAddress>(&self) -> (T, T) {
|
||||
let (local, remote) = (
|
||||
T::from_std(self.local_address.ip()).expect("Incorrect IP type for local address"),
|
||||
|
|
@ -84,7 +88,8 @@ impl CapturePacket<'_> {
|
|||
}
|
||||
|
||||
impl Direction {
|
||||
/// Orders two elements (source and destination) based on the packet's direction.
|
||||
/// Orders two elements (source and destination) based on the packet's
|
||||
/// direction.
|
||||
///
|
||||
/// Returns:
|
||||
/// - (T, T): Ordered tuple (source, destination).
|
||||
|
|
@ -124,9 +129,7 @@ mod tests {
|
|||
use std::str::FromStr;
|
||||
|
||||
// Helper function to create a SocketAddr from a string
|
||||
fn socket_addr(addr: &str) -> SocketAddr {
|
||||
SocketAddr::from_str(addr).unwrap()
|
||||
}
|
||||
fn socket_addr(addr: &str) -> SocketAddr { SocketAddr::from_str(addr).unwrap() }
|
||||
|
||||
#[test]
|
||||
fn test_ports_by_direction() {
|
||||
|
|
|
|||
|
|
@ -11,7 +11,13 @@ use pnet_packet::{
|
|||
use std::{io::Write, net::IpAddr, time::Instant};
|
||||
|
||||
use super::packet::{
|
||||
CapturePacket, Direction, Protocol, HEADER_SIZE_ETHERNET, HEADER_SIZE_IP4, HEADER_SIZE_IP6, HEADER_SIZE_UDP,
|
||||
CapturePacket,
|
||||
Direction,
|
||||
Protocol,
|
||||
HEADER_SIZE_ETHERNET,
|
||||
HEADER_SIZE_IP4,
|
||||
HEADER_SIZE_IP6,
|
||||
HEADER_SIZE_UDP,
|
||||
PACKET_SIZE,
|
||||
};
|
||||
|
||||
|
|
@ -80,7 +86,7 @@ impl<W: Write> Pcap<W> {
|
|||
self.write_transport_payload(
|
||||
info,
|
||||
IpNextHeaderProtocols::Tcp,
|
||||
&buf[..buf_size + payload.len()],
|
||||
&buf[.. buf_size + payload.len()],
|
||||
vec![],
|
||||
);
|
||||
|
||||
|
|
@ -113,7 +119,7 @@ impl<W: Write> Pcap<W> {
|
|||
self.write_transport_payload(
|
||||
&info,
|
||||
IpNextHeaderProtocols::Tcp,
|
||||
&buf[..buf_size],
|
||||
&buf[.. buf_size],
|
||||
vec![EnhancedPacketOption::Comment("Generated TCP ACK".into())],
|
||||
);
|
||||
}
|
||||
|
|
@ -131,7 +137,7 @@ impl<W: Write> Pcap<W> {
|
|||
self.write_transport_payload(
|
||||
info,
|
||||
IpNextHeaderProtocols::Udp,
|
||||
&buf[..buf_size + payload.len()],
|
||||
&buf[.. buf_size + payload.len()],
|
||||
vec![],
|
||||
);
|
||||
}
|
||||
|
|
@ -238,7 +244,7 @@ impl<W: Write> Pcap<W> {
|
|||
self.write_transport_payload(
|
||||
&info,
|
||||
IpNextHeaderProtocols::Tcp,
|
||||
&buf[..buf_size],
|
||||
&buf[.. buf_size],
|
||||
options.clone(),
|
||||
);
|
||||
|
||||
|
|
@ -261,7 +267,7 @@ impl<W: Write> Pcap<W> {
|
|||
self.write_transport_payload(
|
||||
&info,
|
||||
IpNextHeaderProtocols::Tcp,
|
||||
&buf[..buf_size],
|
||||
&buf[.. buf_size],
|
||||
options.clone(),
|
||||
);
|
||||
|
||||
|
|
@ -280,7 +286,12 @@ impl<W: Write> Pcap<W> {
|
|||
|
||||
tcp.packet_size()
|
||||
};
|
||||
self.write_transport_payload(&info, IpNextHeaderProtocols::Tcp, &buf[..buf_size], options);
|
||||
self.write_transport_payload(
|
||||
&info,
|
||||
IpNextHeaderProtocols::Tcp,
|
||||
&buf[.. buf_size],
|
||||
options,
|
||||
);
|
||||
|
||||
self.state.has_sent_handshake = true;
|
||||
}
|
||||
|
|
@ -314,7 +325,7 @@ impl<W: Write> Pcap<W> {
|
|||
self.write_transport_payload(
|
||||
info,
|
||||
IpNextHeaderProtocols::Tcp,
|
||||
&buf[..buf_size],
|
||||
&buf[.. buf_size],
|
||||
vec![EnhancedPacketOption::Comment("Generated TCP FIN".into())],
|
||||
);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue