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: Marc Weil <email@hidden>
- Date: Sat, 15 Mar 2003 14:41:57 -0500
On 3/15/03 1:37 PM, "David Sinclair" <email@hidden> wrote:
>
>
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.
Ahh, excellent. That worked wonderfully for me. The if statement doesn't
execute if there is no active internet connection, and it does execute if
there is an active internet connection. I still think it is kind of strange
that kSCNetworkFlagsReachable is set even if there is no active internet
connection. Oh well. I guess it is just a fluke on Apple's part. As long as
it works, that's all that ultimately matters. :-)
Thanks again!
Marc Weil
_______________________________________________
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.