Created
May 12, 2016 17:53
Star
You must be signed in to star a gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+ (void)pingReachabilityInternal | |
{ | |
BOOL ignoresAdHocWiFi = NO; | |
#if (defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 90000) | |
struct sockaddr_in6 ipAddress; | |
bzero(&ipAddress, sizeof(ipAddress)); | |
ipAddress.sin6_len = sizeof(ipAddress); | |
ipAddress.sin6_family = AF_INET6; | |
#else | |
struct sockaddr_in ipAddress; | |
bzero(&ipAddress, sizeof(ipAddress)); | |
ipAddress.sin_len = sizeof(ipAddress); | |
ipAddress.sin_family = AF_INET; | |
ipAddress.sin_addr.s_addr = htonl(ignoresAdHocWiFi ? INADDR_ANY : IN_LINKLOCALNETNUM); | |
#endif | |
// Recover reachability flags | |
SCNetworkReachabilityRef defaultRouteReachability = SCNetworkReachabilityCreateWithAddress(kCFAllocatorDefault, (struct sockaddr *)&ipAddress); | |
BOOL didRetrieveFlags = SCNetworkReachabilityGetFlags(defaultRouteReachability, &connectionFlags); | |
CFRelease(defaultRouteReachability); | |
if (!didRetrieveFlags) | |
printf("Error. Could not recover network reachability flags\n"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment