Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions etherparse/src/transport/icmpv6/icmpv6_payload/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,7 @@ impl Icmpv6Payload {
/// Write the fixed payload bytes to the writer.
#[cfg(feature = "std")]
#[cfg_attr(docsrs, doc(cfg(feature = "std")))]
pub fn write<T: std::io::Write + Sized>(
&self,
writer: &mut T,
) -> Result<(), std::io::Error> {
pub fn write<T: std::io::Write + Sized>(&self, writer: &mut T) -> Result<(), std::io::Error> {
match self {
Icmpv6Payload::RouterSolicitation(value) => writer.write_all(&value.to_bytes()),
Icmpv6Payload::RouterAdvertisement(value) => writer.write_all(&value.to_bytes()),
Expand All @@ -62,7 +59,6 @@ impl Icmpv6Payload {
#[cfg(test)]
mod tests {
use super::*;
use alloc::format;
use proptest::prelude::*;

#[test]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
use crate::{err, LaxIpSlice};

/// Borrowed payload of a Destination Unreachable message (RFC 4443, Section 3.1).
///
/// The full packet layout is:
/// ```text
/// 0 1 2 3
/// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
/// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
/// | Type | Code | Checksum |
/// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
/// | Unused |
/// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
/// | As much of invoking packet |
/// + as possible without the ICMPv6 packet +
/// | exceeding the minimum IPv6 MTU [IPv6] |
/// ```
///
/// In this crate, `Type`, `Code`, and `Unused` are represented by
/// [`crate::Icmpv6Type::DestinationUnreachable`]. This slice represents the
/// invoking packet bytes after that fixed part.
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct DestinationUnreachablePayloadSlice<'a> {
slice: &'a [u8],
}

impl<'a> DestinationUnreachablePayloadSlice<'a> {
/// Creates a payload slice from the bytes after the ICMPv6 header.
pub fn from_slice(slice: &'a [u8]) -> Result<Self, err::LenError> {
Ok(Self { slice })
}

/// Returns the full payload slice.
pub fn slice(&self) -> &'a [u8] {
self.slice
}

/// Returns the invoking packet bytes carried by the message.
pub fn invoking_packet(&self) -> &'a [u8] {
self.slice
}

/// Decodes the invoking packet bytes as a lax IP slice.
pub fn as_lax_ip_slice(
&self,
) -> Result<
(
LaxIpSlice<'a>,
Option<(err::ipv6_exts::HeaderSliceError, err::Layer)>,
),
err::ip::LaxHeaderSliceError,
> {
LaxIpSlice::from_slice(self.invoking_packet())
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
use crate::err;

/// Borrowed payload of an Echo Reply message (RFC 4443, Section 4.2).
///
/// The full packet layout is:
/// ```text
/// 0 1 2 3
/// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
/// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
/// | Type | Code | Checksum |
/// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
/// | Identifier | Sequence Number |
/// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
/// | Data ...
/// +-+-+-+-+-+-+-+-+-
/// ```
///
/// In this crate, `Type`, `Code`, `Identifier`, and `Sequence Number` are
/// represented by [`crate::Icmpv6Type::EchoReply`]. This slice represents
/// the echoed data after that fixed part.
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct EchoReplyPayloadSlice<'a> {
slice: &'a [u8],
}

impl<'a> EchoReplyPayloadSlice<'a> {
/// Creates a payload slice from the bytes after the ICMPv6 header.
pub fn from_slice(slice: &'a [u8]) -> Result<Self, err::LenError> {
Ok(Self { slice })
}

/// Returns the full payload slice.
pub fn slice(&self) -> &'a [u8] {
self.slice
}

/// Returns the echoed data bytes.
pub fn data(&self) -> &'a [u8] {
self.slice
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
use crate::err;

/// Borrowed payload of an Echo Request message (RFC 4443, Section 4.1).
///
/// The full packet layout is:
/// ```text
/// 0 1 2 3
/// 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
/// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
/// | Type | Code | Checksum |
/// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
/// | Identifier | Sequence Number |
/// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
/// | Data ...
/// +-+-+-+-+-+-+-+-+-
/// ```
///
/// In this crate, `Type`, `Code`, `Identifier`, and `Sequence Number` are
/// represented by [`crate::Icmpv6Type::EchoRequest`]. This slice represents
/// the echoed data after that fixed part.
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct EchoRequestPayloadSlice<'a> {
slice: &'a [u8],
}

impl<'a> EchoRequestPayloadSlice<'a> {
/// Creates a payload slice from the bytes after the ICMPv6 header.
pub fn from_slice(slice: &'a [u8]) -> Result<Self, err::LenError> {
Ok(Self { slice })
}

/// Returns the full payload slice.
pub fn slice(&self) -> &'a [u8] {
self.slice
}

/// Returns the echoed data bytes.
pub fn data(&self) -> &'a [u8] {
self.slice
}
}
Loading
Loading