Re: behaviour of SCNetworkCheckReachablityByName
Re: behaviour of SCNetworkCheckReachablityByName
- Subject: Re: behaviour of SCNetworkCheckReachablityByName
- From: Allan Nathanson <email@hidden>
- Date: Sat, 29 Apr 2006 11:21:49 -0400
On Apr 29, 2006, at 8:42 AM, Gurmit Teotia wrote:
Hi All,
In my application I will have to check at regular interval if a
computer is connected to network or not. To implement this
funtionality I was checking the behaviour of
SCNetworkCheckReachablityByName.
Below is the code snippet:
SCNetworkConnectionFlags status;
BOOL result;
result=SCNetworkCheckReachabilityByName("XYZ",&status);
NSLog(@"Result= %d status=%d",result,status);
Output is always Result=1 status=0 whether "XYZ" computer is
connected to network or not. If I include domain name computer name
as follow:
result==1 (TRUE, the SCNetworkConnectionFlags are valid)
status==0 (Not reachable, most likely because the specified hostname
could not be resolved)
SCNetworkConnectionFlags status;
BOOL result;
result=SCNetworkCheckReachabilityByName("XYZ.MyDomain.com",&status);
NSLog(@"Result= %d status=%d",result,status);
Then output is always "Result=1 status=2" whether computer is
connected to network or not.
result==1 (TRUE, the SCNetworkConnectionFlags are valid)
status==0 (Reachable)
Are you sure that you're getting a status=2 when the computer is not
connected to the network. In many cases you'll get back a status=6
(kSCNetworkFlagsReachable|kSCNetworkFlagsConnectionRequired) which
says "yes, you can (may) reach this host but you must first establish
a connection using your Built-in modem). Most applications should be
testing for :
reachable = ((flags & kSCNetworkFlagsReachable) && !(flags &
kSCNetworkFlagsConnectionRequired));
Can someone explain this behaviour? Is that behaviour correct?
Please also suggest if I'm using the right approach to check if a
computer is connected to network or not.
Unless your code needs to work on a pre-Panther system I'd suggestion
you look at the reachability APIs found in <SystemConfiguration/
SCNetworkReachability.h>. For synchronous requests the APIs will give
you back the same results but you now have the option to setup an
asynchronous notification when the reachability flags change. Using
the notification you can skip having to poll if the network is
available.
- Allan
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden