Re: Problems detecting an active internet connecting using SystemConfiguration
Re: Problems detecting an active internet connecting using SystemConfiguration
- Subject: Re: Problems detecting an active internet connecting using SystemConfiguration
- From: David Sinclair <email@hidden>
- Date: Sat, 15 Mar 2003 10:37:28 -0800
On Saturday, Mar 15, 2003, at 05:40 US/Pacific, Marc Weil wrote:
I have been trying to use SCNetwork.h's
SCNetworkCheckReachabilityByName()
function for detecting an active internet connection, but it doesn't
seem to
work right. It only worked correctly once (unless I am misreading what
its
constants mean).
It took some experiments for me to figure out a good combination that
seems to work in all tested cases -- DSL, AirPort, dial-up, waking from
sleep, etc.
Here are some values I've encountered:
Ethernet DSL unplugged: 0 = 00000000 = all off
Ethernet DSL online: 2 = 00000010 = kSCNetworkFlagsReachable on
AirPort waking (offline): 7 = 00000111 =
kSCNetworkFlagsTransientConnection &
kSCNetworkFlagsReachable &
kSCNetworkFlagsConnectionRequired
Dialup online: 11 = 00001011 =
kSCNetworkFlagsTransientConnection &
kSCNetworkFlagsReachable &
kSCNetworkFlagsConnectionAutomatic
Here's the method I use in my Dejal Simon product, that seems to cover
all cases. I check two sites just in case the first one is unavailable
for some reason:
- (BOOL)internetOnline
{
Boolean success;
BOOL okay;
SCNetworkConnectionFlags status;
success = SCNetworkCheckReachabilityByName("www.apple.com",
&status);
okay = success && (status & kSCNetworkFlagsReachable) && !(status &
kSCNetworkFlagsConnectionRequired);
if (!okay)
{
success = SCNetworkCheckReachabilityByName("www.w3.org",
&status);
okay = success && (status & kSCNetworkFlagsReachable) &&
!(status & kSCNetworkFlagsConnectionRequired);
}
return okay;
}
Hope this helps.
--
David Sinclair, Dejal Systems, LLC - email@hidden
Let Dejal Simon keep an eye on your sites for changes or failures!
http://www.dejal.com/simon/
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.