TcpOption is the base class for all TCP options. Note that TcpOption#len returns the size of the entire option, while TcpOption#optlen is the struct for the TCP Option Length field.
Subclassed options should set the correct TcpOption#kind by redefining initialize. They should also deal with various value types there by setting them explicitly with an accompanying StructFu#typecast for the setter.
By default, values are presumed to be strings, unless they are Numeric, in which case a guess is made to the width of the Numeric based on the given optlen.
Note that normally, optlen is /not/ enforced for directly setting values, so the user is perfectly capable of setting incorrect lengths.
- D
- E
- H
- K
- N
- O
- R
- T
- V
- PacketFu START:includes
- CLASS PacketFu::TcpOption::ECHO
- CLASS PacketFu::TcpOption::ECHOREPLY
- CLASS PacketFu::TcpOption::EOL
- CLASS PacketFu::TcpOption::MSS
- CLASS PacketFu::TcpOption::NOP
- CLASS PacketFu::TcpOption::SACK
- CLASS PacketFu::TcpOption::SACKOK
- CLASS PacketFu::TcpOption::TS
- CLASS PacketFu::TcpOption::WS
Source: show
# File lib/packetfu/protos/tcp.rb, line 228 def initialize(args={}) super( Int8.new(args[:kind]), Int8.new(args[:optlen]) ) if args[:value].kind_of? Numeric self[:value] = case args[:optlen] when 3; Int8.new(args[:value]) when 4; Int16.new(args[:value]) when 6; Int32.new(args[:value]) else; StructFu::String.new.read(args[:value]) end else self[:value] = StructFu::String.new.read(args[:value]) end end
The default decode for an unknown option. Known options should redefine this.
Source: show
# File lib/packetfu/protos/tcp.rb, line 267 def decode unk = "unk-#{self.kind.to_i}" (self[:optlen].to_i > 2 && self[:value].to_s.size > 1) ? [unk,self[:value]].join(":") : unk end
Generally, encoding a value is going to be just a read. Some options will treat things a little differently; TS for example, takes two values and concatenates them.
Source: show
# File lib/packetfu/protos/tcp.rb, line 291 def encode(str) self[:value] = self.class.new(:value => str).value end
Returns true if this option has an optlen. Some don’t.
Source: show
# File lib/packetfu/protos/tcp.rb, line 296 def has_optlen? (kind.value && kind.value < 2) ? false : true end
Returns true if this option has a value. Some don’t.
Source: show
# File lib/packetfu/protos/tcp.rb, line 301 def has_value? (value.respond_to? :to_s && value.to_s.size > 0) ? false : true end
Setter for the “kind” byte of this option.
Source: show
# File lib/packetfu/protos/tcp.rb, line 273 def kind=(i); typecast i; end
Setter for the “option length” byte for this option.
Source: show
# File lib/packetfu/protos/tcp.rb, line 275 def optlen=(i); typecast i; end
Reads a string to populate the object.
Source: show
# File lib/packetfu/protos/tcp.rb, line 253 def read(str) force_binary(str) return self if str.nil? self[:kind].read(str[0,1]) if str[1,1] self[:optlen].read(str[1,1]) if str[2,1] && optlen.value > 2 self[:value].read(str[2,optlen.value-2]) end end self end
Returns the object in string form.
Source: show
# File lib/packetfu/protos/tcp.rb, line 246 def to_s self[:kind].to_s + (self[:optlen].value.nil? ? nil : self[:optlen]).to_s + (self[:value].nil? ? nil : self[:value]).to_s end
Setter for the value of this option.
Source: show
# File lib/packetfu/protos/tcp.rb, line 278 def value=(i) if i.kind_of? Numeric typecast i elsif i.respond_to? :to_s self[:value] = i else self[:value] = '' end end