tcpHandler looks rounded off, add to example

This commit is contained in:
soypat
2025-02-10 20:26:02 -03:00
parent 64a7102064
commit 0cb43c47a4
10 changed files with 184 additions and 137 deletions
+14
View File
@@ -148,6 +148,20 @@ func (tfrm Frame) Segment(payloadSize int) Segment {
}
}
// SetSegment sets the sequence, acknowledgment, offset, window and flag fields of the TCP header from the the [Segment].
// Offset, like in [Frame.SetOffset], is expressed in words with minimum being 5.
func (tfrm Frame) SetSegment(seg Segment, offset uint8) {
if offset >= 1<<4 {
panic("tcp offset too large")
} else if seg.WND > math.MaxUint16 {
panic("tcp window overflow")
}
tfrm.SetSeq(seg.SEQ)
tfrm.SetAck(seg.ACK)
tfrm.SetOffsetAndFlags(offset, seg.Flags)
tfrm.SetWindowSize(uint16(seg.WND))
}
// Options returns the TCP option buffer portion of the frame. The returned slice may be zero length.
// Be sure to call [Frame.ValidateSize] beforehand to avoid panic.
func (tfrm Frame) Options() []byte {