IPv4EndpointOption

Struct IPv4EndpointOption 

Source
pub struct IPv4EndpointOption<T: AsRef<[u8]>> { /* private fields */ }
Expand description

Zero-copy wrapper around IPv4 Endpoint Option (12 bytes total: 4 header + 8 data).

IPv4 endpoint options convey IPv4 address, port, and transport protocol for service endpoints.

Wire format (12 bytes):

0               1               2               3
0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|           Length              |     Type      |D|  Reserved   |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                       IPv4 Address                            |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|    Reserved   |   Protocol    |             Port              |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

Implementations§

Source§

impl<T: AsRef<[u8]>> IPv4EndpointOption<T>

Source

pub const LENGTH: usize = 12usize

IPv4 endpoint option wire format size in bytes (4 header + 8 data).

Source

pub fn new_unchecked(buffer: T) -> Self

Create an IPv4EndpointOption without validation.

§Parameters
  • buffer - The buffer containing the 12-byte option
§Safety

This does not validate buffer length. Use new_checked for validation.

Source

pub fn new_checked(buffer: T) -> Result<Self>

Create an IPv4EndpointOption from a buffer with length validation.

§Parameters
  • buffer - The buffer containing the 12-byte option
§Returns
  • Ok(IPv4EndpointOption) if buffer is at least 12 bytes
  • Err(Error) if buffer is too short
Source

pub fn check_len(&self) -> Result<()>

Validate that the buffer is at least 12 bytes long.

§Returns
  • Ok(()) if buffer meets minimum length requirement
  • Err(Error) if buffer is too short
Source

pub fn header(&self) -> OptionHeader<&[u8]>

Get a view of the option header (first 4 bytes).

§Returns

OptionHeader wrapper around the header bytes

Source

pub fn ipv4_address(&self) -> [u8; 4]

Get the IPv4 address (4 bytes at offset 4-7).

§Returns

The IPv4 address as a 4-byte array in network byte order

Source

pub fn transport_protocol(&self) -> u8

Get the transport protocol (1 byte at offset 9).

§Returns

Protocol value (0x06=TCP, 0x11=UDP)

Source

pub fn check_protocol(&self) -> Result<()>

Validate the transport protocol field.

§Returns
  • Ok(()) if protocol is TCP (0x06) or UDP (0x11)
  • Err(Error::InvalidProtocol) if protocol is unknown
Source

pub fn port(&self) -> u16

Get the port number (2 bytes at offset 10-11, network byte order).

§Returns

The port number

Source§

impl<T: AsRef<[u8]> + AsMut<[u8]>> IPv4EndpointOption<T>

Source

pub fn set_ipv4_address(&mut self, addr: [u8; 4])

Set the IPv4 address (4 bytes at offset 4-7).

§Parameters
  • addr - The IPv4 address as a 4-byte array in network byte order
Source

pub fn set_transport_protocol(&mut self, proto: u8)

Set the transport protocol (1 byte at offset 9).

§Parameters
  • proto - Protocol value (0x06=TCP, 0x11=UDP)
Source

pub fn set_port(&mut self, port: u16)

Set the port number (2 bytes at offset 10-11, network byte order).

§Parameters
  • port - The port number

Trait Implementations§

Source§

impl<T: Clone + AsRef<[u8]>> Clone for IPv4EndpointOption<T>

Source§

fn clone(&self) -> IPv4EndpointOption<T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug + AsRef<[u8]>> Debug for IPv4EndpointOption<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: Copy + AsRef<[u8]>> Copy for IPv4EndpointOption<T>

Auto Trait Implementations§

§

impl<T> Freeze for IPv4EndpointOption<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for IPv4EndpointOption<T>
where T: RefUnwindSafe,

§

impl<T> Send for IPv4EndpointOption<T>
where T: Send,

§

impl<T> Sync for IPv4EndpointOption<T>
where T: Sync,

§

impl<T> Unpin for IPv4EndpointOption<T>
where T: Unpin,

§

impl<T> UnwindSafe for IPv4EndpointOption<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.