Receiving UDP/5353 packets in iOS app

Hello, I am trying to write an iOS app which could receive and analyze mDNS queries. More specifically, I have my app register a Bonjour service, and I need to see queries from the network for any subtype of my primary type, although I have not registered any subtype myself. Reason being that I have a device that tries to find me using a specific primary type, but always includes a subtype in its queries, and I can't know the subtype in advance, so I can't register my service with the subtype. So I'd need to see the query, extract the subtype and re-register my service with that subtype so that the device can then find me.

Looks like the various APIs to interact with Bonjour won't let me do that.

I've tried another approach and started a NWListener on port 5353 with allowLocalEndpointReuse set to true, but I'm getting "Address already in use" and it doesn't work, since this port is likely to be used by the mDNSresponder service.

Is there an API I could use to achieve what I described above ?

Hello, I am trying to write an iOS app which could receive and analyze mDNS queries.

There are a few ways to approach this, and both require the Multicast Entitlement. Essentially, this is the page you need to take a look at that describes this situation in detail, but trying to browse for _services._dns-sd._udp.local. may not be a supported use case here. You may want to take the approach of receiving all of the mDNS traffic on the network and parsing the packets instead. Short story is that I would apply for the Multicast Entitlement and describe what you are looking to do.

Matt Eaton
DTS Engineering, CoreOS
meaton3@apple.com

Hi Matt,

Thanks for your response. I have since been able to implement your second suggested approach that consists in receiving all the mDNS traffic and parsing the packets myself. This is working well in the Simulator. In parallel of this, I have applied for the Multicast Entitlement, as per your suggestion, however I have received a response last night, and my application has been rejected, with the following comment: "It is currently not our policy to enable this entitlement for apps trying to use mDNS directly. If you need new Bonjour APIs, please work with Matt to file the correct enhancement request." Would you be able to bring this up to the Bonjour API team ?

Best regards

Receiving UDP/5353 packets in iOS app
 
 
Q