pub struct ReusablePacketWriter { /* private fields */ }
Expand description
Wrapper around Vec<u8>
that is pre-allocates memory for writing packet bytes
Implementations§
Source§impl ReusablePacketWriter
impl ReusablePacketWriter
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates wrapper around Vec<u8>
with pre-allocated u16::MAX
(max possible MTU size)
Examples found in repository?
examples/udp_packet.rs (line 12)
7fn main() -> ip_spoofing::Result<()> {
8 //wrapper around raw sockets, requires root privileges
9 let socket = RawSocket::new()?;
10
11 //wrapper for writing packets in pre-allocated memory
12 let mut writer = ReusablePacketWriter::new();
13
14 //sends fake UDP packet
15 socket.send_fake_udp_packet(
16 &mut writer,
17 [8, 8, 8, 8], //source IPv4 address
18 1234, //source port
19 [127, 0, 0, 1], //destination IPv4 address
20 5678, //destination port
21 b"hey", //data
22 64, //TTL on most Linux machines is 64
23 )?;
24
25 Ok(())
26}
More examples
examples/udp_flood.rs (line 12)
7fn main() -> ip_spoofing::Result<()> {
8 //wrapper around raw sockets, requires root privileges
9 let socket = RawSocket::new()?;
10
11 //wrapper for writing packets in pre-allocated memory
12 let mut writer = ReusablePacketWriter::new();
13 //thread-local pseudorandom number generator
14 let mut rng = thread_rng();
15
16 //endless spam with a randomly generated UDP packet
17 loop {
18 let ret = socket.send_fake_udp_packet(
19 &mut writer,
20 rng.gen(), //random source IPv4 address
21 rng.gen(), //random source port
22 [127, 0, 0, 1], //destination IPv4 address
23 5678, //destination port
24 b"hey", //data
25 64, //TTL on most Linux machines is 64
26 );
27
28 if let Err(err) = ret {
29 println!("{err:?}");
30 }
31 }
32}
Sourcepub fn build_ipv4_header(
time_to_live: u8,
protocol: IpNumber,
source: [u8; 4],
destination: [u8; 4],
) -> IpHeaders
pub fn build_ipv4_header( time_to_live: u8, protocol: IpNumber, source: [u8; 4], destination: [u8; 4], ) -> IpHeaders
Builds IPv4 header with randomized identification
field
Trait Implementations§
Auto Trait Implementations§
impl Freeze for ReusablePacketWriter
impl RefUnwindSafe for ReusablePacketWriter
impl Send for ReusablePacketWriter
impl Sync for ReusablePacketWriter
impl Unpin for ReusablePacketWriter
impl UnwindSafe for ReusablePacketWriter
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more