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

Inherits:
Mu::Pcap::SCTP::Chunk show all
Defined in:
lib/diy/parser/mu/pcap/sctp/chunk/init.rb

Direct Known Subclasses

InitAck

Constant Summary

Constants inherited from Packet

Packet::IGNORE_UDP_PORTS

Instance Attribute Summary collapse

Attributes inherited from Mu::Pcap::SCTP::Chunk

#flags, #size, #type

Attributes inherited from Packet

#payload, #payload_raw

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Mu::Pcap::SCTP::Chunk

dummy_chunk, #padded_size

Methods inherited from Packet

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

Constructor Details

#initializeInit

Returns a new instance of Init.



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/diy/parser/mu/pcap/sctp/chunk/init.rb', line 13

def initialize
    super
    
    @type        = CHUNK_INIT
    @init_tag    = 0
    @a_rwnd      = 0
    @o_streams   = 0
    @i_streams   = 0
    @init_tsn    = 0
    @payload     = []
end

Instance Attribute Details

#a_rwndObject

Returns the value of attribute a_rwnd.



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

def a_rwnd
  @a_rwnd
end

#i_streamsObject

Returns the value of attribute i_streams.



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

def i_streams
  @i_streams
end

#init_tagObject

Returns the value of attribute init_tag.



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

def init_tag
  @init_tag
end

#init_tsnObject

Returns the value of attribute init_tsn.



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

def init_tsn
  @init_tsn
end

#o_streamsObject

Returns the value of attribute o_streams.



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

def o_streams
  @o_streams
end

Class Method Details

.from_bytes(flags, size, bytes) ⇒ Object



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
# File 'lib/diy/parser/mu/pcap/sctp/chunk/init.rb', line 25

def self.from_bytes flags, size, bytes
    # Basic validation
    Pcap.assert(bytes.length >= 16,
                "Truncated init chunk header: 16 > #{bytes.length}")
    
    # Read init chunk header
    init_tag, a_rwnd, o_streams, i_streams, init_tsn = bytes.unpack('NNnnN')
    
    # Create init chunk
    init           = Init.new
    init.flags     = flags
    init.size      = size
    init.init_tag  = init_tag
    init.a_rwnd    = a_rwnd
    init.o_streams = o_streams
    init.i_streams = i_streams
    init.init_tsn  = init_tsn
    
    # Initialize the counter
    length = 16
    
    # Collect the chunks
    while length < bytes.length
        # Parse new parameter from the bytes
        parameter = Parameter.from_bytes(bytes[length..-1])
        
        # Get parameter size with padding
        length += parameter.padded_size
        
        # Add chunk to the list
        init << parameter
    end
    
    # Return the result
    return init
end

Instance Method Details

#<<(parameter) ⇒ Object



80
81
82
# File 'lib/diy/parser/mu/pcap/sctp/chunk/init.rb', line 80

def << parameter
    @payload << parameter
end

#to_sObject



84
85
86
87
88
89
90
91
92
# File 'lib/diy/parser/mu/pcap/sctp/chunk/init.rb', line 84

def to_s
    return "init(%d, %d, %d, %d, %d, %d, %s)" % [@size,
                                                 @init_tag,
                                                 @a_rwnd,
                                                 @o_streams,
                                                 @i_streams,
                                                 @init_tsn,
                                                 @payload.join(", ")]
end

#write(io, ip) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/diy/parser/mu/pcap/sctp/chunk/init.rb', line 62

def write io, ip
    chunk_header = [@type, @flags, @size].pack('CCn')
    init_header  = [@init_tag,
                    @a_rwnd,
                    @o_streams,
                    @i_streams,
                    @init_tsn].pack('NNnnN')
    
    # Write Chunk header followed by the Init chunk header
    io.write(chunk_header)
    io.write(init_header)
    
    # Write each parameter
    @payload.each do |parameter|
        parameter.write(io, ip)
    end
end