Re: behaviour of SCNetworkCheckReachablityByName
Re: behaviour of SCNetworkCheckReachablityByName
- Subject: Re: behaviour of SCNetworkCheckReachablityByName
- From: "Gurmit Teotia" <email@hidden>
- Date: Mon, 1 May 2006 11:39:25 +0530
Hi Allan,
I have double check the code. I'm always getting 2 in status whether target computer is connected to network or not.
Most applications should be
testing for :
reachable = ((flags & kSCNetworkFlagsReachable) && !(flags &
kSCNetworkFlagsConnectionRequired));
In fact I'm using the same _expression_ to check the connectity but when I got this behaviour I print the value of status and post it to list.
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.
That is a good idea. I'm targetting my application for tiger so above suggestion will work for me.
I'll use the asynchronous notification approach and let you know the result.
Allan, I have one more question. In my application target computer can be across a VPN. If I have to give the domain name for checking reachablity, how can I get the domain name of such computer by nam? Is there any such API? BTW in above issue both source and target exist in same network.
Thanks for your quick response.
Regards,
Gurmit
On 4/29/06, Allan Nathanson <email@hidden> wrote:
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