Skip to content

Instantly share code, notes, and snippets.

@wilsolutions
Created May 12, 2016 17:53
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save wilsolutions/3466a0c6dc48b33fe1551aaf23a602c7 to your computer and use it in GitHub Desktop.
+ (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