dns-sd(1) | General Commands Manual | dns-sd(1) |
-R name type domain port [key=value ...] |
-B type domain |
-L name type domain |
The dns-sd command is primarily intended for interactive use. Because its command-line arguments and output format are subject to change, invoking it from a shell script will generally be fragile. Additionally, the asynchronous nature of DNS Service Discovery does not lend itself easily to script-oriented programming. For example, calls like "browse" never complete; the action of performing a "browse" sets in motion machinery to notify the client whenever instances of that service type appear or disappear from the network. These notifications continue to be delivered indefinitely, for minutes, hours, or even days, as services come and go, until the client explicitly terminates the call. This style of asynchronous interaction works best with applications that are either multi-threaded, or use a main event-handling loop to receive keystrokes, network data, and other asynchronous event notifications as they happen.
name can be arbitrary unicode text, containing any legal unicode characters (including dots, spaces, slashes, colons, etc. without restriction), up to 63 UTF-8 bytes long. type must be of the form "_app-proto._tcp" or "_app-proto._udp", where "app-proto" is an application protocol name registered at http://www.dns-sd.org/ServiceTypes.html.
domain is the domain in which to register the service. In current implementations, only the local multicast domain "local" is supported. In the future, registering will be supported in any arbitrary domain that has a working DNS Update server [RFC 2136]. The domain "." is a synonym for "pick a sensible default" which today means "local".
port is a number from 0 to 65535, and is the TCP or UDP port number upon which the service is listening.
Additional attributes of the service may optionally be described by key/value pairs, which are stored in the advertised service's DNS TXT record. Allowable keys and values are listed with the service registration at http://www.dns-sd.org/ServiceTypes.html.
For valid types see http://www.dns-sd.org/ServiceTypes.html as described above. Omitting the domain or using "." means "pick a sensible default."
Note that in a typical application, browsing happens rarely, while lookup (or "resolving") happens every time the service is used. For example, a user browses the network to pick a default printer fairly rarely, but once a default printer has been picked, that named service is resolved to its current IP address and port number every time the user presses Cmd-P to print.
dns-sd -R "My Test" _printer._tcp. . 515 pdl=application/postscript
For this registration to be useful, you need to actually have LPR service available on port 515. Advertising a service that does not exist is not very useful, and will be confusing and annoying to other people on the network.
Similarly, to advertise a web page being served by an HTTP server on port 80 on this machine, such that it will show up in the Bonjour list in Safari and other DNS-SD compatible Web clients, use:
dns-sd -R "My Test" _http._tcp . 80 path=/path-to-page.html
To find the advertised web pages on the local network (the same list that Safari shows), use:
dns-sd -B _http._tcp
While that command is running, in another window, try the dns-sd -R example given above to advertise a web page, and you should see the "Add" event reported to the dns-sd -B window. Now press Ctrl-C in the dns-sd -R window and you should see the "Remove" event reported to the dns-sd -B window.
April 2004 | NetBSD |