Module ip
Available on crate feature
net only.Expand description
Internet Protocol packets and metadata, independent of sockets and tunnels.
Checked packet views borrow their input; header types encode into caller-owned
buffers. Unknown protocol numbers are preserved. These primitives also work
without the std feature.
use rama_net::ip::{IpPacket, IpProtocol, Ipv4Header, decrement_hop_limit};
use core::net::Ipv4Addr;
let mut bytes = [0; 128];
let header = Ipv4Header::new(
Ipv4Addr::new(192, 0, 2, 1), Ipv4Addr::new(192, 0, 2, 2),
IpProtocol::new(253), // experimental protocol, preserved as-is
);
let n = header.encode(&[], b"payload", &mut bytes)?;
decrement_hop_limit(&mut bytes[..n])?;
let packet = IpPacket::parse(&bytes[..n])?;
assert_eq!(packet.hop_limit(), 63);
assert_eq!(packet.protocol(), Some(IpProtocol::new(253)));Modules§
- icmp
- ICMP forwarding errors without a socket or routing-table dependency.
Structs§
- Internet
Checksum - Incremental Internet checksum (RFC 1071).
- IpFragment
- Fragment metadata.
offsetis measured in bytes, not wire units of eight. - IpProtocol
- An IP Protocol / IPv6 Next Header number (IANA Internet Protocol Numbers).
- Ipv4
Header - IPv4 header fields for packet construction. Options are supplied to
Self::encode. - Ipv4
Option - A borrowed IPv4 option. Single-byte padding options have empty data.
- Ipv4
Options - Iterator over the options of a validated IPv4 header.
- Ipv4
Packet - A validated IPv4 packet view. Trailing bytes after Total Length are excluded.
- Ipv6
Extension - A borrowed IPv6 extension header. Unknown option bytes are retained.
- Ipv6
Extensions - Iterator over a previously validated packet’s extension headers.
- Ipv6
Header - IPv6 base-header fields for construction; extension headers are supplied in the payload.
- Ipv6
Packet - A validated IPv6 packet view, including a bounded extension-header walk.
Enums§
- EcnCodepoint
- Explicit Congestion Notification codepoint from the low two IP traffic-class bits.
- IpPacket
- A checked IP packet, independent of its link or tunnel protocol.
- IpPacket
Error - An invalid packet or an operation that cannot be represented on the wire.
Functions§
- decrement_
hop_ limit - Decrement a forwarded packet’s hop count once, updating the IPv4 checksum.
- internet_
checksum - Internet checksum of a contiguous byte string.
- set_
traffic_ class - Set DSCP/ECN bits, preserving the IPv6 flow label and repairing IPv4’s checksum. Invalid packets are left unchanged.