Class: DNS::ResourceRecord

Inherits:
Object
  • Object
show all
Defined in:
lib/faildns/resourcerecord.rb,
lib/faildns/resourcerecord/IN/A.rb,
lib/faildns/resourcerecord/data.rb,
lib/faildns/resourcerecord/IN/MX.rb,
lib/faildns/resourcerecord/IN/NS.rb,
lib/faildns/resourcerecord/IN/PTR.rb,
lib/faildns/resourcerecord/IN/SOA.rb,
lib/faildns/resourcerecord/IN/TXT.rb,
lib/faildns/resourcerecord/IN/AAAA.rb,
lib/faildns/resourcerecord/IN/NULL.rb,
lib/faildns/resourcerecord/IN/CNAME.rb,
lib/faildns/resourcerecord/IN/HINFO.rb

Overview

– The answer, authority, and additional sections all share the same format: a variable number of resource records, where the number of records is specified in the corresponding count field in the header. Each resource record has the following format:

                                1  1  1  1  1  1
  0  1  2  3  4  5  6  7  8  9  0  1  2  3  4  5
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|                                               |
/                                               /
/                      NAME                     /
|                                               |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|                      TYPE                     |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|                     CLASS                     |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|                      TTL                      |
|                                               |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
|                   RDLENGTH                    |
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--|
/                     RDATA                     /
/                                               /
+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+

where:

NAME a domain name to which this resource record pertains.

TYPE two octets containing one of the RR type codes. This

field specifies the meaning of the data in the RDATA
field.

CLASS two octets which specify the class of the data in the

RDATA field.

TTL a 32 bit unsigned integer that specifies the time

interval (in seconds) that the resource record may be
cached before it should be discarded.  Zero values are
interpreted to mean that the RR can only be used for the
transaction in progress, and should not be cached.

RDLENGTH an unsigned 16 bit integer that specifies the length in

octets of the RDATA field.

RDATA a variable length string of octets that describes the

resource.  The format of this information varies
according to the TYPE and CLASS of the resource record.
For example, the if the TYPE is A and the CLASS is IN,
the RDATA field is a 4 octet ARPA Internet address.

++

Defined Under Namespace

Modules: IN Classes: Data

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(what = {}) ⇒ ResourceRecord

Returns a new instance of ResourceRecord.



108
109
110
111
112
113
114
115
116
117
118
# File 'lib/faildns/resourcerecord.rb', line 108

def initialize (what={})
  if !what.is_a? Hash
    raise ArgumentError.new('You have to pass a Hash.')
  end

  @data = what

  if block_given?
    yield self
  end
end

Class Method Details

.length(string) ⇒ Object



102
103
104
105
106
# File 'lib/faildns/resourcerecord.rb', line 102

def self.length (string)
  string.force_encoding 'BINARY'

  (tmp = DomainName.length(string) + Type.length + Class.length + 4) + string[tmp, 2].unpack('n').first + 2
end

.parse(string, original) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/faildns/resourcerecord.rb', line 78

def self.parse (string, original)
  string.force_encoding 'BINARY'

  ResourceRecord.new {|r|
    r.name  = DomainName.parse(string, original)
    r.type  = Type.parse(string)
    r.class = Class.parse(string)

    r.ttl = string.unpack('N').first; string[0, 4] = ''

    r.length = string.unpack('n').first; string[0, 2] = ''
    r.data   = ResourceRecord.const_get(r.class.to_sym).const_get(r.type.to_sym) rescue nil

    if !r.data
      r.data = ResourceRecord.const_get(r.class.to_sym).const_get(:NULL)
      DNS.debug "ResourceRecord::#{r.class}::#{r.type} not found."
    end

    DNS.debug r.data.inspect, { :level => 2 }
    
    r.data = r.data.parse(string, r.length, original)
  }
end

Instance Method Details

#classObject



122
# File 'lib/faildns/resourcerecord.rb', line 122

def class;  @data[:CLASS]    end

#class=(val) ⇒ Object



129
# File 'lib/faildns/resourcerecord.rb', line 129

def class= (val);  @data[:CLASS]    = Class.new(val)      end

#dataObject



125
# File 'lib/faildns/resourcerecord.rb', line 125

def data;   @data[:RDATA]    end

#data=(val) ⇒ Object



132
# File 'lib/faildns/resourcerecord.rb', line 132

def data= (val);   @data[:RDATA]    = val                 end

#lengthObject



124
# File 'lib/faildns/resourcerecord.rb', line 124

def length; @data[:RDLENGTH] end

#length=(val) ⇒ Object



131
# File 'lib/faildns/resourcerecord.rb', line 131

def length= (val); @data[:RDLENGTH] = val                 end

#nameObject



120
# File 'lib/faildns/resourcerecord.rb', line 120

def name;   @data[:NAME]     end

#name=(val) ⇒ Object



127
# File 'lib/faildns/resourcerecord.rb', line 127

def name= (val);   @data[:NAME]     = DomainName.new(val) end

#packObject



134
135
136
137
# File 'lib/faildns/resourcerecord.rb', line 134

def pack
  self.name.pack + self.type.pack + self.class.pack + [self.ttl].pack('N') +
  [self.length].pack('n') + self.data.pack
end

#ttlObject



123
# File 'lib/faildns/resourcerecord.rb', line 123

def ttl;    @data[:TTL]      end

#ttl=(val) ⇒ Object



130
# File 'lib/faildns/resourcerecord.rb', line 130

def ttl= (val);    @data[:TTL]      = val                 end

#typeObject



121
# File 'lib/faildns/resourcerecord.rb', line 121

def type;   @data[:TYPE]     end

#type=(val) ⇒ Object



128
# File 'lib/faildns/resourcerecord.rb', line 128

def type= (val);   @data[:TYPE]     = Type.new(val)       end