Thedns-sd command is a network diagnostic tool, much like ping(1M) or traceroute(1M). However, unlike those tools, most of its functionality is not implemented in the dns-sd executable itself, but in library code that is available to any application. The library API that dns-sd uses is documented in /usr/include/dns_sd.h.
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 can be unpredictable. Additionally, the asynchronous nature of DNS Service Discoverydoes not easily lend itself to script-oriented programming. 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.
port is a number from 0 to 65535, and is the TCP or UDP port number upon which the service is listening. Registering a service on port 0 allows an application to explicitly advertise the non-availability of a service.
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 -
sd.org, under the service types (RFC 2782) link.
Look up and display the information necessary to contact and use the named service. This information includes the hostname of the machine where that service is available, the port number on which the service is listening, and (if present) TXT record attributesdescribing properties of the service.
Generic query for any resource record type and class. This option also reconfirms each result from the query. Reconfirming the record instructs mdnsd(1M) toverify the validity of the record. If the record is not valid mdnsd(1M) flushes the record from the daemon's cache and also from other mdnsd(1M) caches on the network.
Register (advertise) a service in the specified domain with the given name and type listening on the specified port and accessible on another host. This option should be used to advertise by proxy a service accessible on anotherhost. The host name and IPv4 address to access the service must be specified.
Discover recommended registration domains. This option returns the recommended domains to register a service. The recommended registration domains are returned by querying the name servers in resolv.conf(4).
I can already do something. For example I can register a service using "dns-sd -R ...". I also can browser (see) registered services using "dns-sd -B ...". What I still miss, is how to unregister a service.
At the moment when I type "dns-sd -R ..." the dns-sd does not return me to the command prompt. To return to the command prompt I need to press Ctrl-C. And the service stays registered till I press Ctrl-C.
One more thing which I do not understand yet is what "to look up a service" means. In my picture it should be sufficient to register a service, to see it and then to unregister it. But apparently I need to look up a service. What does it mean and why I need to do it?
ADDED:As it is asked, I clarify. I refer to "dns-sd" command line tool which I use in Windows 7. I think this command is part of Bonjour software for Windows (from Apple). Well, I did not checked if I had this command before I installed Bonjour, but I assume I did not have it. So, my question is about this command.
It's not clear to me exactly what you're trying to accomplish but it sounds like you may be using the wrong tool. dns-sd is a command line testing tool for Multicast DNS and DNS Service Discovery (DNS-SD). The purpose of DNS Service Discovery as the name implies is to advertise network services. The DNS-SD operations are as follows:
If you run a dns-sd command in a terminal (or "DOS box") to register a service, the process stays active in the foreground and does not return a shell prompt to you. The respective service stays registered as long as the dns-sd process keeps running. As soon as you cancel that process by hitting '[ctrl]+[c]', the services becomes un-registered.
Hence, to get back your prompt in the terminal, you have to start the dns-sd command (= process) in the background (or send it into the background after it is started). To un-register the respective service you have to kill the process by whatever means:
The way deregistering a service is handled with Apple's mDNS daemon is that upon registering a service the registering process is provided with a service descriptor, and that descriptor is needed to deregister the service. That means that typically only the process that registers a has the necessary info to deregister it. A process can't start up and deregister a service that that process didn't register in the first place.
One reason for this design is that the process that is providing the service is supposed to also be responsible for registering and de-registering it, which ensures that the status of the service registration is synchronized with the actual service availability.
When using dns-sd to do a proxy registration the process continues running so that when you close it, that process can do the proper deregistration. If you need long-lived service registration you need to arrange for the dns-sd process to be long-lived. Launchd can be used to manage this on OS X.
Browsing for services just tells you what service instances exist; It does not provide sufficient information to actually connect to and use them. To use a service you take the user friendly name discovered via browsing and "look up" or "resolve" the service instance. This tells you the additional information needed for connecting to it: the host, the port number, etc.
This reduces traffic (the additional data could be relatively large, so you don't want to get it for every service instance) and also decouples stable service instance names from the possibly less stable service instance connection data, similar to how hostnames and IP addresses are decoupled.
I am a bit lost in the terminology. I wanted to start to use Bonjour. As the first step, I tried to find an easy way to use it. And I thought that I, probably, can call Bonjour from the command line to register and discover services.
When I asked other people how to do it, I was told about mDNS (which works for Mac and Linux but not Windows). People also told me that I can use "dns-sd" (which works on Windows). I was told that "dns-sd" is just an alias for mDNS.
Moreover, it seems to me that mDNS and DNS-SD are two of three main components of Bonjour. Is it right? Can I use them without Bonjour? On my Windows 7 I have installed Bonjour and I was able to run "dns-sd" in the command line. But I am unable to run mDNS.
Bonjour consists of 3 parts:
1. IPv4 (and IPv6) link-local addressing (
169.254.0.0/16 addresses in IPv4).
2. Multicast name resolution (via the mDNS protocol). This allows hosts on an ad-hoc or isolated LAN to automatically map host names to IP addresses for each other by multicasting out DNS queries and responses amongst themselves, without needing a traditional unicast DNS server.
3. DNS Service Discovery, which allows you to discover the names and details of services of a given type. On a local network, DNS service discovery is typically done via mDNS as well, but via "Wide Area Bonjour" you can actually do DNS Service Discovery for an entire domain via a unicast DNS server.
I think part of your confusion is coming from the fact that there are command-line tools with the same names as the protocols. mDNS is the name of the multicast Domain Name Service protocol, but it's also the old name of a common command-line tool for sending mDNS protocol queries and receiving responses. "dns-sd" is the current name of the most common command-line tool for doing DNS service discovery, as well as for doing multicast name resolution lookups. Both of those command-line tools generally call APIs that are handled by the "mDNSResponder" background process / service / daemon.
The node-dns-sd is a Node.js module which is a pure javascript implementation of mDNS/DNS-SD (Apple Bonjour) browser and packet parser. It allows you to discover IPv4 addresses in the local network specifying a service name such as _http._tcp.local. Besides, it allows you to monitor mDNS/DNS-SD packets.
This module focuses on discovering IPv4 addresses from a service name. It is not a full implementation of mDNS/DNS-SD. If you want to announce services or send custom query packets or discover IPv6 addresses, you should choice another one from mDNS/DNS-SD nodejs implementations.
The node-dns-sd supports a Promise-based method for discovering devices in the local network. The sample code below shows how to discover devices from a service name. In the sample code, _googlecast._tcp.local is specified for a service name.
The type property indicates the query type, such as "PTR". This value must be a (Q)TYPE value defined in the RFC 1035 and RFC 2782. If this property is not specified, the wildcard "*" will be applied.
The key property indicates how to fold multiple DNS-SD query responses. If the value is set to "address" or this property is not specified, the last response form an IP address will be reported. If you want to discover IP addresses rather than services, this mode is appropriate.
If the value of the key property is set to "fqdn", responses will be folded by each FQDN. In this mode, multiple responses with the same IP address could be included. If you want to discover services rather than IP address, this mode is appropriate.
Note that the rdata_buffer property is added only if the type is "TXT". Each value in the rdata_buffer is a Buffer object. Some devices set a binary data to each value. You can parse the binary data using this property.
3a8082e126