class DNSSD::Reply

DNSSD::Reply is used to return information

Attributes

flags[R]

Flags for this reply, see DNSSD::Flags

interface[R]

The interface name for this reply

service[R]

The DNSSD::Service that created this reply

Public Class Methods

new(service, flags, interface) click to toggle source

Creates a new reply attached to service with flags on interface index interface

# File lib/dnssd/reply.rb, line 25
def initialize(service, flags, interface)
  @service = service
  @flags = DNSSD::Flags.new flags
  @interface = if interface then
                 interface > 0 ? DNSSD.interface_name(interface) : interface
               end
end

Public Instance Methods

fullname() click to toggle source

The full service domain name, see DNSS::Service#fullname

# File lib/dnssd/reply.rb, line 36
def fullname
  fullname = DNSSD::Service.fullname @name.gsub("\032", ' '), @type, @domain
  fullname << '.' unless fullname =~ /\.$/
  fullname
end
interface_name() click to toggle source

Expands the name of the interface including constants

# File lib/dnssd/reply.rb, line 51
def interface_name
  case @interface
  when nil                       then 'nil'
  when DNSSD::InterfaceAny       then 'any'
  when DNSSD::InterfaceLocalOnly then 'local'
  when DNSSD::InterfaceUnicast   then 'unicast'
  else @interface
  end
end
protocol() click to toggle source

Protocol of this service

# File lib/dnssd/reply.rb, line 64
def protocol
  raise TypeError, 'no type on this reply' unless
    instance_variable_defined? :@type

  @type.split('.').last.sub '_', ''
end
service_name() click to toggle source

Service name as in Socket.getservbyname

# File lib/dnssd/reply.rb, line 74
def service_name
  raise TypeError, 'no type on this reply' unless
    instance_variable_defined? :@type

  @type.split('.').first.sub '_', ''
end
set_fullname(fullname) click to toggle source

Sets name, type and domain from fullname

# File lib/dnssd/reply.rb, line 84
def set_fullname(fullname)
  fullname = fullname.gsub(/\([0-9]{1,3})/) do $1.to_i.chr end
  fullname = fullname.scan(/(?:[^\.]|\\.)+/).map do |part|
    part.gsub "\\.", '.'
  end

  @name   = fullname[0]
  @type   = fullname[1, 2].join '.'
  @domain = fullname[3..-1].map { |part| part.sub '.', '\.' }.join('.') + '.'
end
set_names(name, type, domain) click to toggle source

Sets name, type and domain

# File lib/dnssd/reply.rb, line 98
def set_names(name, type, domain)
  set_fullname [name, type, domain].join('.')
end