Class: PacketFu::TcpHlen

Inherits:
Struct
  • Object
show all
Includes:
StructFu
Defined in:
lib/packetfu/protos/tcp.rb

Overview

Header Definition

Fixnum (4 bits)  :hlen

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from StructFu

#body=, #clone, #set_endianness, #sz, #typecast

Methods inherited from Struct

#force_binary

Constructor Details

#initialize(args = {}) ⇒ TcpHlen

Returns a new instance of TcpHlen.



53
54
55
# File 'lib/packetfu/protos/tcp.rb', line 53

def initialize(args={})
  super(args[:hlen])
end

Instance Attribute Details

#hlenObject

Returns the value of attribute hlen

Returns:

  • (Object)

    the current value of hlen



49
50
51
# File 'lib/packetfu/protos/tcp.rb', line 49

def hlen
  @hlen
end

Instance Method Details

#read(str) ⇒ Object

Reads a string to populate the object.



65
66
67
68
69
70
71
72
73
74
# File 'lib/packetfu/protos/tcp.rb', line 65

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_iObject

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.



60
61
62
# File 'lib/packetfu/protos/tcp.rb', line 60

def to_i
  hlen.to_i & 0b1111
end

#to_sObject

Returns the object in string form.



77
78
79
# File 'lib/packetfu/protos/tcp.rb', line 77

def to_s
  [self.to_i].pack("C")
end