lib/packetgen/header/dns/rrsection.rb in packetgen-2.6.0 vs lib/packetgen/header/dns/rrsection.rb in packetgen-2.7.0
- old
+ new
@@ -6,42 +6,40 @@
# frozen_string_literal: true
module PacketGen
module Header
class DNS
-
# Define a DNS Ressource Record Section
# @author Sylvain Daubert
class RRSection < Types::Array
-
# @api private
# @param [DNS] dns
# @param [Types::Int] counter
def initialize(dns, counter)
+ super(counter: counter)
@dns = dns
- @counter = counter
end
# Read RR section from a string
# @param [String] str binary string
# @return [RRSection] self
def read(str)
clear
return self if str.nil?
force_binary str
- while str.length > 0 and self.size < @counter.to_i
+ while !str.empty? && (self.size < @counter.to_i)
rr = RR.new(@dns).read(str)
- rr = OPT.new(@dns).read(str) if rr.has_type?('OPT')
+ rr = OPT.new(@dns).read(str) if rr.type?('OPT')
str.slice!(0, rr.sz)
- self.push rr
+ push rr
end
self
end
private
def record_from_hash(hsh)
- if hsh.has_key? :rtype
+ if hsh.key? :rtype
case hsh.delete(:rtype)
when 'Question'
Question.new(@dns, hsh)
when 'OPT'
OPT.new(@dns, hsh)