Context
I'm working on a DNS proxy network extension and would like to be able to parse replies from the upstream DNS server for extracting the TTL for caching purposes.
I already have a working DNS proxy network extension, but at the moment I am not handling the responses and just forward all queries to an upstream DNS server.
My understanding is that I have to take care of result caching myself because I cannot use the system resolver in the DNS proxy network extension.
Question
What is the best way to parse DNS replies in Swift to extract e.g. the TTL?
I found an old thread (https://forums.swift.org/t/parse-dns-packet-requests-and-responses/41797/5) describing a way to achieve this using dns_util
.
The solution described there works - but dns_parse_packet
in dns_util
have been marked deprecated since iOS 16.
So, I am wondering if there is a better way to achieve the parser.
I tried to utilize the dnssd
framework but was unable to figure out how to achieve only parsing of the raw DNS reply. If that is possible it would be great to get some pointers.
<dns_util.h>
is still supported, in the sense that I’ll answer questions about it. However, it’s not really the right answer here.
IMO what you need here is a modern DNS packet parsing library, written in Swift, that avoids unsafe constructs. That’s my ‘gold standard’ for parsing complex structures coming from an untrusted source. {mac,i}OS doesn’t have such an API, so you’ll need to either write or acquire it.
There are such libraries available from other third-party developers. I don’t have direct experience with them, so I can’t offer any opinions. You’ll have to evaluate them like you would any other proposed dependency.
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"