Parent

DNSSD::Reply::QueryRecord

Created by DNSSD::Service#query_record

Attributes

domain[R]

A domain for registration or browsing

name[R]

The service name

record[R]

DNS Record data

record_class[R]

DNS Record class (only IN is supported)

record_type[R]

DNS Record type

ttl[R]

Time-to-live for this record. See #

type[R]

The service type

Public Class Methods

new(service, flags, interface, fullname, record_type, record_class, record, ttl) click to toggle source

Creates a new QueryRecord, called internally by DNSSD::Service#query_record

    # File lib/dnssd/reply/query_record.rb, line 47
47:   def initialize(service, flags, interface, fullname, record_type,
48:                  record_class, record, ttl)
49:     super service, flags, interface
50: 
51:     set_fullname fullname
52: 
53:     @record_type = record_type
54:     @record_class = record_class
55:     @record = record
56: 
57:     @created = Time.now
58:     @ttl = ttl
59:   end

Public Instance Methods

character_string_to_string(character_string) click to toggle source

Converts a RFC 1035 character-string into a ruby String

    # File lib/dnssd/reply/query_record.rb, line 64
64:   def character_string_to_string(character_string)
65:     length = character_string.slice 0
66:     length = length.ord unless Numeric === length
67:     string = character_string.slice 1, length
68: 
69:     if string.length != length then
70:       raise TypeError,
71:         "invalid character string, expected #{length} got #{string.length} in #{@record.inspect}"
72:     end
73: 
74:     string
75:   end
domain_name_to_string(domain_name) click to toggle source

Converts a RFC 1035 domain-name into a ruby String

    # File lib/dnssd/reply/query_record.rb, line 80
80:   def domain_name_to_string(domain_name)
81:     return '.' if domain_name == "\00""
82: 
83:     domain_name = domain_name.dup
84:     string = []
85: 
86:     until domain_name.empty? do
87:       string << character_string_to_string(domain_name)
88:       domain_name.slice! 0, string.last.length + 1
89:     end
90: 
91:     string << nil unless string.last.empty?
92: 
93:     string.join('.')
94:   end
expired?() click to toggle source

Has this QueryRecord passed its TTL?

     # File lib/dnssd/reply/query_record.rb, line 99
 99:   def expired?
100:     Time.now > @created + ttl
101:   end
record_class_name() click to toggle source

Name of this record’s record_class

     # File lib/dnssd/reply/query_record.rb, line 114
114:   def record_class_name
115:     return "unknown #{@record_class}" unless @record_class == DNSSD::Record::IN
116:     'IN' # Only IN is supported
117:   end
record_data() click to toggle source

Decodes output for #, returning the raw record if it can’t be decoded. Handles:

A AAAA CNAME MX NS PTR SOA SRV TXT

     # File lib/dnssd/reply/query_record.rb, line 125
125:   def record_data
126:     return @record unless @record_class == DNSSD::Record::IN
127: 
128:     case @record_type
129:     when DNSSD::Record::A,
130:          DNSSD::Record::AAAA then
131:       IPAddr.new_ntoh @record
132:     when DNSSD::Record::CNAME,
133:          DNSSD::Record::NS,
134:          DNSSD::Record::PTR then
135:       domain_name_to_string @record
136:     when DNSSD::Record::MX then
137:       mx = @record.unpack 'nZ*'
138:       mx[1] = domain_name_to_string mx.last
139:       mx
140:     when DNSSD::Record::SOA then
141:       soa = @record.unpack 'Z*Z*NNNNN'
142:       soa[0] = domain_name_to_string soa[0]
143:       soa[1] = domain_name_to_string soa[1]
144:       soa
145:     when DNSSD::Record::SRV then
146:       srv = @record.unpack 'nnnZ*'
147:       srv[1] = domain_name_to_string srv.last
148:       srv
149:     when DNSSD::Record::TXT then
150:       record = @record.dup
151:       txt = []
152: 
153:       until record.empty? do
154:         txt << character_string_to_string(record)
155:         record.slice! 0, txt.last.length + 1
156:       end
157: 
158:       txt
159:     else
160:       @record
161:     end
162:   end
record_type_name() click to toggle source

Name of this record’s record_type

     # File lib/dnssd/reply/query_record.rb, line 167
167:   def record_type_name
168:     return "unknown #{@record_type} for record class (#{@record_class})" unless
169:       @record_class == DNSSD::Record::IN
170:     DNSSD::Record::VALUE_TO_NAME[@record_type]
171:   end
to_s() click to toggle source

Outputs this record in a BIND-like DNS format

     # File lib/dnssd/reply/query_record.rb, line 176
176:   def to_s
177:     "%s %d %s %s %p" % [
178:       fullname, ttl, record_class_name, record_type_name, record_data
179:     ]
180:   end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.