Determine the host address of a Bonjour service address containing "_tcp"

24 Views Asked by At

Using the function NetFSCopyURLForRemountingVolume (in NetFS.h) to determine the mount URL of a mounted file server on macOS, I may get a Bonjour address like this:

devicename._smb._tcp.local

Sadly, when I then try to use this address to contact the host (e.g. by contacting it via https using the NSURLSession APIs), I get an error about the address being not resolvable.

The correct address would be devicename.local.

The question is: What's the proper way to determine the actually working host address for this service?

I can simple remove all address components that start with an underscore. But I wonder if that's safe.

Are there other ways to do this?

For instance, how does the mount service accomplish this, when it's given an address like smb://devicename._smb._tcp.local/MyNAS? It must resolve that into the actual host address as well somehow, I assume.

I believe the Bonjour service on the Mac has a mapping table for this internally. Is there an API that lets me look that up?

Mind you, performing any actual network calls in order to resolve this address is not what I seek, as that would be causing needless network traffic when the information should be available on the local Mac readily.

0

There are 0 best solutions below