class PacketFu::HSRPHeader

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 fropert@packetfault.org. 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

Public Class Methods

new(args={}) click to toggle source
Calls superclass method
# File lib/packetfu/protos/hsrp/header.rb, line 30
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

Public Instance Methods

hsrp_addr() click to toggle source

Returns a more readable IP source address.

# File lib/packetfu/protos/hsrp/header.rb, line 107
def hsrp_addr
        self[:hsrp_vip].to_x
end
Also aliased as: hsrp_vip_readable
hsrp_addr=(addr) click to toggle source
# File lib/packetfu/protos/hsrp/header.rb, line 102
def hsrp_addr=(addr)
        self[:hsrp_vip].read_quad(addr)
end
hsrp_group() click to toggle source

Getter for the type.

# File lib/packetfu/protos/hsrp/header.rb, line 96
def hsrp_group; self[:hsrp_group].to_i; end
hsrp_group=(i) click to toggle source

Setter for the type.

# File lib/packetfu/protos/hsrp/header.rb, line 94
def hsrp_group=(i); typecast i; end
hsrp_hellotime() click to toggle source

Getter for the type.

# File lib/packetfu/protos/hsrp/header.rb, line 84
def hsrp_hellotime; self[:hsrp_hellotime].to_i; end
hsrp_hellotime=(i) click to toggle source

Setter for the type.

# File lib/packetfu/protos/hsrp/header.rb, line 82
def hsrp_hellotime=(i); typecast i; end
hsrp_holdtime() click to toggle source

Getter for the type.

# File lib/packetfu/protos/hsrp/header.rb, line 88
def hsrp_holdtime; self[:hsrp_holdtime].to_i; end
hsrp_holdtime=(i) click to toggle source

Setter for the type.

# File lib/packetfu/protos/hsrp/header.rb, line 86
def hsrp_holdtime=(i); typecast i; end
hsrp_opcode() click to toggle source

Getter for the type.

# File lib/packetfu/protos/hsrp/header.rb, line 76
def hsrp_opcode; self[:hsrp_opcode].to_i; end
hsrp_opcode=(i) click to toggle source

Setter for the type.

# File lib/packetfu/protos/hsrp/header.rb, line 74
def hsrp_opcode=(i); typecast i; end
hsrp_password_readable() click to toggle source
# File lib/packetfu/protos/hsrp/header.rb, line 115
def hsrp_password_readable
        hsrp_password.to_s.inspect
end
hsrp_priority() click to toggle source

Getter for the type.

# File lib/packetfu/protos/hsrp/header.rb, line 92
def hsrp_priority; self[:hsrp_priority].to_i; end
hsrp_priority=(i) click to toggle source

Setter for the type.

# File lib/packetfu/protos/hsrp/header.rb, line 90
def hsrp_priority=(i); typecast i; end
hsrp_reserved() click to toggle source

Getter for the type.

# File lib/packetfu/protos/hsrp/header.rb, line 100
def hsrp_reserved; self[:hsrp_reserved].to_i; end
hsrp_reserved=(i) click to toggle source

Setter for the type.

# File lib/packetfu/protos/hsrp/header.rb, line 98
def hsrp_reserved=(i); typecast i; end
hsrp_state() click to toggle source

Getter for the type.

# File lib/packetfu/protos/hsrp/header.rb, line 80
def hsrp_state; self[:hsrp_state].to_i; end
hsrp_state=(i) click to toggle source

Setter for the type.

# File lib/packetfu/protos/hsrp/header.rb, line 78
def hsrp_state=(i); typecast i; end
hsrp_version() click to toggle source

Getter for the type.

# File lib/packetfu/protos/hsrp/header.rb, line 72
def hsrp_version; self[:hsrp_version].to_i; end
hsrp_version=(i) click to toggle source

Setter for the type.

# File lib/packetfu/protos/hsrp/header.rb, line 70
def hsrp_version=(i); typecast i; end
hsrp_vip_readable()

Readability aliases

Alias for: hsrp_addr
read(str) click to toggle source

Reads a string to populate the object.

# File lib/packetfu/protos/hsrp/header.rb, line 52
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() click to toggle source

Returns the object in string form.

# File lib/packetfu/protos/hsrp/header.rb, line 47
def to_s
        self.to_a.map {|x| x.to_s}.join
end