pub struct IpPacket {}Expand description
IP header and its associated TCP data
Fields§
§dscp: u8Differentiated 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: u8Explicit Congestion Notification
Used to indicate network congestion without having to drop packets.
len: usizeTotal 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: u16Identification
Primarily used for identifying a group of fragments.
flags: u8Flags
A bit field used for controllig and identifying a fragmented IP packet.
frag_off: u16Fragment Offset
Specifies the offset of a fragment with respect to the beginning of the fragment. Units are 64 bits.
ttl: u8Time to Live
Originally specified the time to live for a packet in seconds. It is now generally used as a hop count.
checksum: u16Header Checksum
Checksum over the header of the IP packet.
source: Ipv4AddrSource Address
The IP address from which this packet was sent.
dest: Ipv4AddrDestination 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: DataTypeEncapsulated data
The payload can be any of the supported types in the DataType enum
recv_time: SystemTimeTime 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
impl IpPacket
Sourcepub fn parse_from_bytes(
data: &dyn AsRef<[u8]>,
time: Option<SystemTime>,
) -> Result<Self, IpParseErr>
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.