File: zeroconf.el.html
This package provides an interface to the Avahi, the zeroconf daemon under GNU/Linux. The communication mean with Avahi is D-Bus.
In order to activate this package, you must add the following code into your .emacs:
(require 'zeroconf)
(zeroconf-init "dns-sd.org")
"dns-sd.org" is an example the domain you wish to resolve services
for. It can also be nil or "", which means the default local
domain "local".
The zeroconf-init function installs several handlers, which are
activated by D-Bus signals sent from the Avahi daemon.
Immediately, when a service is added or removed in the domain, a
corresponding handler in Emacs is called.
Service Discovery
-----------------
The main purpose of zeroconf is service discovery. This means, that services are detected as soon as they appear or disappear in a given domain. A service is offered by a network device. It is assigned to a service type.
In order to see all offered service types of the initialized domain, you can call
(zeroconf-list-service-types)
Service types are described at <http://www.dns-sd.org/ServiceTypes.html>. Detected services for a given service type, let's say "_ipp._tcp", are listed by
(zeroconf-list-services "_ipp._tcp")
It is possible to register an own handler (function) to be called when a service has been added or removed in the domain. The service type "_ipp._tcp" is used for printer services supporting the Internet Printing Protocol.
(defun my-add-printer (service)
(message "Printer `%s' detected" (zeroconf-service-name service)))
(defun my-remove-printer (service)
(message "Printer `%s' removed" (zeroconf-service-name service)))
(zeroconf-service-add-hook "_ipp._tcp" :new 'my-add-printer)
(zeroconf-service-add-hook "_ipp._tcp" :removed 'my-remove-printer)
There are several functions returning information about a service,
see the doc string of zeroconf-service-add-hook.
Service Publishing
------------------
The function zeroconf-publish-service publishes a new service to
the Avahi daemon. Although the domain, where to the service is
published, can be specified by this function, it is usually the
default domain "local" (also written as nil or "").
(zeroconf-publish-service
"Example service" ;; Service name.
"_example._tcp" ;; Service type.
nil ;; Default domain ("local").
nil ;; Default host (concat (getenv "HOST") ".local").
111 ;; Port number of the host, the service is offered.
"1.2.3.4" ;; IPv4 address of the host.
'("version=1.0" ;; TXT fields describing the service.
"abc=456"))
The lifetime of a published service is the lifetime of Emacs.
Defined variables (23)
zeroconf-avahi-current-domain | Domain name services are resolved for. |
zeroconf-avahi-domain-unspec | Empty Avahi domain. |
zeroconf-avahi-flags-unspec | No Avahi flags. |
zeroconf-avahi-interface-unspec | Wildcard Avahi interface spec. |
zeroconf-avahi-protocol-inet4 | Avahi INET4 address protocol family. |
zeroconf-avahi-protocol-inet6 | Avahi INET6 address protocol family. |
zeroconf-avahi-protocol-unspec | Wildcard Avahi protocol spec. |
zeroconf-debug | Write messages during service discovery. |
zeroconf-interface-avahi-entry-group | The D-Bus entry group interface exported by Avahi. |
zeroconf-interface-avahi-server | The D-Bus server interface exported by Avahi. |
zeroconf-interface-avahi-service-browser | The D-Bus service browser interface exported by Avahi. |
zeroconf-interface-avahi-service-resolver | The D-Bus service resolver interface exported by Avahi. |
zeroconf-interface-avahi-service-type-browser | The D-Bus service type browser interface exported by Avahi. |
zeroconf-path-avahi | The D-Bus root object path used to talk to Avahi. |
zeroconf-path-avahi-service-browser-hash | The D-Bus object paths used to talk to the Avahi service browser. |
zeroconf-path-avahi-service-resolver-hash | The D-Bus object paths used to talk to the Avahi service resolver. |
zeroconf-path-avahi-service-type-browser | The D-Bus object path used to talk to the Avahi service type browser. |
zeroconf-resolved-services-hash | Hash table of resolved Avahi services. |
zeroconf-service-added-hooks-hash | Hash table of hooks for newly added services. |
zeroconf-service-avahi | The D-Bus name used to talk to Avahi. |
zeroconf-service-removed-hooks-hash | Hash table of hooks for removed services. |
zeroconf-service-type-browser-handler-running | Prevent infinite recursion in ‘zeroconf-service-type-browser-handler’. |
zeroconf-services-hash | Hash table of discovered Avahi services. |