Class: PacketFu::TcpReserved
- Includes:
- StructFu
- Defined in:
- lib/packetfu/protos/tcp/reserved.rb
Overview
Implements the Reserved bits for TCPHeader.
Header Definition
Integer(1 bit) :r1
Integer(1 bit) :r2
Integer(1 bit) :r3
Instance Attribute Summary collapse
-
#r1 ⇒ Object
Returns the value of attribute r1.
-
#r2 ⇒ Object
Returns the value of attribute r2.
-
#r3 ⇒ Object
Returns the value of attribute r3.
Instance Method Summary collapse
-
#initialize(args = {}) ⇒ TcpReserved
constructor
A new instance of TcpReserved.
-
#read(str) ⇒ Object
Reads a string to populate the object.
-
#to_i ⇒ Object
Returns the Reserved field as an integer.
Methods included from StructFu
#body=, #clone, #set_endianness, #sz, #typecast
Methods inherited from Struct
Constructor Details
#initialize(args = {}) ⇒ TcpReserved
Returns a new instance of TcpReserved.
15 16 17 18 19 20 |
# File 'lib/packetfu/protos/tcp/reserved.rb', line 15 def initialize(args={}) super( args[:r1] || 0, args[:r2] || 0, args[:r3] || 0) if args.kind_of? Hash end |
Instance Attribute Details
#r1 ⇒ Object
Returns the value of attribute r1
11 12 13 |
# File 'lib/packetfu/protos/tcp/reserved.rb', line 11 def r1 @r1 end |
#r2 ⇒ Object
Returns the value of attribute r2
11 12 13 |
# File 'lib/packetfu/protos/tcp/reserved.rb', line 11 def r2 @r2 end |
#r3 ⇒ Object
Returns the value of attribute r3
11 12 13 |
# File 'lib/packetfu/protos/tcp/reserved.rb', line 11 def r3 @r3 end |
Instance Method Details
#read(str) ⇒ Object
Reads a string to populate the object.
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/packetfu/protos/tcp/reserved.rb', line 28 def read(str) force_binary(str) return self if str.nil? || str.size.zero? if 1.respond_to? :ord byte = str[0].ord else byte = str[0] end self[:r1] = byte & 0b00000100 == 0b00000100 ? 1 : 0 self[:r2] = byte & 0b00000010 == 0b00000010 ? 1 : 0 self[:r3] = byte & 0b00000001 == 0b00000001 ? 1 : 0 self end |
#to_i ⇒ Object
Returns the Reserved field as an integer.
23 24 25 |
# File 'lib/packetfu/protos/tcp/reserved.rb', line 23 def to_i (r1.to_i << 2) + (r2.to_i << 1) + r3.to_i end |