Class: PacketFu::HSRPHeader

Inherits:
Struct
  • Object
show all
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

Instance Method Summary collapse

Methods included from StructFu

#clone, #set_endianness, #sz, #typecast

Methods inherited from Struct

#force_binary

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

#bodyObject

Returns the value of attribute body

Returns:

  • (Object)

    the current value of body


23
24
25
# File 'lib/packetfu/protos/hsrp/header.rb', line 23

def body
  @body
end

#hsrp_groupObject

Getter for the type.


23
24
25
# File 'lib/packetfu/protos/hsrp/header.rb', line 23

def hsrp_group
  @hsrp_group
end

#hsrp_hellotimeObject

Getter for the type.


23
24
25
# File 'lib/packetfu/protos/hsrp/header.rb', line 23

def hsrp_hellotime
  @hsrp_hellotime
end

#hsrp_holdtimeObject

Getter for the type.


23
24
25
# File 'lib/packetfu/protos/hsrp/header.rb', line 23

def hsrp_holdtime
  @hsrp_holdtime
end

#hsrp_opcodeObject

Getter for the type.


23
24
25
# File 'lib/packetfu/protos/hsrp/header.rb', line 23

def hsrp_opcode
  @hsrp_opcode
end

#hsrp_passwordObject

Returns the value of attribute hsrp_password

Returns:

  • (Object)

    the current value of hsrp_password


23
24
25
# File 'lib/packetfu/protos/hsrp/header.rb', line 23

def hsrp_password
  @hsrp_password
end

#hsrp_priorityObject

Getter for the type.


23
24
25
# File 'lib/packetfu/protos/hsrp/header.rb', line 23

def hsrp_priority
  @hsrp_priority
end

#hsrp_reservedObject

Getter for the type.


23
24
25
# File 'lib/packetfu/protos/hsrp/header.rb', line 23

def hsrp_reserved
  @hsrp_reserved
end

#hsrp_stateObject

Getter for the type.


23
24
25
# File 'lib/packetfu/protos/hsrp/header.rb', line 23

def hsrp_state
  @hsrp_state
end

#hsrp_versionObject

Getter for the type.


23
24
25
# File 'lib/packetfu/protos/hsrp/header.rb', line 23

def hsrp_version
  @hsrp_version
end

#hsrp_vipObject

Returns the value of attribute hsrp_vip

Returns:

  • (Object)

    the current value of hsrp_vip


23
24
25
# File 'lib/packetfu/protos/hsrp/header.rb', line 23

def hsrp_vip
  @hsrp_vip
end

Instance Method Details

#hsrp_addrObject 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_readableObject


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_sObject

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