iPhone DNS解析,并不是所有A记录返回 [英] iPhone DNS resolution, not all A records returned
问题描述
我有以下代码,应该会删除URL的所有DNS A记录。当我从UI调用这个代码时,它可以正常运行并返回所有的A记录,但是当这个代码从一些其他异步线程调用时,它总是只返回一个IP(一个A记录),任何想法为什么?
I have the following code that should retrive all DNS A records for a URL. When I call this code from the UI, it works fine and returns all the A records, but, when this code is called from some other async thread it always returns only one IP (one A record), Any ideas why?
这是代码:
Boolean result;
CFHostRef hostRef = NULL;
CFArrayRef addresses = NULL;
NSString *hostname = [NSString stringWithCString:server];
hostRef = CFHostCreateWithName(kCFAllocatorDefault, (CFStringRef)hostname);
if (hostRef) {
result = CFHostStartInfoResolution(hostRef, kCFHostAddresses, NULL); // pass an error instead of NULL here to find out why it failed
if (result == TRUE) {
addresses = CFHostGetAddressing(hostRef, &result);
}
}
if (result == TRUE)
{
NSLog(@"ResolveDNS - Resolved");
for (CFIndex count = 0; count < CFArrayGetCount(addresses); count++)
{
char addr[256];
struct sockaddr_in *sa = (struct sockaddr_in *)
CFDataGetBytePtr((CFDataRef)CFArrayGetValueAtIndex(addresses, count));
// inet_ntop will correctly display both IPv4 and IPv6 addresses
if (inet_ntop(sa->sin_family, &sa->sin_addr, addr, sizeof(addr)))
printf("%s:%d \n", addr, ntohs(sa->sin_port));
[ipTmpArray addObject:[NSString stringWithCString:addr]];
}
推荐答案
iOS设备(全部在4.2或4.3),但不在我的模拟器上。
如果我再次启动相同的方法,我有时会获得更多的IP,有时甚至所有的。
the same occurs on all my iOS devices (all on 4.2 or 4.3), but not on my Simulator. And if I launch again the same method I sometime get more IP, sometime even all of them.
我怀疑是由于iOS,某种内存当他们记录以前的分辨率时优化。
I suspect it's due to iOS, some kind of Memory optimisation when they record the previous resolutions.
这篇关于iPhone DNS解析,并不是所有A记录返回的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!