Crate trippy_packet

Crate trippy_packet 

Source
Expand description

Packet wire format parsing and building.

The following packet are supported:

  • ICMPv4
  • ICMPv6
  • IPv4
  • IPv6
  • UDP
  • TCP
  • ICMP extensions

§Endianness

The internal representation is held in network byte order (big-endian) and all accessor methods take and return data in host byte order, converting as necessary for the given architecture.

§Example

The following example parses an UDP packet and asserts its fields:

use trippy_packet::udp::UdpPacket;

let buf = hex_literal::hex!("68 bf 81 b6 00 40 ac be");
let packet = UdpPacket::new_view(&buf)?;
assert_eq!(26815, packet.get_source());
assert_eq!(33206, packet.get_destination());
assert_eq!(64, packet.get_length());
assert_eq!(44222, packet.get_checksum());
assert!(packet.payload().is_empty());

The following example builds an ICMPv4 echo request packet:

use trippy_packet::checksum::icmp_ipv4_checksum;
use trippy_packet::icmpv4::echo_request::EchoRequestPacket;
use trippy_packet::icmpv4::{IcmpCode, IcmpPacket, IcmpType};

let mut buf = [0; IcmpPacket::minimum_packet_size()];
let mut icmp = EchoRequestPacket::new(&mut buf)?;
icmp.set_icmp_type(IcmpType::EchoRequest);
icmp.set_icmp_code(IcmpCode(0));
icmp.set_identifier(1234);
icmp.set_sequence(10);
icmp.set_checksum(icmp_ipv4_checksum(icmp.packet()));
assert_eq!(icmp.packet(), &hex_literal::hex!("08 00 f3 23 04 d2 00 0a"));

Modules§

checksum
Functions for calculating network checksums. Checksum implementations for ICMP & UDP over IPv4 and IPV6.
error
Packet errors.
icmp_extension
ICMP extensions.
icmpv4
ICMPv4 packets.
icmpv6
ICMPv6 packets.
ipv4
IPv4 packets.
ipv6
IPv6 packets.
tcp
TCP packets.
udp
UDP packets.

Enums§

IpProtocol
The IP packet next layer protocol.

Functions§

fmt_payload
Format a payload as a hexadecimal string.