pub enum IpRepr {
Ipv4(Ipv4Repr),
Ipv6(Ipv6Repr),
}Expand description
An IP packet representation.
This enum abstracts the various versions of IP packets. It either contains an IPv4 or IPv6 concrete high-level representation.
Variants§
Implementations§
Source§impl Repr
impl Repr
Sourcepub fn new(
src_addr: Address,
dst_addr: Address,
next_header: Protocol,
payload_len: usize,
hop_limit: u8,
) -> Self
pub fn new( src_addr: Address, dst_addr: Address, next_header: Protocol, payload_len: usize, hop_limit: u8, ) -> Self
Create a new IpRepr, choosing the right IP version for the src/dst addrs.
§Panics
Panics if src_addr and dst_addr are different IP version.
Sourcepub fn parse<T: AsRef<[u8]> + ?Sized>(
packet: &Packet<&T>,
checksum_caps: &ChecksumCapabilities,
) -> Result<Repr>
pub fn parse<T: AsRef<[u8]> + ?Sized>( packet: &Packet<&T>, checksum_caps: &ChecksumCapabilities, ) -> Result<Repr>
Parse an Internet Protocol packet and return an [IpRepr] containing either an Internet
Protocol version 4 or Internet Protocol version 6 packet. Delegates the parsing to the
specific Internet Protocol parsing function. Includes ChecksumCapabilities to handle
Internet Protocol version 4 parsing.
Returns Err(Error) if the packet does not include a valid IPv4 or IPv6 packet, or if the
specific Internet Protocol version feature is not enabled for the supplied packet
Sourcepub const fn next_header(&self) -> Protocol
pub const fn next_header(&self) -> Protocol
Return the next header (protocol).
Sourcepub const fn payload_len(&self) -> usize
pub const fn payload_len(&self) -> usize
Return the payload length.
Sourcepub fn set_payload_len(&mut self, length: usize)
pub fn set_payload_len(&mut self, length: usize)
Set the payload length.
Sourcepub const fn header_len(&self) -> usize
pub const fn header_len(&self) -> usize
Return the length of a header that will be emitted from this high-level representation.
Sourcepub fn emit<T: AsRef<[u8]> + AsMut<[u8]>>(
&self,
buffer: T,
_checksum_caps: &ChecksumCapabilities,
)
pub fn emit<T: AsRef<[u8]> + AsMut<[u8]>>( &self, buffer: T, _checksum_caps: &ChecksumCapabilities, )
Emit this high-level representation into a buffer.
Sourcepub const fn buffer_len(&self) -> usize
pub const fn buffer_len(&self) -> usize
Return the total length of a packet that will be emitted from this high-level representation.
This is the same as repr.buffer_len() + repr.payload_len().