TranLuongTuanAnh
TranLuongTuanAnh

Reputation: 138

Error not occurs when checking for reachability to 0.0.0.0 in Local Mac-based IPv6 DNS64/NAT64 Network

Follow this paper : your_app_and_next_generation_networks, at What Break segment, when checking for reachability to 0.0.0.0 in Local Mac-based IPv6 DNS64/NAT64 Network then error will occurs ( You're Not Connected to the Internet)

However, after created Local Mac-based IPv6 DNS64/NAT64 Network,and I try to checking for reachability to 0.0.0.0 by following code :

Reachability *reachability = [Reachability reachabilityForInternetConnection]; [reachability startNotifier];

then no error is shown for me!

here is implement of reachabilityForInternetConnection method from Reachability Github

+(instancetype)reachabilityForInternetConnection {
  struct sockaddr_in zeroAddress;
  bzero(&zeroAddress, sizeof(zeroAddress));
  zeroAddress.sin_len = sizeof(zeroAddress);
  zeroAddress.sin_family = AF_INET;

  return [self reachabilityWithAddress:&zeroAddress];
}

+(instancetype)reachabilityWithAddress:(void *)hostAddress {
   SCNetworkReachabilityRef ref = SCNetworkReachabilityCreateWithAddress(kCFAllocatorDefault, (const struct sockaddr*)hostAddress);

   if (ref) 
    {
     id reachability = [[self alloc] initWithReachabilityRef:ref];
     return reachability;
    }

   return nil;
}

Upvotes: 1

Views: 296

Answers (1)

ko2ic
ko2ic

Reputation: 2092

As in the following code , It don't work if we use valid global ip.

struct sockaddr_in addr;
addr.sin_len = INET_ADDRSTRLEN;
addr.sin_family = AF_INET;
addr.sin_addr.s_addr = inet_addr("XXX.XXX.XXX.XXX"); // valid global ip instead of 0.0.0.0
Reachability* reachability = [Reachability reachabilityWithAddress:&addr];
[reachability startNotifier];
NSLog(@"reachable[%d]", reachability.currentReachabilityStatus); // when ipv6, it isNotReachable and when ipv4, it is ReachableViaWiFi

Upvotes: 1

Related Questions