Class: PacketFu::TcpHlen
- Includes:
- StructFu
- Defined in:
- lib/packetfu/protos/tcp/hlen.rb
Overview
Implements the Header Length for TCPHeader.
Header Definition
Integer(4 bits) :hlen
Instance Attribute Summary collapse
-
#hlen ⇒ Object
Returns the value of attribute hlen.
Instance Method Summary collapse
-
#initialize(args = {}) ⇒ TcpHlen
constructor
A new instance of TcpHlen.
-
#read(str) ⇒ Object
Reads a string to populate the object.
-
#to_i ⇒ Object
Returns the TcpHlen field as an integer.
-
#to_s ⇒ Object
Returns the object in string form.
Methods included from StructFu
#body=, #clone, #set_endianness, #sz, #typecast
Methods inherited from Struct
Constructor Details
#initialize(args = {}) ⇒ TcpHlen
Returns a new instance of TcpHlen.
12 13 14 |
# File 'lib/packetfu/protos/tcp/hlen.rb', line 12 def initialize(args={}) super(args[:hlen]) end |
Instance Attribute Details
#hlen ⇒ Object
Returns the value of attribute hlen
8 9 10 |
# File 'lib/packetfu/protos/tcp/hlen.rb', line 8 def hlen @hlen end |
Instance Method Details
#read(str) ⇒ Object
Reads a string to populate the object.
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/packetfu/protos/tcp/hlen.rb', line 24 def read(str) force_binary(str) return self if str.nil? || str.size.zero? if 1.respond_to? :ord self[:hlen] = (str[0].ord & 0b11110000) >> 4 else self[:hlen] = (str[0] & 0b11110000) >> 4 end self end |
#to_i ⇒ Object
Returns the TcpHlen field as an integer. Note these will become the high bits at the TCP header’s offset, even though the lower 4 bits will be further chopped up.
19 20 21 |
# File 'lib/packetfu/protos/tcp/hlen.rb', line 19 def to_i hlen.to_i & 0b1111 end |
#to_s ⇒ Object
Returns the object in string form.
36 37 38 |
# File 'lib/packetfu/protos/tcp/hlen.rb', line 36 def to_s [self.to_i].pack("C") end |