Class Dnsruby::RR
In: lib/Dnsruby/resource/DS.rb
lib/Dnsruby/resource/RP.rb
lib/Dnsruby/resource/ISDN.rb
lib/Dnsruby/resource/LOC.rb
lib/Dnsruby/resource/CERT.rb
lib/Dnsruby/resource/KX.rb
lib/Dnsruby/resource/SPF.rb
lib/Dnsruby/resource/MINFO.rb
lib/Dnsruby/resource/IPSECKEY.rb
lib/Dnsruby/resource/NSAP.rb
lib/Dnsruby/resource/AFSDB.rb
lib/Dnsruby/resource/generic.rb
lib/Dnsruby/resource/SOA.rb
lib/Dnsruby/resource/domain_name.rb
lib/Dnsruby/resource/A.rb
lib/Dnsruby/resource/HINFO.rb
lib/Dnsruby/resource/DNSKEY.rb
lib/Dnsruby/resource/IN.rb
lib/Dnsruby/resource/X25.rb
lib/Dnsruby/resource/resource.rb
lib/Dnsruby/resource/NSEC.rb
lib/Dnsruby/resource/TKEY.rb
lib/Dnsruby/resource/RRSIG.rb
lib/Dnsruby/resource/TSIG.rb
lib/Dnsruby/resource/AAAA.rb
lib/Dnsruby/resource/MX.rb
lib/Dnsruby/resource/DHCID.rb
lib/Dnsruby/resource/SSHFP.rb
lib/Dnsruby/resource/NAPTR.rb
lib/Dnsruby/resource/NSEC3PARAM.rb
lib/Dnsruby/resource/TXT.rb
lib/Dnsruby/resource/RT.rb
lib/Dnsruby/resource/DLV.rb
lib/Dnsruby/resource/OPT.rb
lib/Dnsruby/resource/HIP.rb
lib/Dnsruby/resource/SRV.rb
lib/Dnsruby/resource/NSEC3.rb
lib/Dnsruby/resource/PX.rb
Parent: Object
Message Update ResolvError EncodeError OtherResolvError ServFail FormErr DecodeError NXRRSet YXDomain NotImp NXDomain VerifyError NotAuth YXRRSet NotZone Refused TsigError CodeMapper Types MetaTypes QTypes Nsec3HashAlgorithms Algorithms OpCode Classes ExtendedRCode Modes RCode Comparable Name RRSet TsigNotSignedResponseError Resolver SingleResolver StandardError TimeoutError ResolvTimeout DNS Dnssec Hosts RR\n[lib/Dnsruby/resource/A.rb\nlib/Dnsruby/resource/AAAA.rb\nlib/Dnsruby/resource/AFSDB.rb\nlib/Dnsruby/resource/CERT.rb\nlib/Dnsruby/resource/DHCID.rb\nlib/Dnsruby/resource/DLV.rb\nlib/Dnsruby/resource/DNSKEY.rb\nlib/Dnsruby/resource/DS.rb\nlib/Dnsruby/resource/HINFO.rb\nlib/Dnsruby/resource/HIP.rb\nlib/Dnsruby/resource/IN.rb\nlib/Dnsruby/resource/IPSECKEY.rb\nlib/Dnsruby/resource/ISDN.rb\nlib/Dnsruby/resource/KX.rb\nlib/Dnsruby/resource/LOC.rb\nlib/Dnsruby/resource/MINFO.rb\nlib/Dnsruby/resource/MX.rb\nlib/Dnsruby/resource/NAPTR.rb\nlib/Dnsruby/resource/NSAP.rb\nlib/Dnsruby/resource/NSEC.rb\nlib/Dnsruby/resource/NSEC3.rb\nlib/Dnsruby/resource/NSEC3PARAM.rb\nlib/Dnsruby/resource/OPT.rb\nlib/Dnsruby/resource/PX.rb\nlib/Dnsruby/resource/RP.rb\nlib/Dnsruby/resource/RRSIG.rb\nlib/Dnsruby/resource/RT.rb\nlib/Dnsruby/resource/SOA.rb\nlib/Dnsruby/resource/SPF.rb\nlib/Dnsruby/resource/SRV.rb\nlib/Dnsruby/resource/SSHFP.rb\nlib/Dnsruby/resource/TKEY.rb\nlib/Dnsruby/resource/TSIG.rb\nlib/Dnsruby/resource/TXT.rb\nlib/Dnsruby/resource/X25.rb\nlib/Dnsruby/resource/domain_name.rb\nlib/Dnsruby/resource/generic.rb\nlib/Dnsruby/resource/resource.rb] Recursor IPv6 IPv4 ZoneTransfer MessageDecoder MessageEncoder Question Header TheLog ValidatorThread PacketSender ResolverRuby Config KeyCache Cache SingleVerifier SelectThread Resolv ZoneReader lib/Dnsruby/DNS.rb lib/Dnsruby/dnssec.rb lib/Dnsruby/Hosts.rb lib/Dnsruby/resource/PX.rb lib/Dnsruby/Recursor.rb lib/Dnsruby/update.rb lib/Dnsruby/ipv6.rb lib/Dnsruby/ipv4.rb lib/Dnsruby/code_mapper.rb lib/Dnsruby/zone_transfer.rb lib/Dnsruby/message.rb lib/Dnsruby/TheLog.rb lib/Dnsruby/resource/resource.rb lib/Dnsruby/validator_thread.rb lib/Dnsruby/PacketSender.rb lib/Dnsruby/Resolver.rb lib/Dnsruby/Config.rb lib/Dnsruby/key_cache.rb lib/Dnsruby/Cache.rb lib/Dnsruby/single_verifier.rb lib/Dnsruby/SingleResolver.rb lib/Dnsruby/select_thread.rb lib/Dnsruby/name.rb lib/dnsruby.rb lib/Dnsruby/resource/TKEY.rb lib/Dnsruby/zone_reader.rb Dnsruby dot/m_61_0.png

