Class: PacketFu::NDPPacket
- Includes:
- EthHeaderMixin, IPv6HeaderMixin, NDPHeaderMixin
- Defined in:
- lib/bettercap/monkey/packetfu/utils.rb
Instance Attribute Summary collapse
-
#eth_header ⇒ Object
Returns the value of attribute eth_header.
-
#ipv6_header ⇒ Object
Returns the value of attribute ipv6_header.
-
#ndp_header ⇒ Object
Returns the value of attribute ndp_header.
Instance Method Summary collapse
-
#initialize(args = {}) ⇒ NDPPacket
constructor
A new instance of NDPPacket.
-
#ndp_calc_sum ⇒ Object
Calculates the checksum for the object.
-
#ndp_recalc(arg = :all) ⇒ Object
Recalculates the calculatable fields for NDP.
Methods included from NDPHeaderMixin
#ndp_code, #ndp_code=, #ndp_laddr, #ndp_laddr=, #ndp_lla, #ndp_lla=, #ndp_lla_readable, #ndp_opt_len, #ndp_opt_len=, #ndp_opt_type, #ndp_opt_type=, #ndp_reserved, #ndp_reserved=, #ndp_set_flags=, #ndp_sum, #ndp_sum=, #ndp_sum_readable, #ndp_taddr, #ndp_taddr=, #ndp_tgt, #ndp_tgt=, #ndp_tgt_readable, #ndp_type, #ndp_type=
Methods inherited from Packet
Constructor Details
#initialize(args = {}) ⇒ NDPPacket
Returns a new instance of NDPPacket.
373 374 375 376 377 378 379 380 381 382 383 384 385 |
# File 'lib/bettercap/monkey/packetfu/utils.rb', line 373 def initialize(args={}) @eth_header = EthHeader.new(args).read(args[:eth]) @ipv6_header = IPv6Header.new(args).read(args[:ipv6]) @ipv6_header.ipv6_next = PacketFu::NDPHeader::PROTOCOL_NUMBER @ndp_header = NDPHeader.new(args).read(args[:ndp]) @ipv6_header.body = @ndp_header @eth_header.body = @ipv6_header @headers = [@eth_header, @ipv6_header, @ndp_header] super ndp_calc_sum end |
Instance Attribute Details
#eth_header ⇒ Object
Returns the value of attribute eth_header.
371 372 373 |
# File 'lib/bettercap/monkey/packetfu/utils.rb', line 371 def eth_header @eth_header end |
#ipv6_header ⇒ Object
Returns the value of attribute ipv6_header.
371 372 373 |
# File 'lib/bettercap/monkey/packetfu/utils.rb', line 371 def ipv6_header @ipv6_header end |
#ndp_header ⇒ Object
Returns the value of attribute ndp_header.
371 372 373 |
# File 'lib/bettercap/monkey/packetfu/utils.rb', line 371 def ndp_header @ndp_header end |
Instance Method Details
#ndp_calc_sum ⇒ Object
Calculates the checksum for the object.
388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 |
# File 'lib/bettercap/monkey/packetfu/utils.rb', line 388 def ndp_calc_sum checksum = 0 # Compute sum on pseudo-header [ipv6_src, ipv6_dst].each do |iaddr| 8.times { |i| checksum += (iaddr >> (i*16)) & 0xffff } end checksum += PacketFu::NDPHeader::PROTOCOL_NUMBER checksum += ipv6_len # Continue with entire ICMPv6 message. checksum += (ndp_type.to_i << 8) + ndp_code.to_i checksum += ndp_reserved.to_i >> 16 checksum += ndp_reserved.to_i & 0xffff 8.times { |i| checksum += (ndp_tgt.to_i >> (i*16)) & 0xffff } checksum += (ndp_opt_type.to_i << 8) + ndp_opt_len.to_i mac2int = ndp_lla.to_s.unpack('H*').first.to_i(16) 3.times { |i| checksum += (mac2int >> (i*16)) & 0xffff } checksum = checksum % 0xffff checksum = 0xffff - checksum checksum == 0 ? 0xffff : checksum end |
#ndp_recalc(arg = :all) ⇒ Object
Recalculates the calculatable fields for NDP.
414 415 416 417 418 419 420 421 422 423 424 |
# File 'lib/bettercap/monkey/packetfu/utils.rb', line 414 def ndp_recalc(arg=:all) arg = arg.intern if arg.respond_to? :intern case arg when :ndp_sum self.ndp_sum = ndp_calc_sum when :all self.ndp_sum = ndp_calc_sum else raise ArgumentError, "No such field `#{arg}'" end end |