Class: PacketFu::TcpEcn
- Includes:
- StructFu
- Defined in:
- lib/packetfu/protos/tcp/ecn.rb
Overview
Implements the Explict Congestion Notification for TCPHeader.
Header Definition
Integer(1 bit) :n
Integer(1 bit) :c
Integer(1 bit) :e
Instance Attribute Summary collapse
-
#c ⇒ Object
Returns the value of attribute c.
-
#e ⇒ Object
Returns the value of attribute e.
-
#n ⇒ Object
Returns the value of attribute n.
Instance Method Summary collapse
-
#initialize(args = {}) ⇒ TcpEcn
constructor
A new instance of TcpEcn.
-
#read(str) ⇒ Object
Reads a string to populate the object.
-
#to_i ⇒ Object
Returns the TcpEcn field as an integer…
Methods included from StructFu
#body=, #clone, #set_endianness, #sz, #typecast
Methods inherited from Struct
Constructor Details
#initialize(args = {}) ⇒ TcpEcn
Returns a new instance of TcpEcn.
15 16 17 |
# File 'lib/packetfu/protos/tcp/ecn.rb', line 15 def initialize(args={}) super(args[:n], args[:c], args[:e]) if args end |
Instance Attribute Details
#c ⇒ Object
Returns the value of attribute c
11 12 13 |
# File 'lib/packetfu/protos/tcp/ecn.rb', line 11 def c @c end |
#e ⇒ Object
Returns the value of attribute e
11 12 13 |
# File 'lib/packetfu/protos/tcp/ecn.rb', line 11 def e @e end |
#n ⇒ Object
Returns the value of attribute n
11 12 13 |
# File 'lib/packetfu/protos/tcp/ecn.rb', line 11 def n @n end |
Instance Method Details
#read(str) ⇒ Object
Reads a string to populate the object.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/packetfu/protos/tcp/ecn.rb', line 26 def read(str) force_binary(str) return self if str.nil? || str.size < 2 if 1.respond_to? :ord byte1 = str[0].ord byte2 = str[1].ord else byte1 = str[0] byte2 = str[1] end self[:n] = byte1 & 0b00000001 == 0b00000001 ? 1 : 0 self[:c] = byte2 & 0b10000000 == 0b10000000 ? 1 : 0 self[:e] = byte2 & 0b01000000 == 0b01000000 ? 1 : 0 self end |
#to_i ⇒ Object
Returns the TcpEcn field as an integer… even though it’s going to be split across a byte boundary.
21 22 23 |
# File 'lib/packetfu/protos/tcp/ecn.rb', line 21 def to_i (n.to_i << 2) + (c.to_i << 1) + e.to_i end |