CoolrfulDARkness/moonsctp/packet does not have a README file

    PacketError

    pub suberror PacketError {
    TooShort(Int)
    BadChecksum(UInt, UInt)
    InvalidChunkLength(Int)
    TruncatedChunk
    InvalidParameter(String)
    UnknownCriticalChunk(Byte)
    InvalidFlags(Byte)
    ProtocolViolation(String)
    } derive(Eq,
    Debug
    )

    Chunk

    pub(all) enum Chunk {
    Data(DataChunk)
    Init(InitChunk)
    InitAck(InitAckChunk)
    Sack(SackChunk)
    Heartbeat(Bytes)
    HeartbeatAck(Bytes)
    Abort(Bool, Array[ErrorCause])
    Shutdown(UInt)
    ShutdownAck
    Error(Array[ErrorCause])
    CookieEcho(Bytes)
    CookieAck
    ShutdownComplete(Bool)
    ForwardTsn(ForwardTsnChunk)
    } derive(Eq,
    Debug
    )

    All 14 RFC 9260 + RFC 3758 SCTP chunk types.

    DataChunk

    pub(all) struct DataChunk {
    tsn : UInt
    stream_id : UInt
    stream_seq : UInt
    ppid : UInt
    unordered : Bool
    beginning : Bool
    ending : Bool
    payload : Bytes
    } derive(Eq,
    Debug
    )

    ErrorCause

    pub(all) struct ErrorCause {
    code : UInt
    info : Bytes
    } derive(Eq,
    Debug
    )

    ForwardTsnChunk

    pub(all) struct ForwardTsnChunk {
    new_cum_tsn : UInt
    streams : Array[ForwardTsnStream]
    } derive(Eq,
    Debug
    )

    ForwardTsnStream

    pub(all) struct ForwardTsnStream {
    stream_id : UInt
    stream_seq : UInt
    } derive(Eq,
    Debug
    )

    GapAckBlock

    pub(all) struct GapAckBlock {
    start : UInt
    end : UInt
    } derive(Eq,
    Debug
    )

    InitAckChunk

    pub(all) struct InitAckChunk {
    initiate_tag : UInt
    a_rwnd : UInt
    num_outbound_streams : UInt
    num_inbound_streams : UInt
    initial_tsn : UInt
    state_cookie : Bytes
    forward_tsn_supported : Bool
    } derive(Eq,
    Debug
    )

    InitChunk

    pub(all) struct InitChunk {
    initiate_tag : UInt
    a_rwnd : UInt
    num_outbound_streams : UInt
    num_inbound_streams : UInt
    initial_tsn : UInt
    forward_tsn_supported : Bool
    } derive(Eq,
    Debug
    )

    Packet

    pub(all) struct Packet {
    src_port : UInt
    dst_port : UInt
    verification_tag : UInt
    chunks : Array[Chunk]
    } derive(Eq,
    Debug
    )

    Decoded RFC 9260 SCTP Packet.

    SackChunk

    pub(all) struct SackChunk {
    cum_tsn_ack : UInt
    a_rwnd : UInt
    gap_blocks : Array[GapAckBlock]
    dup_tsns : Array[UInt]
    } derive(Eq,
    Debug
    )

    CHUNK_ABORT

    let CHUNK_ABORT : Byte

    let CHUNK_COOKIE_ACK : Byte

    let CHUNK_COOKIE_ECHO : Byte

    CHUNK_DATA

    let CHUNK_DATA : Byte

    CHUNK_ERROR

    let CHUNK_ERROR : Byte

    CHUNK_FORWARD_TSN

    let CHUNK_FORWARD_TSN : Byte

    RFC 3758 §3.2 PR-SCTP FORWARD-TSN Chunk Type (192 = 0xC0).

    CHUNK_HEARTBEAT

    let CHUNK_HEARTBEAT : Byte

    CHUNK_HEARTBEAT_ACK

    let CHUNK_HEARTBEAT_ACK : Byte

    CHUNK_INIT

    let CHUNK_INIT : Byte

    CHUNK_INIT_ACK

    let CHUNK_INIT_ACK : Byte

    CHUNK_SACK

    let CHUNK_SACK : Byte

    CHUNK_SHUTDOWN

    let CHUNK_SHUTDOWN : Byte

    CHUNK_SHUTDOWN_ACK

    let CHUNK_SHUTDOWN_ACK : Byte

    CHUNK_SHUTDOWN_COMPLETE

    let CHUNK_SHUTDOWN_COMPLETE : Byte

    COMMON_HEADER_LEN

    let COMMON_HEADER_LEN : Int

    FLAG_DATA_B

    let FLAG_DATA_B : Byte

    FLAG_DATA_E

    let FLAG_DATA_E : Byte

    FLAG_DATA_I

    let FLAG_DATA_I : Byte

    FLAG_DATA_U

    let FLAG_DATA_U : Byte

    decode_packet

    fn decode_packet(raw : BytesView) -> Packet raise PacketError

    Decodes and validates a wire SCTP packet:
    • Rejects packets < 12 bytes with TooShort
    • Verifies little-endian Castagnoli CRC-32C (BadChecksum(expected, actual))
    • Parses all bundled chunks with strict length/boundary validation and RFC 9260 §3.2 top-2-bit unknown chunk handling.

    encode_packet

    fn encode_packet(pkt : Packet) -> Bytes raise PacketError

    Serializes an SCTP Packet into wire bytes: 12-byte common header (src_port, dst_port, verification_tag, little-endian Castagnoli CRC-32C) followed by 4-byte aligned bundled chunks.

    ssn_inc

    fn ssn_inc(a : UInt) -> UInt

    Increments a 16-bit SSN with modular wraparound (0xFFFF -> 0x0000).

    ssn_le

    fn ssn_le(a : UInt, b : UInt) -> Bool

    RFC 1982 less-than-or-equal comparison for 16-bit SSNs.

    ssn_lt

    fn ssn_lt(a : UInt, b : UInt) -> Bool

    RFC 1982 §3.2 strict less-than comparison for 16-bit Stream Sequence Numbers (SSNs).

    tsn_diff

    fn tsn_diff(a : UInt, b : UInt) -> Int

    Signed modular difference a - b in 32-bit TSN space (positive if a > b, negative if a < b, handling 0xFFFFFFFF -> 0x00000000 wraparound).

    tsn_ge

    fn tsn_ge(a : UInt, b : UInt) -> Bool

    RFC 1982 greater-than-or-equal comparison for 32-bit TSNs.

    tsn_gt

    fn tsn_gt(a : UInt, b : UInt) -> Bool

    RFC 1982 strict greater-than comparison for 32-bit TSNs.

    tsn_le

    fn tsn_le(a : UInt, b : UInt) -> Bool

    RFC 1982 less-than-or-equal comparison for 32-bit TSNs.

    tsn_lt

    fn tsn_lt(a : UInt, b : UInt) -> Bool

    RFC 1982 §3.2 strict less-than comparison for 32-bit TSNs. Returns false when a == b or when a and b differ by exactly 2^31.