Module smoltcp::wire [] [src]

Low-level packet access and construction.

The wire module deals with the packet representation. It provides two levels of functionality.

  • First, it provides functions to extract fields from sequences of octets, and to insert fields into sequences of octets. This happens through the Frame and Packet families of structures, e.g. EthernetPacket.
  • Second, in cases where the space of valid field values is much smaller than the space of possible field values, it provides a compact, high-level representation of packet data that can be parsed from and emitted into a sequence of octets. This happens through the Repr family of enums, e.g. ArpRepr.

The functions in the wire module are designed for robustness and use together with -Cpanic=abort. The accessor and parsing functions never panic. The setter and emission functions only panic if the underlying buffer is too small.

The Frame and Packet families of data structures in the wire module do not perform validation of received data except as needed to access the contents without panicking; the Repr family does.

Examples

To emit an IP packet header into an octet buffer, and then parse it back:

use smoltcp::wire::*;
let repr = Ipv4Repr {
    src_addr:    Ipv4Address::new(10, 0, 0, 1),
    dst_addr:    Ipv4Address::new(10, 0, 0, 2),
    protocol:    IpProtocol::Tcp,
    payload_len: 10
};
let mut buffer = vec![0; repr.buffer_len() + 10];
{ // emission
    let mut packet = Ipv4Packet::new(&mut buffer).unwrap();
    repr.emit(&mut packet);
}
{ // parsing
    let packet = Ipv4Packet::new(&buffer).unwrap();
    let parsed = Ipv4Repr::parse(&packet).unwrap();
    assert_eq!(repr, parsed);
}

Reexports

pub use self::pretty_print::PrettyPrinter;

Modules

pretty_print

Pretty-printing of packet representation.

Structs

ArpPacket

A read/write wrapper around an Address Resolution Protocol packet buffer.

EthernetAddress

A six-octet Ethernet II address.

EthernetFrame

A read/write wrapper around an Ethernet II frame buffer.

Icmpv4Packet

A read/write wrapper around an Internet Control Message Protocol version 4 packet buffer.

IpEndpoint

An internet endpoint address.

Ipv4Address

A four-octet IPv4 address.

Ipv4Packet

A read/write wrapper around an Internet Protocol version 4 packet buffer.

Ipv4Repr

A high-level representation of an Internet Protocol version 4 packet header.

TcpPacket

A read/write wrapper around an Transmission Control Protocol packet buffer.

TcpRepr

A high-level representation of a Transmission Control Protocol packet.

TcpSeqNumber

A TCP sequence number.

UdpPacket

A read/write wrapper around an User Datagram Protocol packet buffer.

UdpRepr

A high-level representation of an User Datagram Protocol packet.

Enums

ArpHardware

ARP hardware type.

ArpOperation

ARP operation type.

ArpRepr

A high-level representation of an Address Resolution Protocol packet.

EthernetProtocol

Ethernet protocol type.

Icmpv4DstUnreachable

Internet protocol control message subtype for type "Destination Unreachable".

Icmpv4Message

Internet protocol control message type.

Icmpv4ParamProblem

Internet protocol control message subtype for type "Parameter Problem".

Icmpv4Redirect

Internet protocol control message subtype for type "Redirect Message".

Icmpv4Repr

A high-level representation of an Internet Control Message Protocol version 4 packet header.

Icmpv4TimeExceeded

Internet protocol control message subtype for type "Time Exceeded".

IpAddress

An internetworking address.

IpProtocol

Internetworking protocol.

IpRepr

An IP packet representation.

TcpControl

The control flags of a Transmission Control Protocol packet.