IpPacket

Struct IpPacket 

Source
pub struct IpPacket {
Show 13 fields pub dscp: u8, pub ecn: u8, pub len: usize, pub id: u16, pub flags: u8, pub frag_off: u16, pub ttl: u8, pub checksum: u16, pub source: Ipv4Addr, pub dest: Ipv4Addr, pub options: Option<Vec<u8>>, pub payload: DataType, pub recv_time: SystemTime,
}
Expand description

IP header and its associated TCP data

Fields§

§dscp: u8

Differentiated Services Code Point

This field is mainly used for real time protocols to determine what kind of data is in the packet. Should be left alone.

§ecn: u8

Explicit Congestion Notification

Used to indicate network congestion without having to drop packets.

§len: usize

Total Length

Length of the IP packet and associated data. Minimum size of 20 bytes for the header. This field is encoded as a u16 so it has a maximum value of 65535.

§id: u16

Identification

Primarily used for identifying a group of fragments.

§flags: u8

Flags

A bit field used for controllig and identifying a fragmented IP packet.

§frag_off: u16

Fragment Offset

Specifies the offset of a fragment with respect to the beginning of the fragment. Units are 64 bits.

§ttl: u8

Time to Live

Originally specified the time to live for a packet in seconds. It is now generally used as a hop count.

§checksum: u16

Header Checksum

Checksum over the header of the IP packet.

§source: Ipv4Addr

Source Address

The IP address from which this packet was sent.

§dest: Ipv4Addr

Destination Address

The IP address where this packet is being sent to.

§options: Option<Vec<u8>>

IP options

Any options the IP header may have. This field will only contain a vector if the IHL field is in the range [6, 15].

§payload: DataType

Encapsulated data

The payload can be any of the supported types in the DataType enum

§recv_time: SystemTime

Time packet received at

This field is populated at the time the packet was parsed at and may not perfectly reflect the time at which the packet was actually received on the interface.

Implementations§

Source§

impl IpPacket

Source

pub fn parse_from_bytes( data: &dyn AsRef<[u8]>, time: Option<SystemTime>, ) -> Result<Self, IpParseErr>

Parse an ip header and TCP packet out of a stream of bytes

This method is meant to be called with data read from the raw socket. It will read out any IPv4 TCP packet and parse the containing data.

§Errors

Returns an error if an unsupported packet type is passed in. Those cases are an IPv6 packet, non-TCP packet, or a slice smaller than 20 bytes.

§Panics

This method may panic. If the system time is before the SystemTime::UNIX_EPOCH time, then a panic will occur.

Source

pub fn pcap_write<W: Write>(&self, file: &mut W) -> Result<()>

Write an IP packet to a pcap file

§Errors

Returns an error if any of the writes fail.

Trait Implementations§

Source§

impl Debug for IpPacket

Source§

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

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

impl Display for IpPacket

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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> 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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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.