Module Utcp.Segment

The module of TCP segments, as seen on the wire.

type tcp_option =
  1. | MaximumSegmentSize of int
  2. | WindowScale of int
  3. | Unknown of int * Cstruct.t

The variant type of supported TCP options

type t = {
  1. src_port : int;
  2. dst_port : int;
  3. seq : Sequence.t;
  4. ack : Sequence.t option;
  5. flag : [ `Syn | `Fin | `Rst ] option;
  6. push : bool;
  7. window : int;
  8. options : tcp_option list;
  9. payload : string list;
  10. payload_len : int;
}

The record type of the TCP segment

val pp : t Fmt.t

pp seg pretty-prints the segment seg.

val equal : t -> t -> bool

equal s1 s2 is true if s1 and s2 are equal (comparing all fields of the record).

val decode_and_validate : src:Ipaddr.t -> dst:Ipaddr.t -> Cstruct.t -> (t * flow, [ `Msg of string ]) result

decode_and_validate ~src ~dst data decodes data and validates its checksum. Some further checks are done: broadcast and multicast packets error, also packets to and from the same endpoint (equal IP address and equal port). If the result is Ok, it is a segment and the flow.

val length : t -> int

length seg computes the length in bytes of s.

val encode_and_checksum : Mtime.t -> src:Ipaddr.t -> dst:Ipaddr.t -> t -> Cstruct.t

encode_and_checksum now ~src ~dst seg encodes the segment seg into a buffer, and computes its checksum. The value now is only used for logging.

val encode_and_checksum_into : Mtime.t -> Cstruct.t -> src:Ipaddr.t -> dst:Ipaddr.t -> t -> unit

encode_and_checksum_into now buf ~src ~dst seg encodes the segment seg into the buffer buf, and computes its checksum. The value now is only used for logging.

val checksum : src:Ipaddr.t -> dst:Ipaddr.t -> Cstruct.t -> int

checksum ~src ~dst buf computes the checksum of buf.

val encode : t -> Cstruct.t

encode seg encodes the segment seg into a buffer.