Class: PacketGen::Header::ICMPv6

Inherits:
ICMP
  • Object
show all
Defined in:
lib/packetgen/header/icmpv6.rb

Overview

ICMPv6 header (RFC 4443)

 0                   1                   2                   3
 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|     Type      |     Code      |          Checksum             |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

A ICMPv6 header consists of:

  • a #type field (BinStruct::Int8 type),

  • a #code field (BinStruct::Int8 type),

  • a #checksum field (BinStruct::Int16 type),

  • and a #body.

Examples:

Create a ICMPv6 header

# standalone
icmpv6 = PacketGen::Header::ICMPv6.new
# in a packet
pkt = PacketGen.gen('IPv6').add('ICMPv6')
# access to ICMPv6 header
pkt.icmpv6.class  # => PacketGen::Header::ICMPv6

ICMPv6 attributes

icmpv6 = PacketGen::Header::ICMPv6.new
icmpv6.code = 0
icmpv6.type = 200
icmpv6.checksum = 0x248a
icmpv6.body = 'this is a body'

Author:

  • Sylvain Daubert

Constant Summary collapse

IP_PROTOCOL =

ICMPv6 internet protocol number

58

Instance Attribute Summary

Attributes inherited from ICMP

#body, #checksum, #code, #type

Instance Method Summary collapse

Methods inherited from Base

bind, calculate_and_set_length, #header_id, inherited, #initialize, #ip_header, #ll_header

Methods included from PacketGen::Headerable

#added_to_packet, included, #method_name, #packet, #packet=, #parse?, #protocol_name, #read, #to_s

Constructor Details

This class inherits a constructor from PacketGen::Header::Base

Instance Method Details

#calc_checksumInteger

Compute IPV6-style checksum and set checksum field

Returns:

  • (Integer)

44
45
46
47
48
49
50
# File 'lib/packetgen/header/icmpv6.rb', line 44

def calc_checksum
  sum = ip_header(self).pseudo_header_checksum
  sum += self.sz
  sum += IP_PROTOCOL
  sum += IP.sum16(self)
  self.checksum = IP.reduce_checksum(sum)
end