我只需要检查 IP 地址的连接性。我正在尝试使用reachabilityWithAddress 选项使用Apple Reachability 类来做到这一点。我的问题是我可以将任何 IP 地址放在 callAddress.sin_addr.s_addr 字段中,并且 statusText 总是“可达”。如何准确检查与 IP 地址的连接?
-(BOOL)reachabilityTest {
struct sockaddr_in callAddress;
callAddress.sin_len = sizeof(callAddress);
callAddress.sin_family = AF_INET;
callAddress.sin_port = htons(24);
callAddress.sin_addr.s_addr = inet_addr("212.83.3.190");
Reachability *hostReach = [[Reachability reachabilityWithAddress:&callAddress] retain];
NetworkStatus netStatus = [hostReach currentReachabilityStatus];
if (netStatus == NotReachable)
{
NSLog(@"NotReachable");
statusField.text = @"NOT reachable";
return NO;
}
if (netStatus == ReachableViaWiFi)
{
NSLog(@"ReachableViaWiFi");
statusField.text = @"reachable";
return YES;
}
[Reachability release];
}