Module Arp_packetSource

Conversion between wire and high-level data

The high-level datatype can be decoded and encoded to bytes to be sent on the wire. ARP specifies hardware and protocol addresses, but this implementation picks Ethernet and IPv4 statically. While decoding can result in an error, encoding can not.

Sourcetype op =
  1. | Request
  2. | Reply
Sourceval op_to_int : op -> int
Sourceval int_to_op : int -> op option
Sourcetype t = {
  1. operation : op;
  2. source_mac : Macaddr.t;
  3. source_ip : Ipaddr.V4.t;
  4. target_mac : Macaddr.t;
  5. target_ip : Ipaddr.V4.t;
}

The high-level ARP frame consisting of the two address pairs and an operation.

Sourceval size : int

size is the size of an ARP frame.

Sourceval pp : Format.formatter -> t -> unit

pp ppf t prints the frame t on ppf.

Sourceval equal : t -> t -> bool

equal a b returns true if frames a and b are equal, false otherwise.

Sourcetype error =
  1. | Too_short
  2. | Unusable
  3. | Unknown_operation of Cstruct.uint16

The type of possible errors during decoding

  • Too_short if the provided buffer is not long enough
  • Unusable if the protocol or hardware address type is not IPv4 and Ethernet
  • Unknown_operation if it is neither a request nor a reply
Sourceval pp_error : Format.formatter -> error -> unit

pp_error ppf err prints the error err on ppf.

Decoding

Sourceval decode : Cstruct.t -> (t, error) result

decode buf attempts to decode the buffer into an ARP frame t.

Encoding

Sourceval encode : t -> Cstruct.t

encode t is a buf, a freshly allocated buffer, which contains the encoded ARP frame t.

Sourceval encode_into : t -> Cstruct.t -> unit

encode_into t buf encodes t into the buffer buf at offset 0.