Skip to main content

Module ip

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§

InternetChecksum
Incremental Internet checksum (RFC 1071).
IpFragment
Fragment metadata. offset is measured in bytes, not wire units of eight.
IpProtocol
An IP Protocol / IPv6 Next Header number (IANA Internet Protocol Numbers).
Ipv4Header
IPv4 header fields for packet construction. Options are supplied to Self::encode.
Ipv4Option
A borrowed IPv4 option. Single-byte padding options have empty data.
Ipv4Options
Iterator over the options of a validated IPv4 header.
Ipv4Packet
A validated IPv4 packet view. Trailing bytes after Total Length are excluded.
Ipv6Extension
A borrowed IPv6 extension header. Unknown option bytes are retained.
Ipv6Extensions
Iterator over a previously validated packet’s extension headers.
Ipv6Header
IPv6 base-header fields for construction; extension headers are supplied in the payload.
Ipv6Packet
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.
IpPacketError
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.