Class: Dnsruby::Name

### Home Classes Methods

### In Files

- lib/Dnsruby/name.rb

### Parent

Object

### Namespace

- CLASS Dnsruby::Name::Label

### Methods

- ::create
- ::split
- #<=>
- #absolute?
- #canonical
- #canonically_before
- #downcase
- #subdomain_of?
- #to_s
- #wild?

### Included Modules

- Comparable

### Files

- DNSSEC
- EVENTMACHINE
- EXAMPLES
- README

### Class/Module Index

Quicksearch

- Dnsruby
- Dnsruby::Algorithms
- Dnsruby::Classes
- Dnsruby::CodeMapper
- Dnsruby::Config
- Dnsruby::DNS
- Dnsruby::DecodeError
- Dnsruby::Dnssec
- Dnsruby::Dnssec::ValidationPolicy
- Dnsruby::EncodeError
- Dnsruby::ExtendedRCode
- Dnsruby::FormErr
- Dnsruby::Header
- Dnsruby::Hosts
- Dnsruby::IPv4
- Dnsruby::IPv6
- Dnsruby::Message
- Dnsruby::Message::Section
- Dnsruby::Message::SecurityLevel
- Dnsruby::MetaTypes
- Dnsruby::Modes
- Dnsruby::NXDomain
- Dnsruby::NXRRSet
- Dnsruby::Name
- Dnsruby::Name::Label
- Dnsruby::NotAuth
- Dnsruby::NotImp
- Dnsruby::NotZone
- Dnsruby::Nsec3HashAlgorithms
- Dnsruby::OpCode
- Dnsruby::OtherResolvError
- Dnsruby::QTypes
- Dnsruby::Question
- Dnsruby::RCode
- Dnsruby::RR
- Dnsruby::RR::ANY
- Dnsruby::RR::CERT
- Dnsruby::RR::CERT::CertificateTypes
- Dnsruby::RR::CNAME
- Dnsruby::RR::DHCID
- Dnsruby::RR::DLV
- Dnsruby::RR::DNAME
- Dnsruby::RR::DNSKEY
- Dnsruby::RR::DS
- Dnsruby::RR::DS::DigestTypes
- Dnsruby::RR::DomainName
- Dnsruby::RR::Generic
- Dnsruby::RR::HINFO
- Dnsruby::RR::HIP
- Dnsruby::RR::IN
- Dnsruby::RR::IN::A
- Dnsruby::RR::IN::AAAA
- Dnsruby::RR::IN::AFSDB
- Dnsruby::RR::IN::PX
- Dnsruby::RR::IN::SRV
- Dnsruby::RR::IN::WKS
- Dnsruby::RR::IPSECKEY
- Dnsruby::RR::ISDN
- Dnsruby::RR::KX
- Dnsruby::RR::LOC
- Dnsruby::RR::MB
- Dnsruby::RR::MG
- Dnsruby::RR::MINFO
- Dnsruby::RR::MR
- Dnsruby::RR::MX
- Dnsruby::RR::NAPTR
- Dnsruby::RR::NS
- Dnsruby::RR::NSAP
- Dnsruby::RR::NSEC
- Dnsruby::RR::NSEC3
- Dnsruby::RR::NSEC3PARAM
- Dnsruby::RR::OPT
- Dnsruby::RR::PTR
- Dnsruby::RR::RP
- Dnsruby::RR::RRSIG
- Dnsruby::RR::RT
- Dnsruby::RR::SOA
- Dnsruby::RR::SPF
- Dnsruby::RR::SSHFP
- Dnsruby::RR::SSHFP::Algorithms
- Dnsruby::RR::SSHFP::FpTypes
- Dnsruby::RR::TKEY
- Dnsruby::RR::TSIG
- Dnsruby::RR::TXT
- Dnsruby::RR::X25
- Dnsruby::RRSet
- Dnsruby::Recursor
- Dnsruby::Refused
- Dnsruby::Resolv
- Dnsruby::ResolvError
- Dnsruby::ResolvTimeout
- Dnsruby::Resolver
- Dnsruby::Resolver::EventType
- Dnsruby::SelectThread
- Dnsruby::ServFail
- Dnsruby::SingleResolver
- Dnsruby::TheLog
- Dnsruby::TsigError
- Dnsruby::TsigNotSignedResponseError
- Dnsruby::Types
- Dnsruby::Update
- Dnsruby::VerifyError
- Dnsruby::YXDomain
- Dnsruby::YXRRSet
- Dnsruby::ZoneReader
- Dnsruby::ZoneReader::ParseException
- Dnsruby::ZoneSerialError
- Dnsruby::ZoneTransfer
- Dnsruby::ZoneTransfer::Delta
- Base32

