Class: PacketGen::Header::ICMPv6

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

Overview

A ICMPv6 header consists of:

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     # => PacketGen::Header::ICMPv6

ICMPv6 attributes

icmpv6.code = 0
icmpv6.type = 200
icmpv6.checksum = 0x248a
icmpv6.body.read '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

Attributes inherited from Base

#packet

Instance Method Summary collapse

Methods inherited from Base

#added_to_packet, bind, bind_header, calculate_and_set_length, #header_id, inherited, #initialize, #ip_header, known_headers, #ll_header, #method_name, #parse?, #protocol_name, protocol_name

Methods inherited from Types::Fields

#[], #[]=, #bits_on, #body=, define_bit_fields_on, define_field, define_field_after, define_field_before, delete_field, fields, #fields, #force_binary, inherited, #initialize, #inspect, #is_optional?, #is_present?, #offset_of, #optional?, #optional_fields, #present?, #read, remove_bit_fields_on, remove_field, #sz, #to_h, #to_s, update_field

Constructor Details

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

Instance Method Details

#calc_checksumInteger

Compute checksum and set checksum field

Returns:

  • (Integer)


36
37
38
39
40
41
42
# File 'lib/packetgen/header/icmpv6.rb', line 36

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