class DNSMessage::Pointer

Handle DNS pointers

Public Class Methods

new(hash = {}) click to toggle source
# File lib/dnsmessage/pointer.rb, line 6
def initialize(hash = {})
  @hash = hash
end

Public Instance Methods

add(key, value) click to toggle source
# File lib/dnsmessage/pointer.rb, line 20
def add(key, value)
  if key.instance_of?(Integer)
    add_name(key, value)
  else
    add_ptr(key, value)
  end
end
add_arr(arr, offset) click to toggle source
# File lib/dnsmessage/pointer.rb, line 10
def add_arr(arr, offset)
  return unless arr

  arr.each do |k, v|
    k += offset if k.instance_of?(Integer)
    v += offset if v.instance_of?(Integer)
    add(k, v)
  end
end
find(key) click to toggle source
# File lib/dnsmessage/pointer.rb, line 32
def find(key)
  @hash[key]
end
to_h() click to toggle source
# File lib/dnsmessage/pointer.rb, line 28
def to_h
  @hash
end

Private Instance Methods

add_name(key, value) click to toggle source
# File lib/dnsmessage/pointer.rb, line 38
def add_name(key, value)
  value = value.split(".")
  loop do
    return unless value.length > 1

    @hash[key] = value.join(".")
    key += value.shift.length + 1
  end
end
add_ptr(key, value) click to toggle source
# File lib/dnsmessage/pointer.rb, line 48
def add_ptr(key, value)
  key = key.split(".")
  loop do
    return unless key.length > 1

    @hash[key.join(".")] = value
    value += key.shift.length + 1
  end
end