Random Thoughts and Musings of a
Mobile Application Developer
Today I found that there are multiple possibilities to resolve a Hostname on iOS, but two of them do not always succeed. If you switch from 3G to Wifi a lot I saw, that sometimes the resolution would not work anymore. These resolution Methods are for C, because thats what most libraries are written in and my goal was to extend one of those and add name resolution.
I first tried with the
int res_query(char *domain_name, int class, int type, char *answer_buffer, int answer_buffer_length)
system call, but as previously mentioned, it failed most of the time after switching between Networks.
I then tried to use struct hostent *gethostbyname(const char *hostName); which failed less often after Network changes, but still occasionally did.
The Problem was that in those cases, the state would not recover and the tries would always fail.
So I dug a little and found out how to do it the apple way which was using
Boolean CFHostStartInfoResolution (CFHostRef theHost, CFHostInfoType info, CFStreamError *error);
In my example I use it synchronously which is not the way it is meant to be used (because it could fail and then the application would block till the timeout kicks in), but my application required it that way.
As always, I hope the code is useful to some. Suggestions and Corrections are always appreciated.
Hey buddy this is an extremely helpful article. i was banging my head with this problem and couldn't find the solution anywhere on the net..
i was wondering that you might help me in another scenario, i want to get the DNS records against a specific host or domain???
I am always glad to help, but I dont think I understand your problem exactly. Once you used CFHostStartInfoResolution you get a array with all the entries from the DNS back. You can iterate through them as described above and extract all the info you need.
If you intend to use the other two types, I have some example code for the same case somewhere. If you need that I think I could send it to you on monday.
yes i get all the A records actually, but i also want to get Reverse DNS(PTR) and ALT Name records too, can't exactly figure out how to manage that e.g against http://www.google.com
A Records: 22.214.171.124 126.96.36.199 188.8.131.52 184.108.40.206 220.127.116.11
ALT Name: www.google.com
Hi, Sorry for my late reply
I did some research but I did not find a way to do it with the native API functions either.
If you find a way, would you be so kind as to send me an example or post it here, so I can complete the article with regards to your findings?
Thanks and sorry again for being no help in this matter.
In case anybody is as dumb as I am
Remember to add CFNetwork framework