Class: Mu::Pcap::SCTP::Chunk

Inherits:
Packet
  • Object
show all
Defined in:
lib/diy/parser/mu/pcap/sctp/chunk.rb,
lib/diy/parser/mu/pcap/sctp/chunk/data.rb,
lib/diy/parser/mu/pcap/sctp/chunk/init.rb,
lib/diy/parser/mu/pcap/sctp/chunk/init_ack.rb

Direct Known Subclasses

Data, Init

Defined Under Namespace

Classes: Data, Init, InitAck

Constant Summary

Constants inherited from Packet

Packet::IGNORE_UDP_PORTS

Instance Attribute Summary collapse

Attributes inherited from Packet

#payload, #payload_raw

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Packet

#==, #deepdup, #flow_id, isolate_l7, normalize, #payload_bytes, #to_bytes

Constructor Details

#initializeChunk

Returns a new instance of Chunk.



12
13
14
15
16
17
18
# File 'lib/diy/parser/mu/pcap/sctp/chunk.rb', line 12

def initialize
    super
    
    @type  = 0
    @flags = 0
    @size  = 0
end

Instance Attribute Details

#flagsObject

Returns the value of attribute flags.



10
11
12
# File 'lib/diy/parser/mu/pcap/sctp/chunk.rb', line 10

def flags
  @flags
end

#sizeObject

Returns the value of attribute size.



10
11
12
# File 'lib/diy/parser/mu/pcap/sctp/chunk.rb', line 10

def size
  @size
end

#typeObject

Returns the value of attribute type.



10
11
12
# File 'lib/diy/parser/mu/pcap/sctp/chunk.rb', line 10

def type
  @type
end

Class Method Details

.dummy_chunk(type, flags, size, bytes) ⇒ Object



102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/diy/parser/mu/pcap/sctp/chunk.rb', line 102

def self.dummy_chunk type, flags, size, bytes
    # Create new dummy chunk
    chunk       = Chunk.new
    chunk.type  = type
    chunk.flags = flags
    chunk.size  = size
    
    # Save the payload
    chunk.payload_raw = chunk.payload = bytes[4..chunk.padded_size]
    
    # Return the result
    return chunk
end

.from_bytes(bytes) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/diy/parser/mu/pcap/sctp/chunk.rb', line 20

def self.from_bytes bytes
    # Basic validation
    Pcap.assert(bytes.length >= 4,
                "Truncated chunk header: 4 > #{bytes.length}")
    
    # Read chunk header
    type, flags, size = bytes.unpack('CCn')
    
    # Validate chunk size
    Pcap.assert(bytes.length >= size,
                "Truncated chunk: #{size} set, #{bytes.length} available")
    
    # Create chunk based on type
    case type
        when CHUNK_DATA
            chunk = Data.from_bytes(flags, size, bytes[4..-1])
        when CHUNK_INIT
            chunk = Init.from_bytes(flags, size, bytes[4..-1])
        when CHUNK_INIT_ACK
            chunk = InitAck.from_bytes(flags, size, bytes[4..-1])
        when CHUNK_SACK
            chunk = dummy_chunk(type, flags, size, bytes)
        when CHUNK_HEARTBEAT
            chunk = dummy_chunk(type, flags, size, bytes)
        when CHUNK_HEARTBEAT_ACK
            chunk = dummy_chunk(type, flags, size, bytes)
        when CHUNK_ABORT
            chunk = dummy_chunk(type, flags, size, bytes)
        when CHUNK_SHUTDOWN
            chunk = dummy_chunk(type, flags, size, bytes)
        when CHUNK_SHUTDOWN_ACK
            chunk = dummy_chunk(type, flags, size, bytes)
        when CHUNK_ERROR
            chunk = dummy_chunk(type, flags, size, bytes)
        when CHUNK_COOKIE_ECHO
            chunk = dummy_chunk(type, flags, size, bytes)
        when CHUNK_COOKIE_ACK
            chunk = dummy_chunk(type, flags, size, bytes)
        when CHUNK_ECNE
            chunk = dummy_chunk(type, flags, size, bytes)
        when CHUNK_CWR
            chunk = dummy_chunk(type, flags, size, bytes)
        when CHUNK_SHUTDOWN_COMPLETE
            chunk = dummy_chunk(type, flags, size, bytes)
        when CHUNK_AUTH
            chunk = dummy_chunk(type, flags, size, bytes)
        when CHUNK_ASCONF_ACK
            chunk = dummy_chunk(type, flags, size, bytes)
        when CHUNK_PADDING
            chunk = dummy_chunk(type, flags, size, bytes)
        when CHUNK_FORWARD_TSN
            chunk = dummy_chunk(type, flags, size, bytes)
        when CHUNK_ASCONF
            chunk = dummy_chunk(type, flags, size, bytes)
        else
            chunk = dummy_chunk(type, flags, size, bytes)
    end
    
    # Return the result
    return chunk
end

Instance Method Details

#padded_sizeObject



90
91
92
93
94
95
96
# File 'lib/diy/parser/mu/pcap/sctp/chunk.rb', line 90

def padded_size
    if 0 == @size % 4
        return @size
    else
        return (@size + 4 - (@size % 4))
    end
end

#to_sObject



98
99
100
# File 'lib/diy/parser/mu/pcap/sctp/chunk.rb', line 98

def to_s
    return "chunk(%d, %d, %d)" % [@type, @flags, @size]
end

#write(io, ip) ⇒ Object



82
83
84
85
86
87
88
# File 'lib/diy/parser/mu/pcap/sctp/chunk.rb', line 82

def write io, ip
    header = [@type, @flags, @size].pack('CCn')
    
    # Write Chunk header followed by the payload
    io.write(header)
    io.write(@payload_raw)
end