APLawrence.com -  Resources for Unix and Linux Systems, Bloggers and the self-employed

Bonjour Discovery

© May 2019 Anthony Lawrence

After the big Apple Leopard patch the other day, my HP printer stopped working. I could still ping it, but my Mac wasn't sending it print jobs, and that was that.

I don't automatically blame Apple for this. HP has a long, long history of making everything too darn complicated. No doubt companies of the same general size as HP appreciate all the extra crud built into their software, but for me, just let me send data to port 9100 and print it it - or not. On OS X 10.4, that's just how I had set up this printer: something like :

sudo lpadmin -p  HPLaser -E -v socket:// -m laserjet

But with Leopard, I had let the System Preferences Print & Fax tool have a crack at it, and sure enough, it found the printer through Bonjour, Apple's zero-conf networking discovery thingy. You can get Bonjour for Windows and Linux; "mDNSResponder" (the core of Bonjour) is open source. Although I have some reservations about dumbing everything down, it is nice to have "chatty" machines and services. Or at least it's nice when they work.

But when I returned to System Preferences now, it still had the printer, yet I couldn't convince it to send anything to actually be printed.

I thought I might try deleting the printer and adding it back. Deleting seemed to work fine, but clicking on "+" to have it find the printer again just gave me a spinning beach ball.. which never went away.. so I finally rebooted, and after that Bonjour instantly found my printer and I could print again.

All that made me curious about Bonjour. In scrounging about the Net, the first thing I came across was this Rawr-jour, which certainly looked like it would be fun to play with, but alas, it seems to have disappeared from our world. Oh well. I pecked about a little more and found Net::Bonjour on CPAN. I did a quick "sudo cpan" and then an "install Net::Bonjour" and then wrote this little program, mostly cribbed from the author's example:

use Net::Bonjour;
@service=qw( pdl-datastream riousprint printer http  ftp ssh
afpovertcp ipp upnp uddi smb ipp);
foreach(@service) {
  print "Trying $service \n";
  my $res = Net::Bonjour->new($service, 'tcp');

  foreach my $entry ( $res->entries ) {
      printf "%s %s:%s\n", $entry->name, $entry->address, $entry->port;

Why on earth did I list all those services? Well, for one thing, I was curious as to what other Bonjourish things might be running, but more directly, I had no idea what the HP had advertised. You see, there is this big list of DNS SRV (RFC 2782) Service Types and I have no idea which one HP uses. I thought it might have been "ipp", and when that didn't work I tried "printer", and when that came up dry I populated the list as you see it above. That found the printer strutting its stuff on "pdl-datastream":

Trying adisk 
Trying pdl-datastream 
HP LaserJet 1022n
Trying riousprint 
Trying printer 

Cool. But it also surprised me:

Trying http 
HP LaserJet 1022n
Trying ftp 
Trying ssh 
Trying afpovertcp 
Trying ipp 
Trying upnp 
Trying uddi 
Trying smb 

I don't even know why I stuck http in there, but there it was. The printer is running a webserver. Now that isn't exactly thunderous news: an awaful lot of devices do that nowadays, but there had been nothing in the documentation I got with my printer that had mentioned this, so it was just a little surprising. Sure enough, a browser pointed at brought up configuration stuff that I had to use a Windows CD for when I bought the darn thing. How annoying that they didn't say anything about that.

A Bonjour service of course doesn't have to be hardware. It can be just about anything you can dream up, and I see great possibilities for perversion. For example, what's stopping you from implementing a print to fax service and letting the print service discover it as a Bonjour "printer". More interesting is what would stop you from implementing something far more deviant? Why, nothing at all, and if you'd like a head start on that, MacDevCenter has a couple of Mac posts about just that subject:

Incorporating Rendezvous into Your Cocoa Applications, Part 1

Incorporating Rendezvous into Your Cocoa Applications, Part 2

It's not hard to find Bonjour for Linux: Apple has source for Mac OS X, Windows, Linux, Solaris, FreeBSD and VxWorks, and also includes helper applications for browsing and advertising services. I easily found RPM's too: RPM resource libavahi-client.so.3 .

This is how five minutes fixing a printer turns into a whole afternoon..

Got something to add? Send me email.

(OLDER)    <- More Stuff -> (NEWER)    (NEWEST)   

Printer Friendly Version

-> Bonjour Discovery

1 comment

Inexpensive and informative Apple related e-books:

Take Control of High Sierra

Take Control of OS X Server

Take Control of Parallels Desktop 12

Take Control of Apple Mail, Third Edition

Take Control of iCloud

More Articles by © Anthony Lawrence

Fri Nov 23 14:49:58 2007: 3273   drag

Generally speaking you'd want to use Avahi on Linux. (hence the avahi in the lib name) It's not based off of Apple's code, but it does provide the same functionality. (unfortunately early on Apple had bonjour's code under a unpleasent license and by the time they changed the license to a truely open source one Avahi was already fairly established)

Then you'll also want to make sure you have libnss-mdns package installed. This allows you to refer to other machines by $HOSTNAME.local over the network. Modern versions of the package should auto-configure your /etc/nsswitch.conf file, but if they don't here is what the 'hosts' line will look like:
hosts: files mdns4_minimal [NOTFOUND=return] dns mdns4

Then if your using network-manager to autocofigure your network when you connect a network it will default to a random Ipv4 link-local address (

All of this combined should allow you to just throw a network together with no dns server, domain controller, or documentation and the machines should autoconfigure themselves and the users should be presented with all available services in a easy-to-use fasion. (more or less). All in all it's pretty slick stuff. Due to how the protocol is designed it also shouldn't go out and advertise any services over the internet, although I suppose you may advertise over a cable line...

Like always Macs are going to be slicker then Linux machines at this sort of thing, but currently the coolest thing you can currently do with avahi is how pulseaudio ties into it. Using pulseaudio you can do network-transparent audio in a similar fasion to how you can do network-transparent GUI with X Windows. Very handy for things like X terminals for call centers and such since you can configure Pulseaudio to follow the remote X stuff around. (currently the only distro that support pulseaudio out of the box is Fedora Core 8).

If Linux was more popular it would allow for people to market clever little devices to allow you tie your audio into a bluetooth cell phone and headset or connect a stereo to the network so you can play music and games on something nicer then your laptop's tiny speakers. Of course for us computer folk there are always things like Gumstix..


Printer Friendly Version

Have you tried Searching this site?

This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more.

Contact us

Printer Friendly Version

Unlike info, pinfo does not display anything if it has nothing. I've been forever irritated by info coming up with its default page when it has nothing to tell me. (Tony Lawrence)

Linux posts

Troubleshooting posts

This post tagged:





Unix/Linux Consultants

Skills Tests

Unix/Linux Book Reviews

My Unix/Linux Troubleshooting Book

This site runs on Linode