Class: PacketGen::Header::DNS::RRSection

Inherits:
BinStruct::Array
  • Object
show all
Defined in:
lib/packetgen/header/dns/rrsection.rb

Overview

Define a DNS Ressource Record Section

Author:

  • Sylvain Daubert

Since:

  • 1.3.0

Direct Known Subclasses

QDSection

Instance Method Summary collapse

Constructor Details

#initialize(dns, counter) ⇒ RRSection

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of RRSection.

Parameters:

  • dns (DNS)
  • counter (BinStruct::Int)

Since:

  • 1.3.0



18
19
20
21
# File 'lib/packetgen/header/dns/rrsection.rb', line 18

def initialize(dns, counter)
  super(counter: counter)
  @dns = dns
end

Instance Method Details

#read(str) ⇒ RRSection

Read RR section from a string

Parameters:

  • str (String)

    binary binary string

Returns:

Since:

  • 1.3.0



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/packetgen/header/dns/rrsection.rb', line 26

def read(str)
  clear
  return self if str.nil?

  str = str.b unless str.encoding == Encoding::BINARY
  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