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

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

Overview

This class is abstract.

Subclass and add more fields

BaseChunk 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

Constant Summary collapse

TYPES =

SCTP chunk types, as per RFC9260

Since:

  • 3.4.0

{
  '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

Methods inherited from Types::Fields

#[], #[]=, #bits_on, define_bit_fields_on, define_field, define_field_after, define_field_before, #fields, fields, inherited, #initialize, #inspect, #offset_of, #optional?, #optional_fields, #present?, #read, remove_bit_fields_on, remove_field, #sz, #to_h, #to_s, update_field

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_field :length, Types::Int16

#typeInteger

8-bit SCTP chunk flags

Returns:

  • (Integer)


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

define_field :type, Types::Int8Enum, enum: TYPES

Instance Method Details

#calc_lengthInteger

TODO:

do not count last parameter padding

Calculate and set chunk length

Returns:

  • (Integer)

Since:

  • 3.4.0



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

Returns:

  • (::String, Integer)

Since:

  • 3.4.0



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

def human_type
  self[:type].to_human
end

#to_human::String

Get human-redable chunk

Returns:

  • (::String)

Since:

  • 3.4.0



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