Checking for an internet connection
Checking for an internet connection
- Subject: Checking for an internet connection
- From: "Bobby B" <email@hidden>
- Date: Thu, 7 Sep 2006 21:59:27 -0400
Hey guys;
I'm trying to find/come up with a simple piece of code that checks for
internet availability. I've searched the archives, and checked
Google. I found the following:
#include <CoreFoundation/CoreFoundation.h>
#include <SystemConfiguration/SCNetworkReachability.h>
- (BOOL)wirelessHasInternet
{
SCNetworkReachabilityRef netreach;
SCNetworkConnectionFlags flags;
netreach = SCNetworkReachabilityCreateWithName (
kCFAllocatorSystemDefault, "www.google.com" )
AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER;
SCNetworkReachabilityGetFlags ( netreach, &flags )
AVAILABLE_MAC_OS_X_VERSION_10_3_AND_LATER;
BOOL reachable = (kSCNetworkFlagsReachable & flags);
if (reachable) return YES; else return NO;
}
However.. This doesn't work. I use Airport and connect to a network
that I can access the internet on, and it says it can't access the
internet. And if I try it on a network that I can't access the
internet on, it still says it can't access it.
I even went as far as trying this in a method:
if(system("ping -c 1 -t 3 www.google.com")) return NO; else return YES;
And that kinda works. But.. I've found something weird. I can
access the internet, and it pings fine and everything works. Then I
disable the internet, without restarting the program, and then it
returns NO that it can't find the internet. But then when I re-enable
the internet (and give it time, like I can load google.com in Safari),
when this method runs it says "cant resolve host google.com".. Odd!
Any hints or clues?
Thank you guys
Bobby B
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden