NWBrowser scan for arbitrary Bonjour Services with Multicast Entitlement ?!

Dear Girls, Guys and Engineers.

I'm currently building a Home Network Scanner App for People which want to know which Bonjour Devices are in her/his Home Network environment. From an older Question I got the answer, that I need an Entitlement to do this.

I started to work on the App and requested the Multicast Entitlement from Apple. They gave me the Entitlement for my App and now I'm trying to discover all devices in my Home Network but I got stuck and need Help.

I only test direct on device, like the recommendation. I also verified that my app is build with the multicast entitlement there where no problems. My problem is now, that is still not possible to discover all Bonjour services in my Home Network with the Help of the NWBrowser.

Can you please help me to make it work ?

I tried to scan for the generic service type:

let browser = NWBrowser(for: .bonjour(type: "_services._dns-sd._udp.", domain: nil), using: .init())

but this is still not working even tough I have the entitlement and the app was verified that the entitlement is correctly enabled

if I scan for this service type, I got the following error:

[browser] nw_browser_fail_on_dns_error_locked [B1] Invalid meta query type specified. nw_browser_start_dns_browser_locked failed: BadParam(-65540)

So what's the correct way now to find all devices in the home network ?

Thank you and best regards Vinz

Answered by Systems Engineer in 680502022

Browsing for the _services._dns-sd._udp. service with NWBrowser would be an Enhancement Request against Network Framework. Please follow up with your Feedback ID. A workaround would be to use the DNSServiceBrowse API.

Matt Eaton
DTS Engineering, CoreOS
meaton3@apple.com
Accepted Answer

Browsing for the _services._dns-sd._udp. service with NWBrowser would be an Enhancement Request against Network Framework. Please follow up with your Feedback ID. A workaround would be to use the DNSServiceBrowse API.

Matt Eaton
DTS Engineering, CoreOS
meaton3@apple.com
Accepted Answer

Matt and I had a good chat with the Network framework and Bonjour teams about this yesterday, so I thought I’d elaborate on the above a little.

First up, you can’t use NWBrowser to browse for services. This isn’t an arbitrary restriction but a result of the way that NWBrowser is structured. Specifically, the browse operation returns endpoints and there’s no way to represent a service type as an endpoint.

That leaves you with either NSNetService or the DNS-SD API (<dns_sd.h>). Given that this is a low-level thing, and NSNetService is now deprecated, I recommend DNS-SD. That's not the easiest API to use but you can get a head start by looking at the DNSSDObjects sample code.

Let us know if you hit any snags.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Hi Matt and Quinn,

Thank you for your fast reply. This light up things for me, i will try to get the service list via dnssd framework. To get the Endpoints I can then use NWBrowser. Just for clarification, the entitlement is still needed to do this or for iOS 14+ ? I used NSNetservice in the past and it was possible to get service list without the entitlement.

Thank you both

Just for clarification, the entitlement is still needed to do this or for iOS 14+?

Yes.

I used NSNetservice in the past and it was possible to get service list without the entitlement.

Correct. This is a policy change added as part of the local network privacy effort.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

NWBrowser scan for arbitrary Bonjour Services with Multicast Entitlement ?!
 
 
Q