fn build_ipv4_response(request: &Ipv4Packet, src_address: Ipv4Addr, data: Vec<u8>) -> Vec<u8> {
    let mut response = vec![0; MutableIpv4Packet::minimum_packet_size() + data.len()];

    let mut packet = MutableIpv4Packet::new(&mut response)
        .expect("Could not construct IPv4 packet with vector as buffer");
    packet.populate(&Ipv4 {
        version: 4,
        header_length: 5,
        dscp: 0,
        ecn: 0,
        total_length: 20_u16 + data.len() as u16,
        identification: 42,
        flags: Ipv4Flags::DontFragment,
        fragment_offset: 0,
        ttl: request.get_ttl() - 1,
        next_level_protocol: IpNextHeaderProtocols::Icmp,
        checksum: 0,
        source: src_address,
        destination: request.get_source(),
        options: vec![],
        payload: data,
    });
    packet.set_checksum(checksum(&packet.to_immutable()));

    trace!(
        "Constructed IPv4 response [len={}, response={:?}]",
        packet.get_total_length(),
        packet.to_immutable(),
    );
    response
}
/// Build an IPv4 packet in response to the provided one
///
/// The generated response packet will have most of it's relevant data extracted from `request`
/// except for it's own source address which is provided via `src_address`. It will also have
/// the given `data` as its payload.
Build an IPv4 packet in response to the provided one
The generated response packet will have most of it's relevant data extracted from `request`
except for it's own source address which is provided via `src_address`. It will also have
the given `data` as its payload.
Build an IPv4 packet in response to the provided one The generated response packet will have most of it ' s relevant data extracted from ` request ` except for it ' s own source address which is provided via ` src_address ` . It will also have the given ` data ` as its payload .
fn build_ipv4_response(request: &Ipv4Packet, src_address: Ipv4Addr, data: Vec<u8>) -> Vec<u8> {
    let mut response = vec![0; MutableIpv4Packet::minimum_packet_size() + data.len()];
    let mut packet = MutableIpv4Packet::new(&mut response)
        .expect("Could not construct IPv4 packet with vector as buffer");
    packet.populate(&Ipv4 {
        version: 4,
        header_length: 5,
        dscp: 0,
        ecn: 0,
        total_length: 20_u16 + data.len() as u16,
        identification: 42,
        flags: Ipv4Flags::DontFragment,
        fragment_offset: 0,
        ttl: request.get_ttl() - 1,
        next_level_protocol: IpNextHeaderProtocols::Icmp,
        checksum: 0,
        source: src_address,
        destination: request.get_source(),
        options: vec![],
        payload: data,
    });
    packet.set_checksum(checksum(&packet.to_immutable()));
    trace!(
        "Constructed IPv4 response [len={}, response={:?}]",
        packet.get_total_length(),
        packet.to_immutable(),
    );
    response
}
fn build_ipv4_response ( request : & Ipv4Packet , src_address : Ipv4Addr , data : Vec < u8 > ) -> Vec < u8 > { let mut response = vec ! [ 0 MutableIpv4Packet minimum_packet_size ( ) data len ( ) ] ; let mut packet = MutableIpv4Packet :: new ( & mut response ) . expect ( " " ) ; packet . populate ( & Ipv4 { version : 4 , header_length : 5 , dscp : 0 , ecn : 0 , total_length : 20_u16 + data . len ( ) as u16 , identification : 42 , flags : Ipv4Flags :: DontFragment , fragment_offset : 0 , ttl : request . get_ttl ( ) - 1 , next_level_protocol : IpNextHeaderProtocols :: Icmp , checksum : 0 , source : src_address , destination : request . get_source ( ) , options : vec ! [ ] , payload : data , } ) ; packet . set_checksum ( checksum ( & packet . to_immutable ( ) ) ) ; trace ! ( " " packet get_total_length ( ) packet to_immutable ( ) ) ; response }
Build an IPv4 packet in response to the provided one
The generated response packet will have most of it's relevant data extracted from `request`
except for it's own source address which is provided via `src_address`.
Build an IPv4 packet in response to the provided one The generated response packet will have most of it ' s relevant data extracted from ` request ` except for it ' s own source address which is provided via ` src_address ` .
request
&Ipv4Packet
src_address
Ipv4Addr
data
Vec<u8>
request
&Ipv4Packet
src_address
Ipv4Addr
data
Vec<u8>