pub fn parse_packet_header(packet: &[u8]) -> Result<NtpPacketHeader, std::io::Error> {
    let mut buff = Cursor::new(packet);
    if packet.len() < 48 {
        Err(Error::new(ErrorKind::InvalidInput, "Too short"))
    } else {
        let first = buff.read_u8()?;
        let stratum = buff.read_u8()?;
        let poll = buff.read_i8()?;
        let precision = buff.read_i8()?;
        let root_delay = buff.read_u32::<BigEndian>()?;
        let root_dispersion = buff.read_u32::<BigEndian>()?;
        let reference_id = buff.read_u32::<BigEndian>()?;
        let ref_timestamp = buff.read_u64::<BigEndian>()?;
        let origin_timestamp = buff.read_u64::<BigEndian>()?;
        let receive_timestamp = buff.read_u64::<BigEndian>()?;
        let transmit_timestamp = buff.read_u64::<BigEndian>()?;
        Ok(NtpPacketHeader {
            leap_indicator: parse_leap_indicator(first),
            version: parse_version(first),
            mode: parse_mode(first),
            stratum: stratum,
            poll: poll,
            precision: precision,
            root_delay: root_delay,
            root_dispersion: root_dispersion,
            reference_id: reference_id,
            reference_timestamp: ref_timestamp,
            origin_timestamp: origin_timestamp,
            receive_timestamp: receive_timestamp,
            transmit_timestamp: transmit_timestamp,
        })
    }
}
/// Extract an NTP packet header from packet and return an error if it cannot be done.
Extract an NTP packet header from packet and return an error if it cannot be done.
Extract an NTP packet header from packet and return an error if it cannot be done .
pub fn parse_packet_header(packet: &[u8]) -> Result<NtpPacketHeader, std::io::Error> {
    let mut buff = Cursor::new(packet);
    if packet.len() < 48 {
        Err(Error::new(ErrorKind::InvalidInput, "Too short"))
    } else {
        let first = buff.read_u8()?;
        let stratum = buff.read_u8()?;
        let poll = buff.read_i8()?;
        let precision = buff.read_i8()?;
        let root_delay = buff.read_u32::<BigEndian>()?;
        let root_dispersion = buff.read_u32::<BigEndian>()?;
        let reference_id = buff.read_u32::<BigEndian>()?;
        let ref_timestamp = buff.read_u64::<BigEndian>()?;
        let origin_timestamp = buff.read_u64::<BigEndian>()?;
        let receive_timestamp = buff.read_u64::<BigEndian>()?;
        let transmit_timestamp = buff.read_u64::<BigEndian>()?;
        Ok(NtpPacketHeader {
            leap_indicator: parse_leap_indicator(first),
            version: parse_version(first),
            mode: parse_mode(first),
            stratum: stratum,
            poll: poll,
            precision: precision,
            root_delay: root_delay,
            root_dispersion: root_dispersion,
            reference_id: reference_id,
            reference_timestamp: ref_timestamp,
            origin_timestamp: origin_timestamp,
            receive_timestamp: receive_timestamp,
            transmit_timestamp: transmit_timestamp,
        })
    }
}
pub fn parse_packet_header ( packet : & [ u8 ] ) -> Result < NtpPacketHeader , std :: io :: Error > { let mut buff = Cursor :: new ( packet ) ; if packet . len ( ) < 48 { Err ( Error :: new ( ErrorKind :: InvalidInput , " " ) ) } else { let first = buff . read_u8 ( ) ? ; let stratum = buff . read_u8 ( ) ? ; let poll = buff . read_i8 ( ) ? ; let precision = buff . read_i8 ( ) ? ; let root_delay = buff . read_u32 :: < BigEndian > ( ) ? ; let root_dispersion = buff . read_u32 :: < BigEndian > ( ) ? ; let reference_id = buff . read_u32 :: < BigEndian > ( ) ? ; let ref_timestamp = buff . read_u64 :: < BigEndian > ( ) ? ; let origin_timestamp = buff . read_u64 :: < BigEndian > ( ) ? ; let receive_timestamp = buff . read_u64 :: < BigEndian > ( ) ? ; let transmit_timestamp = buff . read_u64 :: < BigEndian > ( ) ? ; Ok ( NtpPacketHeader { leap_indicator : parse_leap_indicator ( first ) , version : parse_version ( first ) , mode : parse_mode ( first ) , stratum : stratum , poll : poll , precision : precision , root_delay : root_delay , root_dispersion : root_dispersion , reference_id : reference_id , reference_timestamp : ref_timestamp , origin_timestamp : origin_timestamp , receive_timestamp : receive_timestamp , transmit_timestamp : transmit_timestamp , } ) } }
Extract an NTP packet header from packet and return an error if it cannot be done.
Extract an NTP packet header from packet and return an error if it cannot be done .
packet
&[u8]
packet
&[u8]