Class: PacketGen::Header::ICMPv6

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

Overview

ICMPv6 header class

Author:

  • Sylvain Daubert

Constant Summary collapse

IP_PROTOCOL =

ICMPv6 internet protocol number

58

Instance Attribute Summary

Attributes inherited from ICMP

#body, #code, #sum, #type

Instance Method Summary collapse

Methods inherited from ICMP

#initialize, #read

Methods included from HeaderClassMethods

#bind_header, #known_headers

Methods included from HeaderMethods

#header_id, #ip_header, #packet, #packet=

Methods included from StructFu

#body=, #clone, #set_endianness, #sz, #to_s, #typecast

Methods inherited from Struct

#force_binary

Constructor Details

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

Instance Method Details

#calc_sumInteger

Compute checksum and set sum field

Returns:

  • (Integer)


13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/packetgen/header/icmpv6.rb', line 13

def calc_sum
  sum = ip_header(self).pseudo_header_sum
  sum += self.sz
  sum += IP_PROTOCOL
  sum +=(type << 8) | code

  payload = body.to_s
  payload << "\x00" unless payload.size % 2 == 0
  payload.unpack('n*').each { |x| sum += x }

  while sum > 0xffff do
    sum = (sum & 0xffff) + (sum >> 16)
  end
  sum = ~sum & 0xffff
  self[:sum].value = (sum == 0) ? 0xffff : sum
end