views:

304

answers:

2

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.

+1  A: 

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);
Farcaller
Well, that's not the best option.
mxg
+1  A: 

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.

St3fan
Some actual code on how to actually use CFHost to get the local host name would be useful.
apalopohapa