Skip to content

Commit

Permalink
Enable build for 16 bit systems
Browse files Browse the repository at this point in the history
  • Loading branch information
JulianSchmid committed Apr 1, 2024
1 parent 0972c42 commit 4deb644
Show file tree
Hide file tree
Showing 13 changed files with 22 additions and 9 deletions.
14 changes: 7 additions & 7 deletions etherparse/src/checksum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pub struct Sum16BitWords {
sum: u64,

/// Partial sum
#[cfg(target_pointer_width = "32")]
#[cfg(any(target_pointer_width = "16", target_pointer_width = "32"))]
sum: u32,
}

Expand All @@ -20,7 +20,7 @@ impl Sum16BitWords {
/// has a length that is not multiple of 2 the last byte
/// will be padded with 0.
#[inline]
#[cfg(target_pointer_width = "32")]
#[cfg(any(target_pointer_width = "16", target_pointer_width = "32"))]
pub fn add_slice(self, slice: &[u8]) -> Sum16BitWords {
Sum16BitWords {
sum: u32_16bit_word::add_slice(self.sum, slice),
Expand All @@ -40,7 +40,7 @@ impl Sum16BitWords {

/// Add a 2 byte word.
#[inline]
#[cfg(target_pointer_width = "32")]
#[cfg(any(target_pointer_width = "16", target_pointer_width = "32"))]
pub fn add_2bytes(self, value: [u8; 2]) -> Sum16BitWords {
Sum16BitWords {
sum: u32_16bit_word::add_2bytes(self.sum, value),
Expand All @@ -58,7 +58,7 @@ impl Sum16BitWords {

/// Add a 4 byte word.
#[inline]
#[cfg(target_pointer_width = "32")]
#[cfg(any(target_pointer_width = "16", target_pointer_width = "32"))]
pub fn add_4bytes(&mut self, value: [u8; 4]) -> Sum16BitWords {
Sum16BitWords {
sum: u32_16bit_word::add_4bytes(self.sum, value),
Expand All @@ -76,7 +76,7 @@ impl Sum16BitWords {

/// Add a 8 byte word.
#[inline]
#[cfg(target_pointer_width = "32")]
#[cfg(any(target_pointer_width = "16", target_pointer_width = "32"))]
pub fn add_8bytes(&mut self, value: [u8; 8]) -> Sum16BitWords {
self.add_4bytes([value[0], value[1], value[2], value[3]])
.add_4bytes([value[4], value[5], value[6], value[7]])
Expand Down Expand Up @@ -105,7 +105,7 @@ impl Sum16BitWords {
/// Converts summed up words from an u32 to an u16 ones complement
/// which can be used in a ipv4 checksum.
#[inline]
#[cfg(target_pointer_width = "32")]
#[cfg(any(target_pointer_width = "16", target_pointer_width = "32"))]
pub fn ones_complement(&self) -> u16 {
u32_16bit_word::ones_complement(self.sum)
}
Expand All @@ -123,7 +123,7 @@ impl Sum16BitWords {
///
/// This kind of checksum is used in TCP and UDP headers.
#[inline]
#[cfg(target_pointer_width = "32")]
#[cfg(any(target_pointer_width = "16", target_pointer_width = "32"))]
pub fn to_ones_complement_with_no_zero(&self) -> u16 {
u32_16bit_word::ones_complement_with_no_zero(self.sum)
}
Expand Down
1 change: 1 addition & 0 deletions etherparse/src/err/ip/header_error.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#[cfg(feature = "std")]
use crate::*;

/// Error when decoding the IP header part of a message.
Expand Down
1 change: 1 addition & 0 deletions etherparse/src/err/ip/headers_write_error.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#[cfg(feature = "std")]
use crate::err::{ipv4_exts, ipv6_exts};

/// Error when writing IPv4 extension headers.
Expand Down
2 changes: 2 additions & 0 deletions etherparse/src/err/ip/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ pub use headers_read_error::*;
mod headers_slice_error;
pub use headers_slice_error::*;

#[cfg(feature = "std")]
mod headers_write_error;
#[cfg(feature = "std")]
pub use headers_write_error::*;

mod lax_header_slice_error;
Expand Down
1 change: 1 addition & 0 deletions etherparse/src/err/ipv4_exts/header_write_error.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#[cfg(feature = "std")]
use super::ExtsWalkError;

/// Error when writing IPv4 extension headers.
Expand Down
2 changes: 2 additions & 0 deletions etherparse/src/err/ipv4_exts/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
mod exts_walk_error;
pub use exts_walk_error::*;

#[cfg(feature = "std")]
mod header_write_error;
#[cfg(feature = "std")]
pub use header_write_error::*;
1 change: 1 addition & 0 deletions etherparse/src/err/ipv6_exts/header_write_error.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#[cfg(feature = "std")]
use super::ExtsWalkError;

/// Error when writing IPv6 extension headers.
Expand Down
2 changes: 2 additions & 0 deletions etherparse/src/err/ipv6_exts/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,7 @@ pub use exts_walk_error::*;
mod header_slice_error;
pub use header_slice_error::*;

#[cfg(feature = "std")]
mod header_write_error;
#[cfg(feature = "std")]
pub use header_write_error::*;
1 change: 1 addition & 0 deletions etherparse/src/err/packet/build_write_error.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#[cfg(feature = "std")]
use crate::err::{ipv4_exts, ipv6_exts, ValueTooBigError};

/// Error while writing packet
Expand Down
2 changes: 2 additions & 0 deletions etherparse/src/err/packet/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#[cfg(feature = "std")]
mod build_write_error;
#[cfg(feature = "std")]
pub use build_write_error::*;

mod slice_error;
Expand Down
1 change: 1 addition & 0 deletions etherparse/src/link/ethernet2_header_slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ impl<'a> Ethernet2HeaderSlice<'a> {
/// The caller must ensured that the given slice has the length of
/// [`Ethernet2Header::LEN`]
#[inline]
#[cfg(feature = "std")]
pub(crate) unsafe fn from_slice_unchecked(slice: &[u8]) -> Ethernet2HeaderSlice {
debug_assert!(slice.len() == Ethernet2Header::LEN);
Ethernet2HeaderSlice { slice }
Expand Down
2 changes: 1 addition & 1 deletion etherparse/src/payload_slice.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{link::ether_payload_slice::EtherPayloadSlice, *};
use crate::*;

/// Payload together with an identifier the type of content.
#[derive(Debug, Clone, Eq, PartialEq, Hash, PartialOrd, Ord)]
Expand Down
1 change: 0 additions & 1 deletion etherparse/src/transport/tcp_slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,6 @@ impl<'a> TcpSlice<'a> {

/// Calculates the checksum for the current header in ipv6 mode and
/// returns the result. This does NOT set the checksum.
#[cfg(any(target_pointer_width = "32", target_pointer_width = "64"))]
pub fn calc_checksum_ipv6(
&self,
source: [u8; 16],
Expand Down

0 comments on commit 4deb644

Please sign in to comment.