internet 0.0.5

Network library for rust
Documentation
//! Encoding for IPv4 header following [RFC 791].
//!
//! [IETF RFC 791]: https://datatracker.ietf.org/doc/html/rfc791

use crate::{Buf, BufMut, BufResult, Codec, Cursor, ipv4::Address};

/// A IPv4 header following [RFC 791].
///
/// [IETF RFC 791]: https://datatracker.ietf.org/doc/html/rfc791
///
/// # Examples
/// ```
/// ```
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct Header {
    ///
    pub dscp: u8,
    ///
    pub ihl: u8,
    ///
    pub ecn: u8,
    ///
    pub total_length: u16,
    ///
    pub identification: u16,
    ///
    pub df: bool,
    ///
    pub mf: bool,
    ///
    pub fragment_offset: u16,
    ///
    pub ttl: u8,
    ///
    pub protocol: u8,
    ///
    pub checksum: u16,
    ///
    pub source_address: Address,
    ///
    pub destination_address: Address,
}

impl Header {
    /// Version field.
    pub const VERSION: u8 = 4;
}

impl Codec for Header {
    fn encode<W: BufMut>(&self, _writer: &mut Cursor<W>, _: ()) -> BufResult<()> {
        todo!()
    }

    fn decode<R: Buf>(reader: &mut Cursor<R>, _: ()) -> BufResult<Self> {
        let _ = reader.read_array::<20>()?;

        let dscp = 0;
        let ihl = 0;
        let ecn = 0;
        let total_length = 0;
        let identification = 0;
        let df = false;
        let mf = false;
        let fragment_offset = 0;
        let ttl = 0;
        let protocol = 0;
        let checksum = 0;
        let source_address = Address::UNSPECIFIED;
        let destination_address = Address::UNSPECIFIED;
        Ok(Self {
            dscp,
            ihl,
            ecn,
            total_length,
            identification,
            df,
            mf,
            fragment_offset,
            ttl,
            protocol,
            checksum,
            source_address,
            destination_address,
        })
    }
}

#[cfg(test)]
mod tests {
    #[test]
    fn test() {}
}