I need to check the connection with only an IP address. I am trying to do this using the Apple Reachability class using the reachabilityWithAddress parameter. And my problem is that I can put any IP address in the callAddress.sin_addr.s_addr field, and statusText will always be โreachedโ. How can I accurately verify the connection to the IP address?
-(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];
}
source
share