Availability iPhone SDKWithAddress

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];
 }
+3
source share
1 answer

Instead of using the Reachability classes, go to your old school and open a TCP connection for it. If the answer connect()is equal EHOSTUNREACH, you cannot. If the answer ECONNREFUSEDor a successful connection, you can.

+4

Source: https://habr.com/ru/post/1772503/


All Articles