Hey everyone,
I'm tackling a scenario where I need to fetch a comprehensive list of both IPv4 and IPv6 addresses linked to a particular DNS. I know about the POSIX function getaddrinfo(), but I'm on the lookout for an asynchronous solution. Previously, I could've used CFHost, but unfortunately, it's been deprecated. Any suggestions or insights on how to achieve this asynchronously would be greatly appreciated!
Thanks, Harshal
First up, don’t use top-level code. Put it into a function. Top-level code in Swift is weird.
Second, to get a callback you must schedule your DNSServiceRef
somehow. The easiest way to do that is with DNSServiceSetDispatchQueue
. And if you schedule on the main queue, you need to ‘park’ the main thread is dispatch_main
rather than sleep
.
I recommend that you look at the code I referenced in my previous email. This is a low-level API and thus not trivial to use. That’s especially true when you’re using Swift.
Finally, sockaddr
is a very hard type to use correctly in Swift, and inet_ntop
is bad form in any language. I recommend getnameinfo
with NI_NUMERIC{HOST,SERV}
. See QSocket: Addresses.
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"