Class: PacketFu::HSRPHeader
- Includes:
- StructFu
- Defined in:
- lib/packetfu/protos/hsrp/header.rb
Overview
HSRPHeader is a complete HSRP struct, used in HSRPPacket. HSRP is typically used for fault-tolerant default gateway in IP routing environment.
For more on HSRP packets, see www.networksorcery.com/enp/protocol/hsrp.htm
Submitted by [email protected]. Thanks, Francois!
Header Definition
Int8 :hsrp_version Default: 0 # Version
Int8 :hsrp_opcode # Opcode
Int8 :hsrp_state # State
Int8 :hsrp_hellotime Default: 3 # Hello Time
Int8 :hsrp_holdtime Default: 10 # Hold Time
Int8 :hsrp_priority # Priority
Int8 :hsrp_group # Group
Int8 :hsrp_reserved Default: 0 # Reserved
String :hsrp_password # Authentication Data
Octets :hsrp_vip # Virtual IP Address
String :body
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
-
#hsrp_group ⇒ Object
Getter for the type.
-
#hsrp_hellotime ⇒ Object
Getter for the type.
-
#hsrp_holdtime ⇒ Object
Getter for the type.
-
#hsrp_opcode ⇒ Object
Getter for the type.
-
#hsrp_password ⇒ Object
Returns the value of attribute hsrp_password.
-
#hsrp_priority ⇒ Object
Getter for the type.
-
#hsrp_reserved ⇒ Object
Getter for the type.
-
#hsrp_state ⇒ Object
Getter for the type.
-
#hsrp_version ⇒ Object
Getter for the type.
-
#hsrp_vip ⇒ Object
Returns the value of attribute hsrp_vip.
Instance Method Summary collapse
-
#hsrp_addr ⇒ Object
(also: #hsrp_vip_readable)
Returns a more readable IP source address.
- #hsrp_addr=(addr) ⇒ Object
- #hsrp_password_readable ⇒ Object
-
#initialize(args = {}) ⇒ HSRPHeader
constructor
A new instance of HSRPHeader.
-
#read(str) ⇒ Object
Reads a string to populate the object.
-
#to_s ⇒ Object
Returns the object in string form.
Methods included from StructFu
#clone, #set_endianness, #sz, #typecast
Methods inherited from Struct
Constructor Details
#initialize(args = {}) ⇒ HSRPHeader
Returns a new instance of HSRPHeader.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/packetfu/protos/hsrp/header.rb', line 31 def initialize(args={}) super( Int8.new(args[:hsrp_version] || 0), Int8.new(args[:hsrp_opcode]), Int8.new(args[:hsrp_state]), Int8.new(args[:hsrp_hellotime] || 3), Int8.new(args[:hsrp_holdtime] || 10), Int8.new(args[:hsrp_priority]), Int8.new(args[:hsrp_group]), Int8.new(args[:hsrp_reserved] || 0), StructFu::String.new.read(args[:hsrp_password] || "cisco\x00\x00\x00"), Octets.new.read(args[:hsrp_vip] || ("\x00" * 4)), StructFu::String.new.read(args[:body]) ) end |
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body
23 24 25 |
# File 'lib/packetfu/protos/hsrp/header.rb', line 23 def body @body end |
#hsrp_group ⇒ Object
Getter for the type.
23 24 25 |
# File 'lib/packetfu/protos/hsrp/header.rb', line 23 def hsrp_group @hsrp_group end |
#hsrp_hellotime ⇒ Object
Getter for the type.
23 24 25 |
# File 'lib/packetfu/protos/hsrp/header.rb', line 23 def hsrp_hellotime @hsrp_hellotime end |
#hsrp_holdtime ⇒ Object
Getter for the type.
23 24 25 |
# File 'lib/packetfu/protos/hsrp/header.rb', line 23 def hsrp_holdtime @hsrp_holdtime end |
#hsrp_opcode ⇒ Object
Getter for the type.
23 24 25 |
# File 'lib/packetfu/protos/hsrp/header.rb', line 23 def hsrp_opcode @hsrp_opcode end |
#hsrp_password ⇒ Object
Returns the value of attribute hsrp_password
23 24 25 |
# File 'lib/packetfu/protos/hsrp/header.rb', line 23 def hsrp_password @hsrp_password end |
#hsrp_priority ⇒ Object
Getter for the type.
23 24 25 |
# File 'lib/packetfu/protos/hsrp/header.rb', line 23 def hsrp_priority @hsrp_priority end |
#hsrp_reserved ⇒ Object
Getter for the type.
23 24 25 |
# File 'lib/packetfu/protos/hsrp/header.rb', line 23 def hsrp_reserved @hsrp_reserved end |
#hsrp_state ⇒ Object
Getter for the type.
23 24 25 |
# File 'lib/packetfu/protos/hsrp/header.rb', line 23 def hsrp_state @hsrp_state end |
#hsrp_version ⇒ Object
Getter for the type.
23 24 25 |
# File 'lib/packetfu/protos/hsrp/header.rb', line 23 def hsrp_version @hsrp_version end |
#hsrp_vip ⇒ Object
Returns the value of attribute hsrp_vip
23 24 25 |
# File 'lib/packetfu/protos/hsrp/header.rb', line 23 def hsrp_vip @hsrp_vip end |
Instance Method Details
#hsrp_addr ⇒ Object Also known as: hsrp_vip_readable
Returns a more readable IP source address.
108 109 110 |
# File 'lib/packetfu/protos/hsrp/header.rb', line 108 def hsrp_addr self[:hsrp_vip].to_x end |
#hsrp_addr=(addr) ⇒ Object
103 104 105 |
# File 'lib/packetfu/protos/hsrp/header.rb', line 103 def hsrp_addr=(addr) self[:hsrp_vip].read_quad(addr) end |
#hsrp_password_readable ⇒ Object
116 117 118 |
# File 'lib/packetfu/protos/hsrp/header.rb', line 116 def hsrp_password_readable hsrp_password.to_s.inspect end |
#read(str) ⇒ Object
Reads a string to populate the object.
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/packetfu/protos/hsrp/header.rb', line 53 def read(str) force_binary(str) return self if str.nil? self[:hsrp_version].read(str[0,1]) self[:hsrp_opcode].read(str[1,1]) self[:hsrp_state].read(str[2,1]) self[:hsrp_hellotime].read(str[3,1]) self[:hsrp_holdtime].read(str[4,1]) self[:hsrp_priority].read(str[5,1]) self[:hsrp_group].read(str[6,1]) self[:hsrp_reserved].read(str[7,1]) self[:hsrp_password].read(str[8,8]) self[:hsrp_vip].read(str[16,4]) self[:body].read(str[20,str.size]) if str.size > 20 self end |
#to_s ⇒ Object
Returns the object in string form.
48 49 50 |
# File 'lib/packetfu/protos/hsrp/header.rb', line 48 def to_s self.to_a.map {|x| x.to_s}.join end |