You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by sh...@apache.org on 2016/12/08 00:57:19 UTC

[3/4] cordova-plugin-network-information git commit: CB-11230 CB-11505 iOS: Add compatibility with IPv6

CB-11230 CB-11505 iOS: Add compatibility with IPv6

Remove the logic associated with the local wi-fi because of the narrow use case for this API and the large potential for misuse

See also docs https://developer.apple.com/library/content/samplecode/Reachability/Listings/ReadMe_md.html#//apple_ref/doc/uid/DTS40007324-ReadMe_md-DontLinkElementID_11

 This closes #51


Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-network-information/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-network-information/commit/c911ef88
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-network-information/tree/c911ef88
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-network-information/diff/c911ef88

Branch: refs/heads/1.3.x
Commit: c911ef883c4564b5f04eff04eb6a257eab8b4323
Parents: f4dc63c
Author: Nikita Matrosov <ma...@gmail.com>
Authored: Mon Nov 14 17:05:21 2016 +0300
Committer: Vladimir Kotikov <ko...@gmail.com>
Committed: Thu Nov 17 09:49:06 2016 +0300

----------------------------------------------------------------------
 src/ios/CDVReachability.h |  6 +-----
 src/ios/CDVReachability.m | 42 ++++++------------------------------------
 2 files changed, 7 insertions(+), 41 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-network-information/blob/c911ef88/src/ios/CDVReachability.h
----------------------------------------------------------------------
diff --git a/src/ios/CDVReachability.h b/src/ios/CDVReachability.h
index 01a95c3..852d37b 100644
--- a/src/ios/CDVReachability.h
+++ b/src/ios/CDVReachability.h
@@ -57,7 +57,6 @@ typedef enum {
 
 @interface CDVReachability : NSObject
 {
-    BOOL localWiFiRef;
     SCNetworkReachabilityRef reachabilityRef;
 }
 
@@ -65,15 +64,12 @@ typedef enum {
 + (CDVReachability*)reachabilityWithHostName:(NSString*)hostName;
 
 // reachabilityWithAddress- Use to check the reachability of a particular IP address.
-+ (CDVReachability*)reachabilityWithAddress:(const struct sockaddr_in*)hostAddress;
++ (CDVReachability*)reachabilityWithAddress:(const struct sockaddr*)hostAddress;
 
 // reachabilityForInternetConnection- checks whether the default route is available.
 //  Should be used by applications that do not connect to a particular host
 + (CDVReachability*)reachabilityForInternetConnection;
 
-// reachabilityForLocalWiFi- checks whether a local wifi connection is available.
-+ (CDVReachability*)reachabilityForLocalWiFi;
-
 // Start listening for reachability notifications on the current run loop
 - (BOOL)startNotifier;
 - (void)stopNotifier;

http://git-wip-us.apache.org/repos/asf/cordova-plugin-network-information/blob/c911ef88/src/ios/CDVReachability.m
----------------------------------------------------------------------
diff --git a/src/ios/CDVReachability.m b/src/ios/CDVReachability.m
index 1399867..70177a7 100644
--- a/src/ios/CDVReachability.m
+++ b/src/ios/CDVReachability.m
@@ -140,7 +140,6 @@ static void CDVReachabilityCallback(SCNetworkReachabilityRef target, SCNetworkRe
         retVal = [[self alloc] init];
         if (retVal != NULL) {
             retVal->reachabilityRef = reachability;
-            retVal->localWiFiRef = NO;
         }
         else {
             CFRelease(reachability);
@@ -149,15 +148,14 @@ static void CDVReachabilityCallback(SCNetworkReachabilityRef target, SCNetworkRe
     return retVal;
 }
 
-+ (CDVReachability*)reachabilityWithAddress:(const struct sockaddr_in*)hostAddress;
++ (CDVReachability*)reachabilityWithAddress:(const struct sockaddr*)hostAddress;
 {
-    SCNetworkReachabilityRef reachability = SCNetworkReachabilityCreateWithAddress(kCFAllocatorDefault, (const struct sockaddr*)hostAddress);
+    SCNetworkReachabilityRef reachability = SCNetworkReachabilityCreateWithAddress(kCFAllocatorDefault, hostAddress);
     CDVReachability* retVal = NULL;
     if (reachability != NULL) {
         retVal = [[self alloc] init];
         if (retVal != NULL) {
             retVal->reachabilityRef = reachability;
-            retVal->localWiFiRef = NO;
         }
         else {
             CFRelease(reachability);
@@ -166,43 +164,19 @@ static void CDVReachabilityCallback(SCNetworkReachabilityRef target, SCNetworkRe
     return retVal;
 }
 
+// Reachability treats the 0.0.0.0 address as a special token that causes it to monitor the general routing
+// status of the device, both IPv4 and IPv6.
 + (CDVReachability*)reachabilityForInternetConnection;
 {
     struct sockaddr_in zeroAddress;
     bzero(&zeroAddress, sizeof(zeroAddress));
     zeroAddress.sin_len = sizeof(zeroAddress);
     zeroAddress.sin_family = AF_INET;
-    return [self reachabilityWithAddress:&zeroAddress];
-}
-
-+ (CDVReachability*)reachabilityForLocalWiFi;
-{
-    struct sockaddr_in localWifiAddress;
-    bzero(&localWifiAddress, sizeof(localWifiAddress));
-    localWifiAddress.sin_len = sizeof(localWifiAddress);
-    localWifiAddress.sin_family = AF_INET;
-    // IN_LINKLOCALNETNUM is defined in <netinet/in.h> as 169.254.0.0
-    localWifiAddress.sin_addr.s_addr = htonl(IN_LINKLOCALNETNUM);
-    CDVReachability* retVal = [self reachabilityWithAddress:&localWifiAddress];
-    if (retVal != NULL) {
-        retVal->localWiFiRef = YES;
-    }
-    return retVal;
+    return [self reachabilityWithAddress:(const struct sockaddr*) &zeroAddress];
 }
 
 #pragma mark Network Flag Handling
 
-- (NetworkStatus)localWiFiStatusForFlags:(SCNetworkReachabilityFlags)flags
-{
-    CDVPrintReachabilityFlags(flags, "localWiFiStatusForFlags");
-
-    BOOL retVal = NotReachable;
-    if ((flags & kSCNetworkReachabilityFlagsReachable) && (flags & kSCNetworkReachabilityFlagsIsDirect)) {
-        retVal = ReachableViaWiFi;
-    }
-    return retVal;
-}
-
 - (NetworkStatus)networkStatusForFlags:(SCNetworkReachabilityFlags)flags
 {
     CDVPrintReachabilityFlags(flags, "networkStatusForFlags");
@@ -254,11 +228,7 @@ static void CDVReachabilityCallback(SCNetworkReachabilityRef target, SCNetworkRe
     NetworkStatus retVal = NotReachable;
     SCNetworkReachabilityFlags flags;
     if (SCNetworkReachabilityGetFlags(reachabilityRef, &flags)) {
-        if (localWiFiRef) {
-            retVal = [self localWiFiStatusForFlags:flags];
-        } else {
-            retVal = [self networkStatusForFlags:flags];
-        }
+        retVal = [self networkStatusForFlags:flags];
     }
     return retVal;
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org