Superclass for all Dnsruby resource records.

Represents a DNS RR (resource record) [RFC1035, section 3.2]

Use Dnsruby::RR::create(…) to create a new RR record.

   mx = Dnsruby::RR.create("example.com. 7200 MX 10 mailhost.example.com.")

   rr = Dnsruby::RR.create({:name => "example.com", :type => "MX", :ttl => 7200,
                                  :preference => 10, :exchange => "mailhost.example.com"})

   s = rr.to_s # Get a String representation of the RR (in zone file format)
   rr_again = Dnsruby::RR.create(s)

Methods

Classes and Modules

Module Dnsruby::RR::IN
Class Dnsruby::RR::ANY
Class Dnsruby::RR::CERT
Class Dnsruby::RR::CNAME
Class Dnsruby::RR::DHCID
Class Dnsruby::RR::DLV
Class Dnsruby::RR::DNAME
Class Dnsruby::RR::DNSKEY
Class Dnsruby::RR::DS
Class Dnsruby::RR::DomainName
Class Dnsruby::RR::Generic
Class Dnsruby::RR::HINFO
Class Dnsruby::RR::HIP
Class Dnsruby::RR::IPSECKEY
Class Dnsruby::RR::ISDN
Class Dnsruby::RR::KX
Class Dnsruby::RR::LOC
Class Dnsruby::RR::MB
Class Dnsruby::RR::MG
Class Dnsruby::RR::MINFO
Class Dnsruby::RR::MR
Class Dnsruby::RR::MX
Class Dnsruby::RR::NAPTR
Class Dnsruby::RR::NS
Class Dnsruby::RR::NSAP
Class Dnsruby::RR::NSEC
Class Dnsruby::RR::NSEC3
Class Dnsruby::RR::NSEC3PARAM
Class Dnsruby::RR::PTR
Class Dnsruby::RR::RP
Class Dnsruby::RR::RRSIG
Class Dnsruby::RR::RT
Class Dnsruby::RR::SOA
Class Dnsruby::RR::SPF
Class Dnsruby::RR::SSHFP
Class Dnsruby::RR::TKEY
Class Dnsruby::RR::TSIG
Class Dnsruby::RR::TXT
Class Dnsruby::RR::X25

Constants

