pub fn generate_packet(
        &self,
        src_port: u16,
        dst_port: u16,
        payload_len: usize,
    ) -> Result<Vec<u8>, WriteError> {
        let builder = PacketBuilder::ethernet2(
            self.src.addr(), // src mac
            self.dst.addr(), // dst mac
        )
        .ipv4(
            self.src.ip_addr().octets(), // src ip
            self.dst.ip_addr().octets(), // dst ip
            20,                          // time to live
        )
        .udp(src_port, dst_port);

        let payload = generate_random_bytes(payload_len);

        let mut result = Vec::with_capacity(builder.size(payload.len()));

        builder.write(&mut result, &payload)?;

        Ok(result)
    }
/// Generate an ETH frame w/ UDP as transport layer and payload size `payload_len`
Generate an ETH frame w/ UDP as transport layer and payload size `payload_len`
Generate an ETH frame w / UDP as transport layer and payload size ` payload_len `
pub fn generate_packet(
        &self,
        src_port: u16,
        dst_port: u16,
        payload_len: usize,
    ) -> Result<Vec<u8>, WriteError> {
        let builder = PacketBuilder::ethernet2(
            self.src.addr(), // src mac
            self.dst.addr(), // dst mac
        )
        .ipv4(
            self.src.ip_addr().octets(), // src ip
            self.dst.ip_addr().octets(), // dst ip
            20,                          // time to live
        )
        .udp(src_port, dst_port);
        let payload = generate_random_bytes(payload_len);
        let mut result = Vec::with_capacity(builder.size(payload.len()));
        builder.write(&mut result, &payload)?;
        Ok(result)
    }
pub fn generate_packet ( & self , src_port : u16 , dst_port : u16 , payload_len : usize , ) -> Result < Vec < u8 > , WriteError > { let builder = PacketBuilder :: ethernet2 ( self . src . addr ( ) , // src mac self . dst . addr ( ) , // dst mac ) . ipv4 ( self . src . ip_addr ( ) . octets ( ) , // src ip self . dst . ip_addr ( ) . octets ( ) , // dst ip 20 , // time to live ) . udp ( src_port , dst_port ) ; let payload = generate_random_bytes ( payload_len ) ; let mut result = Vec :: with_capacity ( builder . size ( payload . len ( ) ) ) ; builder . write ( & mut result , & payload ) ? ; Ok ( result ) }
Generate an ETH frame w/ UDP as transport layer and payload size `payload_len`
Generate an ETH frame w / UDP as transport layer and payload size ` payload_len `
&self
src_port
u16
dst_port
u16
payload_len
usize
&self
src_port
u16
dst_port
u16
payload_len
usize