class PacketGen::Header::DNS::RRSection

Define a DNS Ressource Record Section @author Sylvain Daubert

Public Class Methods

new(dns, counter) click to toggle source

@api private @param [DNS] dns @param [Types::Int] counter

Calls superclass method
# File lib/packetgen/header/dns/rrsection.rb, line 17
def initialize(dns, counter)
  super(counter: counter)
  @dns = dns
end

Public Instance Methods

read(str) click to toggle source

Read RR section from a string @param [String] str binary string @return [RRSection] self

# File lib/packetgen/header/dns/rrsection.rb, line 25
def read(str)
  clear
  return self if str.nil?

  PacketGen.force_binary str
  while !str.empty? && (self.size < @counter.to_i)
    rr = RR.new(@dns).read(str)
    rr = OPT.new(@dns).read(str) if rr.type?('OPT')
    str.slice!(0, rr.sz)
    push rr
  end
  self
end

Private Instance Methods

record_from_hash(hsh) click to toggle source
# File lib/packetgen/header/dns/rrsection.rb, line 41
def record_from_hash(hsh)
  if hsh.key? :rtype
    case hsh.delete(:rtype)
    when 'Question'
      Question.new(@dns, hsh)
    when 'OPT'
      OPT.new(@dns, hsh)
    when 'RR'
      RR.new(@dns, hsh)
    else
      raise TypeError, 'rtype should be a Question, OPT or RR'
    end
  else
    hsh
  end
end