lib/packetgen/header/icmpv6.rb in packetgen-2.4.0 vs lib/packetgen/header/icmpv6.rb in packetgen-2.5.0
- old
+ new
@@ -1,10 +1,12 @@
# This file is part of PacketGen
# See https://github.com/sdaubert/packetgen for more informations
# Copyright (C) 2016 Sylvain Daubert <sylvain.daubert@laposte.net>
# This program is published under MIT license.
+# frozen_string_literal: true
+
module PacketGen
module Header
# A ICMPv6 header consists of:
# * a +type+ field ({Types::Int8} type),
@@ -35,20 +37,11 @@
# @return [Integer]
def calc_checksum
sum = ip_header(self).pseudo_header_checksum
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[:checksum].value = (sum == 0) ? 0xffff : sum
+ sum += IP.sum16(self)
+ self.checksum = IP.reduce_checksum(sum)
end
end
self.add_class ICMPv6
IPv6.bind_header ICMPv6, next: ICMPv6::IP_PROTOCOL