No matching classes.

# Dnsruby::Name

## 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

### Constants

MaxNameLength

### Attributes

labels[RW]

### Public Class Methods

create(arg) click to toggle source

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

- Name | returns `arg`

- String | returns a new Name

    # File lib/Dnsruby/name.rb, line 43
    def self.create(arg)
      case arg
      when Name
        return Name.new(arg.labels, arg.absolute?)
      when String
        #        arg.gsub!(/\.$/o, "")
        if (arg==".")
          return Name.new([],true)
        end
        if (arg=="")
          return Name.new([],false)
        end
        return Name.new(split_escaped(arg), /\.\z/ =~ arg ? true : false)
        #        return Name.new(Label.split(arg), /\.\z/ =~ arg ? true : false)
      when Array
        return Name.new(arg, /\.\z/ =~ (arg.last ? ((arg.last.kind_of?String)?arg.last : arg.last.string) : arg.last) ? true : false)
      else
        raise ArgumentError.new("cannot interpret as DNS name: #{arg.inspect}")
      end
    end

split(name) click to toggle source

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

### Public Instance Methods

<=>(other) click to toggle source

    # File lib/Dnsruby/name.rb, line 135
    def <=>(other)
      # return -1 if other less than us, +1 if greater than us
      return 0 if (canonical == other.canonical)
      if (canonically_before(other))
        return +1
      end
      return -1
    end

absolute?() click to toggle source

Returns true if this Name is absolute

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

canonical() click to toggle source

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

    # File lib/Dnsruby/name.rb, line 127
    def canonical
      #
      return MessageEncoder.new {|msg|
        msg.put_name(self, true)
      }.to_s

    end

canonically_before(n) click to toggle source

    # File lib/Dnsruby/name.rb, line 144
    def canonically_before(n)
      if (!(Name === n))
        n = Name.create(n)
      end
      # Work out whether this name is canonically before the passed Name
      # RFC 4034 section 6.1
      # For the purposes of DNS security, owner names are ordered by treating
      #individual labels as unsigned left-justified octet strings.  The
      #absence of a octet sorts before a zero value octet, and uppercase
      #US-ASCII letters are treated as if they were lowercase US-ASCII
      #letters.
      #To compute the canonical ordering of a set of DNS names, start by
      #sorting the names according to their most significant (rightmost)
      #labels.  For names in which the most significant label is identical,
      #continue sorting according to their next most significant label, and
      #so forth.

      # Get the list of labels for both names, and then swap them
      my_labels = @labels.reverse
      other_labels = n.labels.reverse
      my_labels.each_index {|i|
        if (!other_labels[i])
          return false
        end
        next if (other_labels[i].downcase == my_labels[i].downcase)
        return (my_labels[i].downcase < other_labels[i].downcase)
      }
      return true
    end

downcase() click to toggle source

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

subdomain_of?(other) click to toggle source

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

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

to_s(include_absolute=false) click to toggle source

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"

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

wild?() click to toggle source

Is this name a wildcard?

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

[Validate]

Generated with the Darkfish Rdoc Generator 2.