在基于本地 Mac 的 IPv6 DNS64/NAT64 网络中检查到 0.0.0.0 的可达性时不会发生错误
Error not occurs when checking for reachability to 0.0.0.0 in Local Mac-based IPv6 DNS64/NAT64 Network
关注本文:your_app_and_next_generation_networks,在 What Break 段,在基于本地 Mac 的 IPv6 [= 中检查到 0.0.0.0 的可达性时29=] 网络然后会发生错误(您未连接到 Internet)
但是,在创建基于本地 Mac 的 IPv6 DNS64/NAT64 网络后,我尝试通过以下代码检查是否可达 0.0.0.0:
Reachability *reachability = [Reachability reachabilityForInternetConnection];
[reachability startNotifier];
然后没有错误显示给我!
中 reachabilityForInternetConnection
方法的实现
+(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;
}
如以下代码,‖如果我们使用有效的全局 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
关注本文:your_app_and_next_generation_networks,在 What Break 段,在基于本地 Mac 的 IPv6 [= 中检查到 0.0.0.0 的可达性时29=] 网络然后会发生错误(您未连接到 Internet)
但是,在创建基于本地 Mac 的 IPv6 DNS64/NAT64 网络后,我尝试通过以下代码检查是否可达 0.0.0.0:
Reachability *reachability = [Reachability reachabilityForInternetConnection];
[reachability startNotifier];
然后没有错误显示给我!
中reachabilityForInternetConnection
方法的实现
+(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;
}
如以下代码,‖如果我们使用有效的全局 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