Class: PacketFu::ICMPv6Header

Inherits:
Struct
  • Object
show all
Includes:
StructFu
Defined in:
lib/packetfu/protos/icmpv6/header.rb

Overview

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

Constant Summary collapse

PROTOCOL_NUMBER =
58

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 = {}) ⇒ ICMPv6Header

Returns a new instance of ICMPv6Header.



24
25
26
27
28
29
30
31
# 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

Instance Attribute Details

#bodyObject

Returns the value of attribute body

Returns:

  • (Object)

    the current value of body



19
20
21
# File 'lib/packetfu/protos/icmpv6/header.rb', line 19

def body
  @body
end

#icmpv6_codeObject

Getter for the code.



19
20
21
# File 'lib/packetfu/protos/icmpv6/header.rb', line 19

def icmpv6_code
  @icmpv6_code
end

#icmpv6_sumObject

Getter for the checksum.



19
20
21
# File 'lib/packetfu/protos/icmpv6/header.rb', line 19

def icmpv6_sum
  @icmpv6_sum
end

#icmpv6_typeObject

Getter for the type.



19
20
21
# File 'lib/packetfu/protos/icmpv6/header.rb', line 19

def icmpv6_type
  @icmpv6_type
end

Instance Method Details

#icmpv6_sum_readableObject



63
64
65
# File 'lib/packetfu/protos/icmpv6/header.rb', line 63

def icmpv6_sum_readable
  "0x%04x" % icmpv6_sum
end

#read(str) ⇒ Object

Reads a string to populate the object.



39
40
41
42
43
44
45
46
47
# 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_sObject

Returns the object in string form.



34
35
36
# File 'lib/packetfu/protos/icmpv6/header.rb', line 34

def to_s
  self.to_a.map {|x| x.to_s}.join
end