Class Racket::L4::ICMPv6Generic
In: lib/racket/l4/icmpv6.rb  (CVS)
Parent: RacketPart

Internet Control Message Protcol, v6

en.wikipedia.org/wiki/ICMPv6

Generic ICMP class from which all ICMP variants spawn. This should never be used directly.

Methods

add_option   checksum!   checksum?   fix!   get_options   new   slla   slla=   tlla   tlla=  

Constants

ICMPv6_TYPE_ECHO_REPLY = 129
ICMPv6_TYPE_DESTINATION_UNREACHABLE = 1
ICMPv6_TYPE_PACKET_TOO_BIG = 2
ICMPv6_TYPE_ECHO_REQUEST = 128
ICMPv6_TYPE_TIME_EXCEEDED = 3
ICMPv6_TYPE_PARAMETER_PROBLEM = 4
ICMPv6_TYPE_MLD_QUERY = 130
ICMPv6_TYPE_MLD_REPORT = 131
ICMPv6_TYPE_MLD_DONE = 132
ICMPv6_TYPE_ROUTER_SOLICITATION = 133
ICMPv6_TYPE_ROUTER_ADVERTISEMENT = 134
ICMPv6_TYPE_NEIGHBOR_SOLICITATION = 135
ICMPv6_TYPE_NEIGHBOR_ADVERTISEMENT = 136
ICMPv6_TYPE_REDIRECT = 137
ICMPv6_TYPE_INFORMATION_REQUEST = 139
ICMPv6_TYPE_INFORMATION_REPLY = 140

Attributes

checksum    Checksum
code    Code
message   
type    Type

Public Class methods

[Source]

# File lib/racket/l4/icmpv6.rb, line 66
  def initialize(*args)
    super(*args)
    @autofix = false
  end

Public Instance methods

Add an ICMPv6 option. RFC claims that the value should be padded (with what?) to land on a 64-bit boundary, however that doesn‘t always appear to be the case. so, yeah, try to pad on your own or pick strings that are multiples of 8 characters

[Source]

# File lib/racket/l4/icmpv6.rb, line 74
  def add_option(type, value)
    t = Racket::Misc::TLV.new(1,1)
    t.type = type
    t.length = (value.length + 2) / 8
    just = value.length + 2 + (8 - ((value.length + 2) % 8))
    t.value = (value.length + 2) % 8 == 0 ? value : value.ljust(just, "\x00")
    self.payload = t.encode + self.payload 
  end

compute and set the checksum for this ICMP packet

[Source]

# File lib/racket/l4/icmpv6.rb, line 96
  def checksum!(src_ip, dst_ip)
    self.checksum = compute_checksum(src_ip, dst_ip)
  end

check the checksum for this ICMP packet

[Source]

# File lib/racket/l4/icmpv6.rb, line 62
  def checksum?
    self.checksum == compute_checksum
  end

‘fix’ this ICMP packet up for sending. (really, just set the checksum)

[Source]

# File lib/racket/l4/icmpv6.rb, line 102
  def fix!(src_ip, dst_ip)
    self.checksum!(src_ip, dst_ip)
  end

ignorantly assume the first parts of the payload contain ICMPv6 options and find a return an array of Racket::Misc::TLV representing the options

[Source]

# File lib/racket/l4/icmpv6.rb, line 85
  def get_options
    p = self.payload
    options = []
    until ((o = Racket::Misc::TLV.new(1,1,8,true).decode(p)).nil?)
      options << o[0..2]
      p = o[3]
    end
    options
  end

get the source link layer address of this message, if found

[Source]

# File lib/racket/l4/icmpv6.rb, line 107
  def slla
    addr = nil
    self.get_options.each do |o|
      type, length, value, rest = o.flatten
      if (type == 1)
        addr = L2::Misc.string2mac(value)
      end
    end
    addr
  end

set the source link layer address of this message. expects addr in de:ad:ba:dc:af:e0 form

[Source]

# File lib/racket/l4/icmpv6.rb, line 120
  def slla=(addr)
    self.add_option(1, L2::Misc.mac2string(addr))
  end

get the target link layer address of this message, if found

[Source]

# File lib/racket/l4/icmpv6.rb, line 125
  def tlla
    addr = nil
    self.get_options.each do |o|
      type, length, value, rest = o.flatten
      if (type == 2)
        addr = L2::Misc.string2mac(value)
      end
    end
    addr
  end

set the target link layer address of this message expects addr in de:ad:ba:dc:af:e0 form

[Source]

# File lib/racket/l4/icmpv6.rb, line 138
  def tlla=(addr)
    self.add_option(2, L2::Misc.mac2string(addr))
  end

[Validate]