Class: PacketGen::Header::ICMPv6
- Defined in:
- lib/packetgen/header/icmpv6.rb
Overview
ICMPv6 header class
Constant Summary collapse
- IP_PROTOCOL =
ICMPv6 internet protocol number
58
Instance Attribute Summary
Attributes inherited from ICMP
Instance Method Summary collapse
-
#calc_sum ⇒ Integer
Compute checksum and set
sumfield.
Methods inherited from ICMP
Methods included from HeaderClassMethods
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
Constructor Details
This class inherits a constructor from PacketGen::Header::ICMP
Instance Method Details
#calc_sum ⇒ Integer
Compute checksum and set sum field
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 |