mxg
mxg

Reputation: 21254

Objective-C detect DNS

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.

Upvotes: 1

Views: 1616

Answers (2)

Stefan Arentz
Stefan Arentz

Reputation: 34945

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.

Upvotes: 1

Farcaller
Farcaller

Reputation: 3090

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);

Upvotes: 1

Related Questions