packet_formats::ip

Trait IpPacket

Source
pub trait IpPacket<B: SplitByteSlice, I: IpExt>:
    Sized
    + Debug
    + ParsablePacket<B, (), Error = IpParseError<I>> {
    type Builder: IpPacketBuilder<I>;
    type VersionSpecificMeta;

    // Required methods
    fn src_ip(&self) -> I::Addr;
    fn dst_ip(&self) -> I::Addr;
    fn proto(&self) -> I::Proto;
    fn ttl(&self) -> u8;
    fn dscp_and_ecn(&self) -> DscpAndEcn;
    fn set_ttl(&mut self, ttl: u8)
       where B: SplitByteSliceMut;
    fn body(&self) -> &[u8] ;
    fn version_specific_meta(&self) -> Self::VersionSpecificMeta;
    fn as_ip_addr_ref(&self) -> IpAddr<&Ipv4Packet<B>, &Ipv6Packet<B>>;
    fn reassemble_fragmented_packet<BV: BufferViewMut<B>, IT: Iterator<Item = Vec<u8>>>(
        buffer: BV,
        header: Vec<u8>,
        body_fragments: IT,
    ) -> IpParseResult<I, ()>
       where B: SplitByteSliceMut;
    fn to_vec(&self) -> Vec<u8>;

    // Provided method
    fn into_metadata(self) -> (I::Addr, I::Addr, I::Proto, ParseMetadata) { ... }
}
Expand description

An IPv4 or IPv6 packet.

IpPacket is implemented by Ipv4Packet and Ipv6Packet.

Required Associated Types§

Source

type Builder: IpPacketBuilder<I>

A builder for this packet type.

Source

type VersionSpecificMeta

Metadata which is only present in the packet format of a specific version of the IP protocol.

Required Methods§

Source

fn src_ip(&self) -> I::Addr

The source IP address.

Source

fn dst_ip(&self) -> I::Addr

The destination IP address.

Source

fn proto(&self) -> I::Proto

The protocol number.

Source

fn ttl(&self) -> u8

The Time to Live (TTL) (IPv4) or Hop Limit (IPv6) field.

Source

fn dscp_and_ecn(&self) -> DscpAndEcn

The Differentiated Services Code Point (DSCP) and the Explicit Congestion Notification (ECN).

Source

fn set_ttl(&mut self, ttl: u8)
where B: SplitByteSliceMut,

Set the Time to Live (TTL) (IPv4) or Hop Limit (IPv6) field.

set_ttl updates the packet’s TTL/Hop Limit in place.

Source

fn body(&self) -> &[u8]

Get the body.

Source

fn version_specific_meta(&self) -> Self::VersionSpecificMeta

Gets packet metadata relevant only for this version of the IP protocol.

Source

fn as_ip_addr_ref(&self) -> IpAddr<&Ipv4Packet<B>, &Ipv6Packet<B>>

Converts a packet reference into a dynamically-typed reference.

Source

fn reassemble_fragmented_packet<BV: BufferViewMut<B>, IT: Iterator<Item = Vec<u8>>>( buffer: BV, header: Vec<u8>, body_fragments: IT, ) -> IpParseResult<I, ()>
where B: SplitByteSliceMut,

Reassembles a fragmented packet into a parsed IP packet.

Source

fn to_vec(&self) -> Vec<u8>

Copies the full packet into a Vec.

Provided Methods§

Source

fn into_metadata(self) -> (I::Addr, I::Addr, I::Proto, ParseMetadata)

Consume the packet and return some metadata.

Consume the packet and return the source address, destination address, protocol, and ParseMetadata.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§