class PacketFu::ICMPv6Header

ICMPv6Header is a complete ICMPv6 struct, used in ICMPv6Packet. ICMPv6 is typically used for network administration and connectivity testing.

For more on ICMP packets, see www.networksorcery.com/enp/protocol/icmpv6.htm

Header Definition

Int8    :icmp_type                        # Type
Int8    :icmp_code                        # Code
Int16   :icmp_sum    Default: calculated  # Checksum
String  :body

Constants

PROTOCOL_NUMBER

Public Class Methods

new(args={}) click to toggle source
Calls superclass method
# File lib/packetfu/protos/icmpv6/header.rb, line 24
def initialize(args={})
  super(
    Int8.new(args[:icmpv6_type]),
    Int8.new(args[:icmpv6_code]),
    Int16.new(args[:icmpv6_sum]),
    StructFu::String.new.read(args[:body])
  )
end

Public Instance Methods

icmpv6_code() click to toggle source

Getter for the code.

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

Setter for the code.

# File lib/packetfu/protos/icmpv6/header.rb, line 54
def icmpv6_code=(i); typecast i; end
icmpv6_sum() click to toggle source

Getter for the checksum.

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

Setter for the checksum. Note, this is calculated automatically with icmpv6_calc_sum.

# File lib/packetfu/protos/icmpv6/header.rb, line 59
def icmpv6_sum=(i); typecast i; end
icmpv6_sum_readable() click to toggle source
# File lib/packetfu/protos/icmpv6/header.rb, line 63
def icmpv6_sum_readable
  "0x%04x" % icmpv6_sum
end
icmpv6_type() click to toggle source

Getter for the type.

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

Setter for the type.

# File lib/packetfu/protos/icmpv6/header.rb, line 50
def icmpv6_type=(i); typecast i; end
read(str) click to toggle source

Reads a string to populate the object.

# File lib/packetfu/protos/icmpv6/header.rb, line 39
def read(str)
  force_binary(str)
  return self if str.nil?
  self[:icmpv6_type].read(str[0,1])
  self[:icmpv6_code].read(str[1,1])
  self[:icmpv6_sum].read(str[2,2])
  self[:body].read(str[4,str.size])
  self
end
to_s() click to toggle source

Returns the object in string form.

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