Class Dnsruby::Name
In: lib/Dnsruby/name.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

Dnsruby::Name class

A representation of a DNS name (RFC1035, section 3.1)

methods

  • Name::create(namestring)
  • Name#absolute?
  • Name#wild?
  • Name#subdomain_of?(other)
  • Name#labels

Methods

Included Modules

Comparable

Classes and Modules

Class Dnsruby::Name::Label

Constants

MaxNameLength = 255

External Aliases

== -> eql?

Attributes

labels  [RW] 

Public Class methods

Creates a new Dnsruby::Name from arg. arg can be :

  • Name:: returns arg
  • String:: returns a new Name

[Source]

    # File lib/Dnsruby/name.rb, line 43
43:     def self.create(arg)
44:       case arg
45:       when Name
46:         return Name.new(arg.labels, arg.absolute?)
47:       when String
48:         #        arg.gsub!(/\.$/o, "")
49:         if (arg==".")
50:           return Name.new([],true)
51:         end
52:         if (arg=="")
53:           return Name.new([],false)
54:         end
55:         return Name.new(split_escaped(arg), /\.\z/ =~ arg ? true : false)
56:         #        return Name.new(Label.split(arg), /\.\z/ =~ arg ? true : false)
57:       when Array
58:         return Name.new(arg, /\.\z/ =~ (arg.last ? ((arg.last.kind_of?String)?arg.last : arg.last.string) : arg.last) ? true : false)
59:       else        
60:         raise ArgumentError.new("cannot interpret as DNS name: #{arg.inspect}")
61:       end
62:     end

[Source]

    # File lib/Dnsruby/name.rb, line 69
69:     def self.split(name)
70:       encodedlabels = name2encodedlabels(name)
71:       labels = encodedlabels.each  {|el| Name.decode(el.to_s)}
72:       return labels
73:     end

Public Instance methods

[Source]

     # File lib/Dnsruby/name.rb, line 135
135:     def <=>(other)
136:       # return -1 if other less than us, +1 if greater than us
137:       return 0 if (canonical == other.canonical)
138:       if (canonically_before(other))
139:         return +1
140:       end
141:       return -1
142:     end

Returns true if this Name is absolute

[Source]

     # File lib/Dnsruby/name.rb, line 105
105:     def absolute?
106:       return @absolute
107:     end

Return the canonical form of this name (RFC 4034 section 6.2)

[Source]

     # File lib/Dnsruby/name.rb, line 127
127:     def canonical
128:       #
129:       return MessageEncoder.new {|msg|
130:         msg.put_name(self, true)
131:       }.to_s
132: 
133:     end

[Source]

     # File lib/Dnsruby/name.rb, line 144
144:     def canonically_before(n)
145:       if (!(Name === n))
146:         n = Name.create(n)
147:       end
148:       # Work out whether this name is canonically before the passed Name
149:       # RFC 4034 section 6.1
150:       # For the purposes of DNS security, owner names are ordered by treating
151:       #individual labels as unsigned left-justified octet strings.  The
152:       #absence of a octet sorts before a zero value octet, and uppercase
153:       #US-ASCII letters are treated as if they were lowercase US-ASCII
154:       #letters.
155:       #To compute the canonical ordering of a set of DNS names, start by
156:       #sorting the names according to their most significant (rightmost)
157:       #labels.  For names in which the most significant label is identical,
158:       #continue sorting according to their next most significant label, and
159:       #so forth.
160: 
161:       # Get the list of labels for both names, and then swap them
162:       my_labels = @labels.reverse
163:       other_labels = n.labels.reverse
164:       my_labels.each_index {|i|
165:         if (!other_labels[i])
166:           return false
167:         end
168:         next if (other_labels[i].downcase == my_labels[i].downcase)
169:         return (my_labels[i].downcase < other_labels[i].downcase)
170:       }
171:       return true
172:     end

[Source]

    # File lib/Dnsruby/name.rb, line 94
94:     def downcase
95:       labels = []
96:       @labels.each do |label| labels << Label.new(label.downcase) end
97:       return Name.new(labels)
98:     end

Tests subdomain-of relation : returns true if this name is a subdomain of other.

  domain = Resolv::Name.create("y.z")
  p Resolv::Name.create("w.x.y.z").subdomain_of?(domain) #=> true
  p Resolv::Name.create("x.y.z").subdomain_of?(domain) #=> true
  p Resolv::Name.create("y.z").subdomain_of?(domain) #=> false
  p Resolv::Name.create("z").subdomain_of?(domain) #=> false
  p Resolv::Name.create("x.y.z.").subdomain_of?(domain) #=> false
  p Resolv::Name.create("w.z").subdomain_of?(domain) #=> false

[Source]

     # File lib/Dnsruby/name.rb, line 190
190:     def subdomain_of?(other)
191:       raise ArgumentError, "not a domain name: #{other.inspect}" unless Name === other
192:       return false if @absolute != other.absolute?
193:       other_len = other.length
194:       return false if @labels.length <= other_len
195:       return @labels[-other_len, other_len] == other.to_a
196:     end

returns the domain name as a string.

The domain name doesn‘t have a trailing dot even if the name object is absolute.

Example :

  p Resolv::Name.create("x.y.z.").to_s #=> "x.y.z"
  p Resolv::Name.create("x.y.z").to_s #=> "x.y.z"

[Source]

     # File lib/Dnsruby/name.rb, line 224
224:     def to_s(include_absolute=false)
225:       ret = to_str(@labels)
226:       if (@absolute && include_absolute)
227:         ret += "."
228:       end
229:       return ret
230:     end

Is this name a wildcard?

[Source]

     # File lib/Dnsruby/name.rb, line 119
119:     def wild?
120:       if (labels.length == 0)
121:         return false
122:       end
123:       return (labels[0].string == '*')
124:     end

[Validate]