Class: DNSSD::Reply

Inherits:
Object
  • Object
show all
Defined in:
lib/dnssd/reply.rb

Overview

DNSSD::Reply is used to return information

Direct Known Subclasses

AddrInfo, Browse, Domain, QueryRecord, Register, Resolve

Defined Under Namespace

Classes: AddrInfo, Browse, Domain, QueryRecord, Register, Resolve

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(service, flags, interface) ⇒ Reply

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



25
26
27
28
29
30
31
# 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

Instance Attribute Details

#flagsObject (readonly)

Flags for this reply, see DNSSD::Flags



9
10
11
# File 'lib/dnssd/reply.rb', line 9

def flags
  @flags
end

#interfaceObject (readonly)

The interface name for this reply



14
15
16
# File 'lib/dnssd/reply.rb', line 14

def interface
  @interface
end

#serviceObject (readonly)

The DNSSD::Service that created this reply



19
20
21
# File 'lib/dnssd/reply.rb', line 19

def service
  @service
end

Instance Method Details

#fullnameObject

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



36
37
38
39
40
# File 'lib/dnssd/reply.rb', line 36

def fullname
  fullname = DNSSD::Service.fullname @name.gsub("\032", ' '), @type, @domain
  fullname << '.' unless fullname =~ /\.$/
  fullname
end

#inspectObject

:nodoc:



42
43
44
45
46
# File 'lib/dnssd/reply.rb', line 42

def inspect # :nodoc:
  "#<%s:0x%x interface: %s flags: %p>" % [
    self.class, object_id, interface_name, @flags
  ]
end

#interface_nameObject

Expands the name of the interface including constants



51
52
53
54
55
56
57
58
59
# 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

#protocolObject

Protocol of this service

Raises:

  • (TypeError)


64
65
66
67
68
69
# 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_nameObject

Service name as in Socket.getservbyname

Raises:

  • (TypeError)


74
75
76
77
78
79
# 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) ⇒ Object

Sets #name, #type and #domain from fullname



84
85
86
87
88
89
90
91
92
93
# 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) ⇒ Object

Sets #name, #type and #domain



98
99
100
# File 'lib/dnssd/reply.rb', line 98

def set_names(name, type, domain)
  set_fullname [name, type, domain].join('.')
end