help! I met a crash when i try to get the addresses for the give hostname; the crash log shows like this:
1 libobjc.A.dylib 0x0000000197d180e4 objc_exception_throw + 56
2 CoreFoundation 0x0000000186044218 -[NSException initWithCoder:]
3 Foundation 0x0000000186e9528c -[NSThread start] + 136
4 ZFirewall7.dylib 0x0000000105e4d768 -[FiPSettingsManager doHostStuff:] + 1124
5 ZFirewall7.dylib 0x0000000105e48424 _ZL23my_CFHostCreateWithNamePPK13__CFAllocatorPPK10__CFString + 164
6 Upload 0x000000010220d1c0 +[UploadUtil addressesForHostname:] (UploadUtil.m:277)
7 Upload 0x000000010220d120 +[UploadUtil addressForHostname:] (UploadUtil.m:267)
....
*** -[NSThread start]: attempt to start the thread again
and my code is:
+(NSArray *)addressesForHostname:(NSString *)hostname
{
// Get the addresses for the given hostname.
CFHostRef hostRef = CFHostCreateWithName(kCFAllocatorDefault, (__bridge CFStringRef)hostname);
BOOL isSuccess = CFHostStartInfoResolution(hostRef, kCFHostAddresses, nil);
if (!isSuccess)
{
CFRelease(hostRef);
return nil;
}
CFArrayRef addressesRef = CFHostGetAddressing(hostRef, nil);
if (addressesRef == nil)
{
CFRelease(hostRef);
return nil;
}
// Convert these addresses into strings.
char ipAddress[INET6_ADDRSTRLEN];
NSMutableArray *addresses = [NSMutableArray array];
CFIndex numAddresses = CFArrayGetCount(addressesRef);
for (CFIndex currentIndex = 0; currentIndex < numAddresses; currentIndex++) {
struct sockaddr *address = (struct sockaddr *)CFDataGetBytePtr(CFArrayGetValueAtIndex(addressesRef, currentIndex));
if (address == nil)
{
CFRelease(hostRef);
return nil;
}
getnameinfo(address, address->sa_len, ipAddress, INET6_ADDRSTRLEN, nil, 0, NI_NUMERICHOST);
[addresses addObject:[NSString stringWithCString:ipAddress encoding:NSASCIIStringEncoding]];
}
CFRelease(hostRef);
return addresses;
}
this function do called by several threads, and the doc of CFHostCreateWithName says that it is thread safe, now i have no idea about how to solve this problem.