Class: DNSSD::Reply
- Inherits:
-
Object
- Object
- DNSSD::Reply
- Defined in:
- lib/dnssd/reply.rb
Overview
DNSSD::Reply is used to return information
Defined Under Namespace
Classes: AddrInfo, Browse, Domain, QueryRecord, Register, Resolve
Instance Attribute Summary collapse
-
#flags ⇒ Object
readonly
Flags for this reply, see DNSSD::Flags.
-
#interface ⇒ Object
readonly
The interface name for this reply.
-
#service ⇒ Object
readonly
The DNSSD::Service that created this reply.
Instance Method Summary collapse
-
#fullname ⇒ Object
The full service domain name, see DNSS::Service#fullname.
-
#initialize(service, flags, interface) ⇒ Reply
constructor
Creates a new reply attached to
service
withflags
on interface indexinterface
. -
#inspect ⇒ Object
:nodoc:.
-
#interface_name ⇒ Object
Expands the name of the interface including constants.
-
#protocol ⇒ Object
Protocol of this service.
-
#service_name ⇒ Object
Service name as in Socket.getservbyname.
-
#set_fullname(fullname) ⇒ Object
Sets #name, #type and #domain from
fullname
. -
#set_names(name, type, domain) ⇒ Object
Sets #name, #type and #domain.
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
#flags ⇒ Object (readonly)
Flags for this reply, see DNSSD::Flags
9 10 11 |
# File 'lib/dnssd/reply.rb', line 9 def flags @flags end |
#interface ⇒ Object (readonly)
The interface name for this reply
14 15 16 |
# File 'lib/dnssd/reply.rb', line 14 def interface @interface end |
#service ⇒ Object (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
#fullname ⇒ Object
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 |
#inspect ⇒ Object
: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_name ⇒ Object
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 |
#protocol ⇒ Object
Protocol of this service
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_name ⇒ Object
Service name as in Socket.getservbyname
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 |