netpkt/icmp.rs#
Source: lib/netpkt/icmp.rs
icmp -- ICMP for IPv4 (RFC 792, 1191, 1812)
IcmpView::parse(b) type, code, checksum, the 4 bytes after it, payload
Icmp EchoRequest / EchoReply { id, seq }, Unreachable { code, mtu },
TimeExceeded { code }, Redirect { code, gateway }, ParamProblem,
Other; encode(payload) with checksum, push_onto(&mut Pkt)
error_quote(packet) what an error message quotes of the offending packet: its header and
the first 8 bytes of its payload
name(type, code) "Echo (ping) request", "Destination unreachable (Port unreachable)", ...
ICMP_HDR: usize = 8
T_ECHO_REPLY: u8 = 0
T_UNREACH: u8 = 3
T_REDIRECT: u8 = 5
T_ECHO_REQUEST: u8 = 8
T_TIME_EXCEEDED: u8 = 11
T_PARAM_PROBLEM: u8 = 12
UNREACH_NET: u8 = 0
UNREACH_HOST: u8 = 1
UNREACH_PROTO: u8 = 2
UNREACH_PORT: u8 = 3
UNREACH_FRAG_NEEDED: u8 = 4
UNREACH_ADMIN: u8 = 13
EXCEEDED_TTL: u8 = 0
EXCEEDED_REASSEMBLY: u8 = 1
struct IcmpView<'a>a received ICMP message
impl<'a> IcmpView<'a>
fn parse(b: &'a [u8]) -> Option<IcmpView<'a>>fn typ(&self) -> u8fn code(&self) -> u8fn checksum(&self) -> u16fn checksum_ok(&self) -> boolfn rest(&self) -> [u8; 4]the 4 bytes after the checksumfn id(&self) -> u16fn seq(&self) -> u16fn payload(&self) -> &'a [u8]fn quoted(&self) -> Option<Ipv4View<'a>>the quoted packet of an error message (unreachable, time exceeded, redirect, ...)fn is_error(&self) -> boolfn error_quote(packet: &[u8]) -> &[u8]the header and the first 8 payload bytes of the offending packet (what an ICMP error quotes)enum Icmpan ICMP message to writeEchoRequest { id: u16, seq: u16 }EchoReply { id: u16, seq: u16 }Unreachable { code: u8, mtu: u16 }-- destination unreachable;mtuis the next-hop MTU of code 4 (RFC 1191), else 0TimeExceeded { code: u8 }Redirect { code: u8, gateway: Ipv4 }ParamProblem { pointer: u8 }Other { typ: u8, code: u8, rest: [u8; 4] }
impl Icmp
fn read(v: &IcmpView) -> Icmpfn type_code(&self) -> (u8, u8)fn encode(&self, payload: &[u8]) -> Vec<u8>header + payload with the checksumfn push_onto(&self, p: &mut Pkt)prepends the header; the packet's current content is the payloadfn name(typ: u8, code: u8) -> &'static stra readable name of an ICMP type and code