Does anyone knows how can i detect from an app the DNS of the iPhone?
UPDATE: If there're different ways of obtaining the DNS server and DNS host name, any solution is acceptable.
Does anyone knows how can i detect from an app the DNS of the iPhone?
UPDATE: If there're different ways of obtaining the DNS server and DNS host name, any solution is acceptable.
To get the host name you can use libc API, gethostname:
#import <unistd.h>
...
char hostname[HOST_NAME_MAX];
int err = gethostname(hostname, HOST_NAME_MAX);
if(!err)
NSLog(@"My hostname is %s", hostname);
An alternative, and possibly better way, to do this, is to use the Core Foundations APIs.
More specifically, the CFHost
API will do asynchronous host resolution.
You can ask a CFHost
instance to start resolving a host and test for its reachability. The process will happen on a runloop and you will get callbacks when the resolution has finished.
It is a good alternative for the blocking gethostname
call.