Class: PacketGen::Header::SCTP::BaseChunk Abstract

Inherits:
Base
  • Object
show all
Includes:
Padded32
Defined in:
lib/packetgen/header/sctp/chunk.rb

Overview

This class is abstract.

Subclass and add more fields

Base SCTP chunk class, defining SCTP chunk common fields.

 0                   1                   2                   3
 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|  Chunk Type   |  Chunk Flags  |         Chunk Length          |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

Author:

  • Sylvain Daubert

Since:

  • 3.4.0

  • 4.1.0 Remove ErrorMixin and ParameterMixin

Constant Summary collapse

TYPES =

SCTP chunk types, as per RFC9260

Since:

  • 3.4.0

  • 4.1.0 Remove ErrorMixin and ParameterMixin

{
  'DATA' => 0,
  'INIT' => 1,
  'INIT_ACK' => 2,
  'SACK' => 3,
  'HEARTBEAT' => 4,
  'HEARTBEAT_ACK' => 5,
  'ABORT' => 6,
  'SHUTDOWN' => 7,
  'SHUTDOWN_ACK' => 8,
  'ERROR' => 9,
  'COOKIE_ECHO' => 10,
  'COOKIE_ACK' => 11,
  'SHUTDOWN_COMPLETE' => 14,
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Padded32

#padded?, #to_s

Methods inherited from Base

bind, calculate_and_set_length, #header_id, inherited, #initialize, #ip_header, #ll_header

Methods included from PacketGen::Headerable

#added_to_packet, included, #method_name, #packet, #packet=, #parse?, #protocol_name, #read, #to_s

Constructor Details

This class inherits a constructor from PacketGen::Header::Base

Instance Attribute Details

#lengthInteger

16-bit SCTP chunk length

Returns:

  • (Integer)


53
# File 'lib/packetgen/header/sctp/chunk.rb', line 53

define_attr :length, BinStruct::Int16

#typeInteger

8-bit SCTP chunk flags

Returns:

  • (Integer)


45
# File 'lib/packetgen/header/sctp/chunk.rb', line 45

define_attr :type, BinStruct::Int8Enum, enum: TYPES

Instance Method Details

#calc_lengthInteger

Calculate and set chunk #length

Returns:

  • (Integer)

Since:

  • 3.4.0

  • 4.1.0 Remove ErrorMixin and ParameterMixin



72
73
74
# File 'lib/packetgen/header/sctp/chunk.rb', line 72

def calc_length
  self.length = to_s(no_padding: true).size
end

#human_type::String, Integer

Get human-readable type

Returns:

  • (::String, Integer)

Since:

  • 3.4.0

  • 4.1.0 Remove ErrorMixin and ParameterMixin



66
67
68
# File 'lib/packetgen/header/sctp/chunk.rb', line 66

def human_type
  self[:type].to_human
end

#to_human::String

Get human-redable chunk

Returns:

  • (::String)

Since:

  • 3.4.0

  • 4.1.0 Remove ErrorMixin and ParameterMixin



57
58
59
60
61
62
# File 'lib/packetgen/header/sctp/chunk.rb', line 57

def to_human
  str = "<chunk:#{human_type}"
  flags_str = flags_to_human
  str << ",flags:#{flags_str}" unless flags_str.empty?
  str << '>'
end