Reachability and IPv6
Asked Answered
L

2

18

One of my project uses the Apple's Reachability class in order to be monitor the network state and be notified in case of changes.

After reading this article about supporting IPv6 I was wondering if were to be made to this class to make it work with IPv6.

I set up an IPv6 network following the same article and everything seems to work fine but maybe there is an issue with the setup.

Is the part of the Reachability class checking the Internet connection working with IPv6 as it is now or does it need some changes?

Lyre answered 11/8, 2015 at 9:49 Comment(2)
did you figure this out?Files
Is that create problem if i am not updating reachability library ? And what will happen if my app is already uploaded with old library ? \Clank
S
8

Short answer from Apple itself (https://developer.apple.com/videos/play/wwdc2015/719/ at ~10:30 - though I would recommend to watch the video in full - or at least look through at the key points here: http://www.internetsociety.org/deploy360/blog/2015/06/video-of-apple-wwdc-session-about-ipv6-and-ios-9-now-available-and-some-screenshots/):

Just Try The Connection.

A copy paste from https://developer.apple.com/library/ios/documentation/NetworkingInternetWeb/Conceptual/NetworkingOverview/UnderstandingandPreparingfortheIPv6Transition/UnderstandingandPreparingfortheIPv6Transition.html#//apple_ref/doc/uid/TP40010220-CH213-SW25 which reiterates this:

Connect Without Preflight

The Reachability APIs (see SCNetworkReachability Reference) are intended for diagnostic purposes after identifying a connectivity issue. Many apps incorrectly use these APIs to proactively check for an Internet connection by calling the SCNetworkReachabilityCreateWithAddress method and passing it an IPv4 address of 0.0.0.0, which indicates that there is a router on the network. However, the presence of a router doesn’t guarantee that an Internet connection exists. In general, avoid preflighting network reachability. Just try to make a connection and gracefully handle failures. If you must check for network availability, avoid calling the SCNetworkReachabilityCreateWithAddress method. Call the SCNetworkReachabilityCreateWithName method and pass it a hostname instead.

Some apps also pass the SCNetworkReachabilityCreateWithAddress method an IPv4 address of 169.254.0.0, a self-assigned link-local address, to check for an active Wi-Fi connection. To check for Wi-Fi or cellular connectivity, look for the network reachability flag kSCNetworkReachabilityFlagsIsWWAN instead.

Sasaki answered 5/5, 2016 at 18:18 Comment(2)
Is that create problem if i am not updating reachability library ? And what will happen if my app is already uploaded with old library ?Clank
If you avoid calling the old routines, then you will just have some dead code, which probably isn't a problem.Sasaki
F
0

I also have similar doubt regarding IPv6 and Reachability class. Apple has asked in their docs to provide support for IPv6 types also like (struct in_addr6, AF_INET6, struct sockaddr_in6 etc) but the class seem to be not updated yet to have these types. This is the doubt that I am having. I am yet to try IPv6 tests but just observed while doing the static code checks. Some changes might be required.

Reachability.m

+ (instancetype)reachabilityForInternetConnection
{
    struct sockaddr_in zeroAddress;

    bzero(&zeroAddress, sizeof(zeroAddress));

    zeroAddress.sin_len = sizeof(zeroAddress);

    zeroAddress.sin_family = AF_INET;

    return [self reachabilityWithAddress:&zeroAddress];
}
Files answered 14/9, 2015 at 10:49 Comment(1)
If you must check for network availability, avoid calling the SCNetworkReachabilityCreateWithAddress method. Call the SCNetworkReachabilityCreateWithName method and pass it a hostname instead. developer.apple.com/library/content/documentation/…Darbee

© 2022 - 2024 — McMap. All rights reserved.