Skip to content

Commit

Permalink
Minor fixes for non-std support
Browse files Browse the repository at this point in the history
  • Loading branch information
JulianSchmid authored May 2, 2024
1 parent 0f4603e commit 34f3e45
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions etherparse/src/link/linux_sll_header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ impl LinuxSllHeader {

/// Read an SLL header from a slice and return the header & unused parts of the slice.
#[inline]
pub fn from_slice(slice: &[u8]) -> Result<(LinuxSllHeader, &[u8]), err::ReadError> {
pub fn from_slice(slice: &[u8]) -> Result<(LinuxSllHeader, &[u8]), err::linux_sll::HeaderSliceError> {
Ok((
LinuxSllHeaderSlice::from_slice(slice)?.to_header(),
&slice[LinuxSllHeader::LEN..],
Expand All @@ -34,11 +34,13 @@ impl LinuxSllHeader {
/// Read an SLL header from a static sized byte array.
#[inline]
pub fn from_bytes(bytes: [u8; 16]) -> Result<LinuxSllHeader, err::ReadError> {
let packet_type = LinuxSllPacketType::try_from(u16::from_be_bytes([bytes[0], bytes[1]]))?;
use err::linux_sll::HeaderSliceError::Content;

let packet_type = LinuxSllPacketType::try_from(u16::from_be_bytes([bytes[0], bytes[1]])).map_err(Content)?;
let arp_hrd_type = ArpHardwareId::from(u16::from_be_bytes([bytes[2], bytes[3]]));
let sender_address_valid_length = u16::from_be_bytes([bytes[4], bytes[5]]);
let sender_address = [bytes[6], bytes[7], bytes[8], bytes[9], bytes[10], bytes[11], bytes[12], bytes[13]];
let protocol_type = LinuxSllProtocolType::try_from((arp_hrd_type, u16::from_be_bytes([bytes[14], bytes[15]])))?;
let protocol_type = LinuxSllProtocolType::try_from((arp_hrd_type, u16::from_be_bytes([bytes[14], bytes[15]]))).map_err(Content)?;

Ok(LinuxSllHeader {
packet_type,
Expand Down

0 comments on commit 34f3e45

Please sign in to comment.