I am trying to find the IP of a windows computer (named TEST) on a local wifi network on iOS for smb purposes. I have bonjour installed on this windows machine and if i type the following command in terminal on my mac(on the same wifi network):
ping TEST.local
I get a success ( '64 bytes from 10.0.1.19: icmp_seq=285 ttl=128 time=3.237 ms' ). Note the ip (10.0.1.19): It resolves the hostname correctly! No problem so far!
Now, I'm trying to do the same on iOS by using CFHostCreateWithName:
NSString *host = @"TEST.local";
CFHostRef hostref = CFHostCreateWithName(nil/*or kCFAllocatorDefault, same result...*/,(__bridge CFStringRef)host);
CFStreamError *err;
Boolean lookup = CFHostStartInfoResolution(hostref, kCFHostAddresses, err);
NSArray* addresses = (__bridge NSArray*)CFHostGetAddressing(hostref, &lookup);
id first = addresses.firstObject;
if(first!=nil) {
struct in_addr *firstaddress = (__bridge struct in_addr *)first;
NSString *strDNS = [NSString stringWithUTF8String:inet_ntoa(*(firstaddress))];
}
Results vary from:
- First it returns 2 addresses, both the same, and are nonsense(not anywhere near 10.0.1.19, usually starts with 8)
- after that, no results, and an error(err): err->domain = 12 and err->error = 8. Looks like some form of caching, not sure about that...
So host resolving is fine on mac, but does not work on an iOS device connected to the same network... Did i miss something?