pub fn write_header(
        buf: T,
        protocol: u8,
        src_addr: Ipv4Addr,
        dst_addr: Ipv4Addr,
    ) -> Result<Incomplete<Self>, Error> {
        if buf.len() < OPTIONS_OFFSET {
            return Err(Error::SliceTooShort);
        }
        let mut packet = IPv4Packet::from_bytes_unchecked(buf);
        packet
            .set_version_and_header_len(IPV4_VERSION, OPTIONS_OFFSET)
            .set_dscp_and_ecn(0, 0)
            .set_identification(0)
            .set_flags_and_fragment_offset(0, 0)
            .set_ttl(DEFAULT_TTL)
            .set_protocol(protocol)
            .set_source_address(src_addr)
            .set_destination_address(dst_addr);

        Ok(Incomplete::new(packet))
    }
/// Attempts to write an IPv4 packet header to `buf`, making sure there is enough space.
///
/// This method returns an incomplete packet, because the size of the payload might be unknown
/// at this point. IP options are not allowed, which means `header_len == OPTIONS_OFFSET`. The
/// `dscp`, `ecn`, `identification`, `flags`, and `fragment_offset` fields are set to 0. The
/// `ttl` is set to a default value. The `total_len` and `checksum` fields will be set when
/// the length of the incomplete packet is determined.
Attempts to write an IPv4 packet header to `buf`, making sure there is enough space.
This method returns an incomplete packet, because the size of the payload might be unknown
at this point. IP options are not allowed, which means `header_len == OPTIONS_OFFSET`.
Attempts to write an IPv4 packet header to ` buf ` making sure there is enough space . This method returns an incomplete packet because the size of the payload might be unknown at this point . IP options are not allowed which means ` header_len == OPTIONS_OFFSET ` .
pub fn write_header(
        buf: T,
        protocol: u8,
        src_addr: Ipv4Addr,
        dst_addr: Ipv4Addr,
    ) -> Result<Incomplete<Self>, Error> {
        if buf.len() < OPTIONS_OFFSET {
            return Err(Error::SliceTooShort);
        }
        let mut packet = IPv4Packet::from_bytes_unchecked(buf);
        packet
            .set_version_and_header_len(IPV4_VERSION, OPTIONS_OFFSET)
            .set_dscp_and_ecn(0, 0)
            .set_identification(0)
            .set_flags_and_fragment_offset(0, 0)
            .set_ttl(DEFAULT_TTL)
            .set_protocol(protocol)
            .set_source_address(src_addr)
            .set_destination_address(dst_addr);
        Ok(Incomplete::new(packet))
    }
pub fn write_header ( buf : T , protocol : u8 , src_addr : Ipv4Addr , dst_addr : Ipv4Addr , ) -> Result < Incomplete < Self > , Error > { if buf . len ( ) < OPTIONS_OFFSET { return Err ( Error :: SliceTooShort ) ; } let mut packet = IPv4Packet :: from_bytes_unchecked ( buf ) ; packet . set_version_and_header_len ( IPV4_VERSION , OPTIONS_OFFSET ) . set_dscp_and_ecn ( 0 , 0 ) . set_identification ( 0 ) . set_flags_and_fragment_offset ( 0 , 0 ) . set_ttl ( DEFAULT_TTL ) . set_protocol ( protocol ) . set_source_address ( src_addr ) . set_destination_address ( dst_addr ) ; Ok ( Incomplete :: new ( packet ) ) }
Attempts to write an IPv4 packet header to `buf`, making sure there is enough space.
Attempts to write an IPv4 packet header to ` buf ` making sure there is enough space .
buf
T
protocol
u8
src_addr
Ipv4Addr
dst_addr
Ipv4Addr
buf
T
protocol
u8
src_addr
Ipv4Addr
dst_addr
Ipv4Addr