How to use DNSServiceReconfirmRecord?

TL;DR: How does one use DNSServiceReconfirmRecord() to invalidate mDNS state of a device that's gone offline?

I'm using the DNSServiceDiscovery API (dns_sd.h) for a local P2P service. The problem I'm trying to solve is how to deal with a peer that abruptly loses connectivity, i.e. by turning off WiFi or simply by moving out of range or otherwise losing connectivity. In this situation there is of course no notification that the peer device has gone offline; it simply stops sending any packets.

After my own timeout mechanism determines the peer is not responding, I mark it as offline in my own data structures. The problem is how to discover when/if it comes back online later. My DNSServiceBrowse callback won't be invoked because mDNS doesn't know the device went offline in the first place.

I am trying to use DNSServiceReconfirmRecord, which appears to be for exactly this use case -- "Instruct the daemon to verify the validity of a resource record that appears to be out of date (e.g. because TCP connection to a service's target failed.)" However my attempts always return a BadReference error (-65541). The function requires me to pass a DNS record, and the only one I know is the TXT record; perhaps it needs a different one? Which, and how would I get it?

Thanks!

Answered by DTS Engineer in 874061022

Hey Jens, it’s been a while.

which appears to be for exactly this use case

Yep.

my attempts always return a BadReference error (-65541).

Yeah, this is not an easy API to use correctly. There are two parts to it:

  1. Actually calling the DNSServiceReconfirmRecord API.
  2. Deciding what record data to pass in.

That kDNSServiceErr_BadReference error suggests you’re having problems with the first step, not the second. Regardless, I have suggestions for both of these in this post.

Share and Enjoy

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

Hey Jens, it’s been a while.

which appears to be for exactly this use case

Yep.

my attempts always return a BadReference error (-65541).

Yeah, this is not an easy API to use correctly. There are two parts to it:

  1. Actually calling the DNSServiceReconfirmRecord API.
  2. Deciding what record data to pass in.

That kDNSServiceErr_BadReference error suggests you’re having problems with the first step, not the second. Regardless, I have suggestions for both of these in this post.

Share and Enjoy

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

How to use DNSServiceReconfirmRecord?
 
 
Q