Reverse DNS Lookups
Doing reverse DNS lookups sound easy enough by just using the getnameinfo function. But unfortunately, you have to be much more careful here as getnameinfo only performs a simple PTR lookup for the IP address. It does not validate that a corresponding forward entry exists for the returned name and therefore you shouldn't rely on the result (as it's easy for the IP address owner to just return any domain name).
So, what you really would have to do is to iterate over the list of returned results (as there can be multiple results) and for each result do an A (or AAAA) lookup and check if it contains the IP address you are looking for. Of course, getaddrinfo is the obvious choice for performing the A/AAAA lookups, but there is the problem that this is a purely synchronous API and you'll therefore have to do each lookup in sequence (or spawn a couple of worker threads).
By now you should have realised that the currently available APIs are rather inadequate for the seemingly simple task of doing a reverse DNS lookup. So what's the solution, you ask. Well, I am currently working on providing these kind of functionality as part of the nginetd project, so you might want to have a look there...

