Module Ethernet.Packet

type protocol =
  1. | ARPv4
  2. | IPv4
  3. | IPv6
    (*

    The Ethernet protocol field (EtherType).

    *)
type t = {
  1. src : Macaddr.t;
  2. dst : Macaddr.t;
  3. protocol : protocol option;
}

A decoded Ethernet header. protocol is None if the EtherType is not recognized.

val decode : Bstr.t -> len:int -> (t * Slice_bstr.t, [> `Invalid_ethernet_packet ]) result

decode buf ~len decodes an Ethernet frame from the first len bytes of buf. Returns the header and a slice pointing to the payload (after the 14-byte Ethernet header).

val encode_into : t -> ?off:int -> Bstr.t -> unit

encode_into header ?off buf writes the Ethernet header into buf at offset off (defaults to 0). The caller must ensure buf has at least 14 bytes available from off.