Class: PacketGen::Header::TCP::Options
- Inherits:
-
Types::Array
- Object
- 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
#<<, #==, #[], #clear, #clear!, #delete, #delete_at, #each, #empty?, #first, #force_binary, #initialize, #initialize_copy, #last, #push, set_of, #size, #sz, #to_a, #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
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/packetgen/header/tcp/options.rb', line 16 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
61 62 63 64 65 66 |
# File 'lib/packetgen/header/tcp/options.rb', line 61 def add(opt, value=nil) Deprecation.deprecated(self.class, __method__, 'push') option = record_from_hash(opt: opt, value: value) self << option self end |
#read(str) ⇒ self
Read TCP header options from a string
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/packetgen/header/tcp/options.rb', line 30 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.length? this_option.length = nil this_option.value = nil end self << this_option i += this_option.sz end self end |