Hack 78. Advertise Bonjour Services in Linux

Use the Howl toolkit to publish services to Bonjour clients from your Linux box.

If you've already built your own access point [Hack #63], if you have a Windows, Linux, or BSD machine that you use as a server, or if you just want to share your streaming MP3 collection from your laptop, this hack is for you.

5.17.1. Background

Back in September 1999, the Internet Engineering Task Force (IETF) chartered a Zeroconf Working Group. Their purpose was to develop IP protocols for simple network usage similar to what AppleTalk had historically provided on proprietary Apple networks. Based on their work, there are now specifications for several items classified under Zero Configuration Networking:

Figure 5-27. Tracking signal strength for clients of a base station

 

IPv4 Link-Local Addressing

If you've ever seen your computer attempt to get an IP address via DHCP, fail, and assign itself an IP address like 169.254.100.1, you have seen this specification in action. It allows a network device to assign itself a unique address on an ad hoc basis.

 

Multicast DNS

This allows translation between DNS names and IP addresses on the Link-Local Network without the use of a DNS server.

 

DNS Service Discovery

This option lets your computer find services without a directory server or proprietary vendor-based protocol.

Apple Computer released their implementation of Zeroconf specifications in 2002 and called the software Rendezvous. It has been included in all subsequent versions of Mac OSX. As of April 2005, Apple's Zeroconf implemention has been renamed Bonjour as the result of a trademark settlement. You can find much more information and detailed documentation at http://www.zeroconf.org.

Mac OS X users have been able to advertise services on their machines for several years. In addition, most major printer manufacturers support Bonjour device discovery. Apple released an implementation of Bonjour for Windows as well. However, this hack shows how to advertise any service you want using a Bonjour implementation on your Linux box.

To advertise Rendezvous services, you need a Multicast DNS advertiser. Apple has released a Posix implementation, which is adequate, but fairly limited in features. Instead, we're going to use Howl, a cross-platform open source Zeroconf implementation written by the friendly folks at Porchdog Software.

5.17.2. Using Howl

Download the source code for Howl at http://www.porchdogsoft.com/products/howl. This hack won't compile Howl, since both of our example operating systems offer packages of the software.

Ubuntu users can install the necessary packages like so:

	sudo apt-get install howl-utils mdnsresponder libhowl-dev

Fedora Core 3 (or later) users have it even easier, because Howl is included by default. You will need the Howl development libraries, which you can get using yum:

	yum install howl-devel

Mac OSX users can download the source code for Howl and compile it. You'll need to have the Xcode tools installed. Installation instructions can be found at http://www.porchdogsoft.com/products/howl/InstallUnix.html. Alternatively, Howl packages can be installed using Fink, available from http://fink.sourceforge.net. For a graphical method of advertising any service on OSX, see "Advertise Any Service with Bonjour in Mac OS X" [Hack #79].

The configuration for howl is located in /etc/howl/mDNSResponder.conf on Fedora Core, and /etc/mdnsresponder/mDNSResponder.conf in Ubuntu. The sample .conf file has a couple commented out lines that show the parameters required:

	[Name] [Service type] [Domain] [Port] [Text]

The first argument, Name, is the name of the service that users will see advertised. The name should be a descriptive name and should be enclosed in double quotes if there are any spaces.

The Service type field is a little tricky. It takes the following form, where service is a well-known IANA service name (i.e., something out of /etc/services, such as http) and transport is the actual transport (such as _tcp. or _udp.):

	_service._transport.

The Domain argument in all of our examples will be local. (with the trailing dot). The Port argument is simply the port number of the service, and the optional Text field supplies additional information to the application receiving the advertisements (more on this later).

For example, here's how to advertise your local HTTP server:

	example _http._tcp. local. 80

This creates an example.local address that resolves to your machine's IP address via Multicast DNS. It is an HTTP service, running on TCP port 80. This is fine if you want to advertise the root of your web server, but what if you need to go to a particular URL? For example, to get to a wiki, you need to go to http://example.local/wiki, not just http://example.local/. This is where the optional text field at the end comes in. Web browsers will accept a path= argument in this field that gets appended to the URL line:

	example _http._tcp. local. 80 "path=/wiki"

Incidentally, if you're using VirtualHosts in Apache, you'll have to tell Apache to respond to the name you're advertising (example.local in the previous example). This is done easily with the ServerAlias directive from within your stanza:

	ServerName example.foo.com
	ServerAlias example.local

You'll want to use mDNSresponder.conf for any services that you want Howl to advertise on startup. Howl also has included a binary that allows you to add published services on the fly. mDNSPublish takes almost the same arguments as the previous configuration file. This example advertises the SSH daemon on our Linux box:

	mDNSPublish "SSH Example" _ssh._tcp 22

Lastly, here's a really useful example. We're running a local daapd server (http://www.deleet.de/projekte/daap/daapd), which uses the DAAP protocol that iTunes understands for streaming audio. We want to be able to advertise the daapd server via Howl. The default port for the DAAP protocol is 3689, so we call mDNSPublish with the correct parameters:

	mDNSPublish "Example iTunes" _daap._tcp. 3689

Any iTunes user on your network can now open iTunes and access the music library streamed out by daapd.


Bluetooth, Mobile Phones, and GPS

Network Discovery and Monitoring

Wireless Security

Hardware Hacks

Software Hacks

Do-It-Yourself Antennas

Wireless Network Design

Appendix A. Wireless Standards

Appendix B. Wireless Hardware Guide



Wireless Hacks
Wireless Hacks: Tips & Tools for Building, Extending, and Securing Your Network
ISBN: 0596101449
EAN: 2147483647
Year: 2004
Pages: 178

Flylib.com © 2008-2020.
If you may any questions please contact us: flylib@qtcs.net