lib/packetgen/header/dns/name.rb in packetgen-2.6.0 vs lib/packetgen/header/dns/name.rb in packetgen-2.7.0

- old
+ new

@@ -6,15 +6,13 @@ # frozen_string_literal: true module PacketGen module Header class DNS - # DNS Name, defined as a suite of labels. A label is of type {Types::IntString}. # @author Sylvain Daubert class Name < Types::Array - # Mask to decode a pointer on another label POINTER_MASK = 0xc000 # @return [DNS] attr_accessor :dns @@ -54,22 +52,22 @@ clear return self if str.nil? force_binary str start = 0 - while true + loop do index = str[start, 2].unpack('n').first if pointer? index # Pointer on another label @pointer = str[start, 2] break else label = Types::IntString.new label.read(str[start..-1]) start += label.sz self << label - break if label.length == 0 or str[start..-1].length == 0 + break if label.length.zero? || str[start..-1].length.zero? end end # force resolution of compressed names name_from_pointer self @@ -99,19 +97,19 @@ end def name_from_pointer return nil unless @pointer return @pointer_name if @pointer_name - + index = @pointer.unpack('n').first mask = ~POINTER_MASK & 0xffff ptr = index & mask name = Name.new name.dns = @dns @pointer_name = name.read(self.dns.to_s[ptr..-1]).to_human end - def record_from_hash(hsh) + def record_from_hash(_hsh) raise NotImplementedError, "not supported by #{self.class}" end end end end