Class: PacketGen::Header::ICMPv6
- Defined in:
- lib/packetgen/header/icmpv6.rb
Overview
A ICMPv6 header consists of:
-
a
typefield (StructFu::Int8 type), -
a
codefield (StructFu::Int8 type), -
a
checksumfield (StructFu::Int16 type), -
and a
body.
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'
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
-
#calc_checksum ⇒ Integer
Compute checksum and set
checksumfield.
Methods inherited from ICMP
Methods included from HeaderClassMethods
#bind_header, #define_bit_fields_on, #known_headers
Methods included from HeaderMethods
#header_id, #inspect, #ip_header, #packet, #packet=, #protocol_name
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_checksum ⇒ Integer
Compute checksum and set checksum field
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# 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 +=(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 end |