Class: Mu::Pcap::SCTP::Chunk::Init
- Inherits:
-
Mu::Pcap::SCTP::Chunk
- Object
- Packet
- Mu::Pcap::SCTP::Chunk
- Mu::Pcap::SCTP::Chunk::Init
- Defined in:
- lib/mu/pcap/sctp/chunk/init.rb
Direct Known Subclasses
Constant Summary
Constants inherited from Packet
Instance Attribute Summary collapse
-
#a_rwnd ⇒ Object
Returns the value of attribute a_rwnd.
-
#i_streams ⇒ Object
Returns the value of attribute i_streams.
-
#init_tag ⇒ Object
Returns the value of attribute init_tag.
-
#init_tsn ⇒ Object
Returns the value of attribute init_tsn.
-
#o_streams ⇒ Object
Returns the value of attribute o_streams.
Attributes inherited from Mu::Pcap::SCTP::Chunk
Attributes inherited from Packet
Class Method Summary collapse
Instance Method Summary collapse
- #<<(parameter) ⇒ Object
-
#initialize ⇒ Init
constructor
A new instance of Init.
- #to_s ⇒ Object
- #write(io, ip) ⇒ Object
Methods inherited from Mu::Pcap::SCTP::Chunk
Methods inherited from Packet
#==, #deepdup, #flow_id, isolate_l7, normalize, #payload_bytes, #to_bytes
Constructor Details
#initialize ⇒ Init
Returns a new instance of Init.
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/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_rwnd ⇒ Object
Returns the value of attribute a_rwnd.
11 12 13 |
# File 'lib/mu/pcap/sctp/chunk/init.rb', line 11 def a_rwnd @a_rwnd end |
#i_streams ⇒ Object
Returns the value of attribute i_streams.
11 12 13 |
# File 'lib/mu/pcap/sctp/chunk/init.rb', line 11 def i_streams @i_streams end |
#init_tag ⇒ Object
Returns the value of attribute init_tag.
11 12 13 |
# File 'lib/mu/pcap/sctp/chunk/init.rb', line 11 def init_tag @init_tag end |
#init_tsn ⇒ Object
Returns the value of attribute init_tsn.
11 12 13 |
# File 'lib/mu/pcap/sctp/chunk/init.rb', line 11 def init_tsn @init_tsn end |
#o_streams ⇒ Object
Returns the value of attribute o_streams.
11 12 13 |
# File 'lib/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/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/mu/pcap/sctp/chunk/init.rb', line 80 def << parameter @payload << parameter end |
#to_s ⇒ Object
84 85 86 87 88 89 90 91 92 |
# File 'lib/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/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 |