Class: PacketGen::Header::TCP::Options
- Inherits:
-
Types::Array
- Object
- Array
- Types::Array
- PacketGen::Header::TCP::Options
- Defined in:
- lib/packetgen/header/tcp/options.rb
Overview
Container for TCP options in TCP header.
Constant Summary
Constants inherited from Types::Array
Class Method Summary collapse
-
.option_classes ⇒ Array<Class>
Get Option subclasses.
Instance Method Summary collapse
-
#add(opt, value = nil) ⇒ self
deprecated
Deprecated.
use Types::Array#push or Types::Array#<<
-
#read(str) ⇒ self
Read TCP header options from a string.
Methods inherited from Types::Array
#<<, #delete, #force_binary, #initialize, #push, set_of, #sz, #to_human, #to_s
Constructor Details
This class inherits a constructor from PacketGen::Types::Array
Class Method Details
.option_classes ⇒ Array<Class>
Get PacketGen::Header::TCP::Option subclasses
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/packetgen/header/tcp/options.rb', line 11 def self.option_classes return @klasses if defined? @klasses @klasses = [] Option.constants.each do |cst| next unless cst.to_s.end_with? '_KIND' optname = cst.to_s.sub(/_KIND/, '') @klasses[Option.const_get(cst)] = TCP.const_get(optname) end @klasses end |
Instance Method Details
#add(opt, value = nil) ⇒ self
Deprecated.
use Types::Array#push or Types::Array#<<
Add a well-known option
56 57 58 59 60 |
# File 'lib/packetgen/header/tcp/options.rb', line 56 def add(opt, value=nil) option = record_from_hash(opt: opt, value: value) self << option self end |
#read(str) ⇒ self
Read TCP header options from a string
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/packetgen/header/tcp/options.rb', line 25 def read(str) clear return self if str.nil? PacketGen.force_binary str i = 0 klasses = self.class.option_classes while i < str.to_s.length kind = str[i, 1].unpack('C').first this_option = if klasses[kind].nil? Option.new else klasses[kind].new end this_option.read str[i, str.size] unless this_option.has_length? this_option.length = nil this_option.value = nil end self << this_option i += this_option.sz end self end |