How do I read the output of dns-sd?
When I run the dns-sd
command, for example as dns-sd -B _services._dns-sd._udp.
to list all the service types on my local network, I get a table that looks like:
$ dns-sd -B _services._dns-sd._udp.
Browsing for _services._dns-sd._udp.
DATE: ---Tue 31 Dec 2013---
14:39:57.995 ...STARTING...
Timestamp A/R Flags if Domain Service Type Instance Name
14:39:57.995 Add 3 4 . _tcp.local. _ssh
14:39:57.996 Add 3 4 . _tcp.local. _sftp-ssh
I get "Timestamp", and "A/R" is probably Add/Remove. What are "Flags"? What's "if"?
A half answer:
I found the source code for dns-sd.c and dns_sd.h, dating back to 2004 and OS X "Lion", where "flags" is a value of type DNSServiceFlags
, which seems to be one of these (deprecated) constants. If that's so, then "1" means "kDNSServiceFlagsMoreComing": another entry should follow immediately. "2" means just "kDNSServiceFlagsAdd". "3" means "kDNSServiceFlagsAdd" together with "kDNSServiceFlagsMoreComing". Not very useful.
According to that same program, "if" is uint32_t ifIndex
, the "interface index", which is also mentioned on that Apple developer page. I'm seeing values like "4" and "0", and I can't quite figure out the meaning. It seems to be both a bitmask for requesting a class of interface (where 0 means "any", and -1/-2/-3 cast to an uint32_t are other classes), and an index into a list of network interfaces (where 0 means "error", and positive integers indicate a valid interface). I only have one active network interface, and I can't tell that it's "#4" of anything, or why I'd see "0" for some dns-sd requests.
Apple's mDNSResponder code, in many revisions across many years, is at https://opensource.apple.com/source/mDNSResponder/.
"if" is short for "interface". "interface" is a term in the networking protocol stack arena, and in this case, an interface is a software entity that binds up to the bottom end of the Internet Protocol (IP) layer of the stack. An "interface" software module provides a known API to IP, to bind network hardware drivers into the IP layer. Typical interfaces provide this binding for things like Ethernet, WiFi, Bluetooth, Firewire, etc. Since any given machine can have more than one physical media interface, the IP layer can bind to multiple interfaces. These bindings are kept track of via simple index values in a table. The "if" value in the dns-sd display is simply the index number of the interface for which the service is accessible.
You can find out what interfaces are configured in your system which other command line utilities, such as netstat -i
. In OS X and other UNIX, you may see <Link#4>
listed, meaning index 4.