pub struct PacketBuilder {}
Expand description

Helper for building packets.

The packet builder allows the easy construction of a packet from the ethernet II layer downwards including ipv6, ipv4, the udp header and the actual payload. The packet builder automatically calculates lengths & checksums for ip & udp and set type identifiers for ethernetII and ip. This makes it easy and less error prone to construct custom packets.

Example

let builder = PacketBuilder::
    ethernet2([1,2,3,4,5,6],     //source mac
              [7,8,9,10,11,12]) //destionation mac
   .ipv4([192,168,1,1], //source ip
         [192,168,1,2], //desitionation ip
         20)            //time to life
   .udp(21,    //source port 
        1234); //desitnation port

//payload of the udp packet
let payload = [1,2,3,4,5,6,7,8];
     
//get some memory to store the result
let mut result = Vec::<u8>::with_capacity(
                    builder.size(payload.len()));
     
//serialize
builder.write(&mut result, &payload).unwrap();
println!("{:?}", result);

Implementations§

Start an packet with an ethernetII header.

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.