ClassInsensitiveTypes = { Types::NS => NS, Types::CNAME => CNAME, Types::DNAME => DNAME, Types::DNSKEY => DNSKEY, Types::SOA => SOA, Types::PTR => PTR, Types::HINFO => HINFO, Types::MINFO => MINFO, Types::MX => MX, Types::TXT => TXT, Types::ISDN => ISDN, Types::MB => MB, Types::MG => MG, Types::MR => MR, Types::NAPTR => NAPTR, Types::NSAP => NSAP, Types::OPT => OPT, Types::RP => RP, Types::RT => RT, Types::X25 => X25, Types::KX => KX, Types::SPF => SPF, Types::CERT => CERT, Types::LOC => LOC, Types::TSIG => TSIG, Types::TKEY => TKEY, Types::ANY => ANY, Types::RRSIG => RRSIG, Types::NSEC => NSEC, Types::DS => DS, Types::NSEC3 => NSEC3, Types::NSEC3PARAM => NSEC3PARAM, Types::DLV => DLV, Types::SSHFP => SSHFP, Types::IPSECKEY => IPSECKEY, Types::HIP => HIP, Types::DHCID => DHCID

External Aliases

type -> rr_type

Attributes

klass  [R]  The Resource class
name  [R]  The Resource‘s domain name
rdata  [RW]  The Resource data section
ttl  [RW]  The Resource Time-To-Live
type  [R]  The Resource type

Public Class methods

Create a new RR from the arguments, which can be either a String or a Hash. See new_from_string and new_from_hash for details

   a     = Dnsruby::RR.create("foo.example.com. 86400 A 10.1.2.3")
   mx    = Dnsruby::RR.create("example.com. 7200 MX 10 mailhost.example.com.")
   cname = Dnsruby::RR.create("www.example.com 300 IN CNAME www1.example.com")
   txt   = Dnsruby::RR.create('baz.example.com 3600 HS TXT "text record"')

   rr = Dnsruby::RR.create({:name => "example.com"})
   rr = Dnsruby::RR.create({:name => "example.com", :type => "MX", :ttl => 10,
                                  :preference => 5, :exchange => "mx1.example.com"})

[Source]

     # File lib/Dnsruby/resource/resource.rb, line 630
630:     def RR.create(*args)
631:       if (args.length == 1) && (args[0].class == String)
632:         return new_from_string(args[0])
633:       elsif (args.length == 1) && (args[0].class == Hash)
634:         return new_from_hash(args[0])
635:       else
636:         return new_from_data(args)
637:       end
638:     end

[Source]

     # File lib/Dnsruby/resource/resource.rb, line 640
640:     def self.get_num(bytes)
641:       ret = 0
642:       shift = (bytes.length-1) * 8
643:       bytes.each_byte {|byte|
644:         ret += byte.to_i << shift
645:         shift -= 8
646:       }
647:       return ret
648:     end

Return an array of all the currently implemented RR types

[Source]

     # File lib/Dnsruby/resource/resource.rb, line 485
485:     def RR.implemented_rrs
486:       if (!@@implemented_rr_map)
487:         @@implemented_rr_map = ClassHash.keys.map {|k| Dnsruby::Types.to_string(k[0])}
488:       end
489:       return @@implemented_rr_map
490:     end

Create a new RR from the hash. The name is required; all other fields are optional. Type defaults to ANY and the Class defaults to IN. The TTL defaults to 0.

If the type is specified, then it is necessary to provide ALL of the resource record fields which are specific to that record; i.e. for an MX record, you would need to specify the exchange and the preference

   require 'Dnsruby'
   rr = Dnsruby::RR.new_from_hash({:name => "example.com"})
   rr = Dnsruby::RR.new_from_hash({:name => "example.com", :type => Types.MX, :ttl => 10, :preference => 5, :exchange => "mx1.example.com"})

[Source]

     # File lib/Dnsruby/resource/resource.rb, line 330
330:     def RR.new_from_hash(inhash)
331:       hash = inhash.clone
332:       type = hash[:type] || Types::ANY
333:       klass = hash[:klass] || Classes::IN
334:       ttl = hash[:ttl] || 0
335:       recordclass = get_class(type, klass)
336:       record = recordclass.new
337:       record.name=hash[:name]
338:       if !(record.name.kind_of?Name)
339:         record.name = Name.create(record.name)
340:       end
341:       record.ttl=ttl
342:       record.type = type
343:       record.klass = klass
344:       hash.delete(:name)
345:       hash.delete(:type)
346:       hash.delete(:ttl)
347:       hash.delete(:klass)
348:       record.from_hash(hash)
349:       return record
350:     end

Returns a Dnsruby::RR object of the appropriate type and initialized from the string passed by the user. The format of the string is that used in zone files, and is compatible with the string returned by Net::DNS::RR.inspect

The name and RR type are required; all other information is optional. If omitted, the TTL defaults to 0 and the RR class defaults to IN.

All names must be fully qualified. The trailing dot (.) is optional.

   a     = Dnsruby::RR.new_from_string("foo.example.com. 86400 A 10.1.2.3")
   mx    = Dnsruby::RR.new_from_string("example.com. 7200 MX 10 mailhost.example.com.")
   cname = Dnsruby::RR.new_from_string("www.example.com 300 IN CNAME www1.example.com")
   txt   = Dnsruby::RR.new_from_string('baz.example.com 3600 HS TXT "text record"')

[Source]

     # File lib/Dnsruby/resource/resource.rb, line 369
369:     def RR.new_from_string(rrstring)
370:       # strip out comments
371:       # Test for non escaped ";" by means of the look-behind assertion
372:       # (the backslash is escaped)
373:       rrstring.gsub!(/(\?<!\\);.*/o, "");
374:       
375:       if ((rrstring =~/#{@@RR_REGEX}/xo) == nil)
376:         raise Exception, "#{rrstring} did not match RR pat.\nPlease report this to the author!\n"
377:       end
378:       
379:       name    = $1;
380:       ttl     = $2.to_i || 0;
381:       rrclass = $3 || '';
382:       
383:       
384:       rrtype  = $4 || '';
385:       rdata   = $5 || '';
386:       
387:       if rdata
388:         rdata.gsub!(/\s+$/o, "")
389:       end
390:       
391:       # RFC3597 tweaks
392:       # This converts to known class and type if specified as TYPE###
393:       if rrtype  =~/^TYPE\d+/o
394:         rrtype  = Dnsruby::Types.typesbyval(Dnsruby::Types::typesbyname(rrtype))
395:       end
396:       if rrclass =~/^CLASS\d+/o
397:         rrclass = Dnsruby::Classes.classesbyval(Dnsruby::Classes::classesbyname(rrclass))
398:       end
399:       
400:       
401:       if (rrtype=='' && rrclass && rrclass == 'ANY')
402:         rrtype  = 'ANY';
403:         rrclass = 'IN';
404:       elsif (rrclass=='')
405:         rrclass = 'IN';
406:       end
407:       
408:       if (rrtype == '')
409:         rrtype = 'ANY';
410:       end
411: 
412:       if ((rrtype == "NAPTR") || (rrtype == "TXT"))
413:       else
414:         if (rdata)
415:         rdata.gsub!("(", "")
416:         rdata.gsub!(")", "")
417:         end
418:       end
419:       
420:       if (implemented_rrs.include?(rrtype) && rdata !~/^\s*\\#/o )
421:         subclass = _get_subclass(name, rrtype, rrclass, ttl, rdata)
422:         return subclass
423:       elsif (implemented_rrs.include?(rrtype))   # A known RR type starting with \#
424:         rdata =~ /\\\#\s+(\d+)\s+(.*)$/o;
425:         
426:         rdlength = $1.to_i;
427:         hexdump  = $2;
428:         hexdump.gsub!(/\s*/, "");
429:         
430:         if hexdump.length() != rdlength*2
431:           raise Exception, "#{rdata} is inconsistent; length does not match content"
432:         end
433:         
434:         rdata = [hexdump].pack('H*');
435:         
436:         return new_from_data(name, rrtype, rrclass, ttl, rdlength, rdata, 0) # rdata.length() - rdlength);
437:       elsif (rdata=~/\s*\\\#\s+\d+\s+/o)
438:         #We are now dealing with the truly unknown.
439:         raise Exception, 'Expected RFC3597 representation of RDATA' unless rdata =~/\\\#\s+(\d+)\s+(.*)$/o;
440:         
441:         rdlength = $1.to_i;
442:         hexdump  = $2;
443:         hexdump.gsub!(/\s*/o, "");
444:         
445:         if hexdump.length() != rdlength*2
446:           raise Exception, "#{rdata} is inconsistent; length does not match content" ;
447:         end
448:         
449:         rdata = [hexdump].pack('H*');
450:         
451:         return new_from_data(name,rrtype,rrclass,ttl,rdlength,rdata,0) # rdata.length() - rdlength);
452:       else
453:         #God knows how to handle these...
454:         subclass = _get_subclass(name, rrtype, rrclass, ttl, "")
455:         return subclass
456:       end
457:     end

Public Instance methods

[Source]

     # File lib/Dnsruby/resource/resource.rb, line 538
538:     def ==(other)
539:       return false unless self.class == other.class
540:       ivars = self.instance_variables
541:       s_ivars = []
542:       ivars.each {|i| s_ivars << i.to_s} # Ruby 1.9
543:       s_ivars.delete "@ttl" # RFC 2136 section 1.1
544:       s_ivars.delete "@rdata"
545:       if (self.type == Types.DS)
546:         s_ivars.delete "@digest"
547:       end
548:       s_ivars.sort!
549:       
550:       ivars = other.instance_variables
551:       o_ivars = []
552:       ivars.each {|i| o_ivars << i.to_s} # Ruby 1.9
553:       o_ivars.delete "@ttl" # RFC 2136 section 1.1
554:       o_ivars.delete "@rdata"
555:       if (other.type == Types.DS)
556:         o_ivars.delete "@digest"
557:       end
558:       o_ivars.sort!
559:       
560:       return s_ivars == o_ivars &&
561:         s_ivars.collect {|name| self.instance_variable_get name} ==
562:         o_ivars.collect {|name| other.instance_variable_get name}
563:     end

[Source]

     # File lib/Dnsruby/resource/resource.rb, line 263
263:     def clone
264:       MessageDecoder.new(MessageEncoder.new {|msg|
265:           msg.put_rr(self, true)}.to_s) {|msg|
266:         r = msg.get_rr
267:         return r
268:       }
269: 
270:     end

[Source]

     # File lib/Dnsruby/resource/resource.rb, line 287
287:     def init_defaults
288:       # Default to do nothing
289:     end

[Source]

     # File lib/Dnsruby/resource/resource.rb, line 251
251:     def klass=(klass)
252:       if (@type != Types::OPT)
253:         @klass= Classes.new(klass)
254:       else
255:         if (klass.class == Classes)
256:           @klass = klass
257:         else
258:           @klass = Classes.new("CLASS#{klass}")
259:         end
260:       end
261:     end

[Source]

     # File lib/Dnsruby/resource/resource.rb, line 238
238:     def name=(newname)
239:       if (!(newname.kind_of?Name))
240:         @name=Name.create(newname)
241:       else
242:         @name = newname
243:       end
244:     end

Get a string representation of the data section of the RR (in zone file format)

[Source]

     # File lib/Dnsruby/resource/resource.rb, line 510
510:     def rdata_to_string
511:       if (@rdata && @rdata.length > 0)
512:         return @rdata
513:       else
514:         return "no rdata"
515:       end
516:     end

[Source]

     # File lib/Dnsruby/resource/resource.rb, line 234
234:     def rdlength
235:       return rdata.length
236:     end

Determines if two Records could be part of the same RRset. This compares the name, type, and class of the Records; the ttl and rdata are not compared.

[Source]

     # File lib/Dnsruby/resource/resource.rb, line 275
275:     def sameRRset(rec)
276:       if (@klass != rec.klass || @name.downcase != rec.name.downcase)
277:         return false
278:       end
279:       [rec, self].each { |rr|
280:         if (rr.type == Types::RRSIG)
281:           return ((@type == rr.type_covered) || (rec.type == rr.type_covered))
282:         end
283:       }
284:       return (@type == rec.type)
285:     end

Returns a string representation of the RR in zone file format

[Source]

     # File lib/Dnsruby/resource/resource.rb, line 505
505:     def to_s
506:       return (@name ? @name.to_s(true):"") + "\t" +(@ttl ? @ttl.to_s():"") + "\t" + (klass() ? klass.to_s():"") + "\t" + (type() ? type.to_s():"") + "\t" + rdata_to_string
507:     end

[Source]

     # File lib/Dnsruby/resource/resource.rb, line 246
246:     def type=(type)
247:       @type = Types.new(type)
248:     end

[Validate]