Hello.
Earlier this week, I asked how I could determine network reachability from my
app. Someone replied to check the SystemConfiguration framework. I finally got
around to have a look and wrote the following code:
+ (BOOL)hostIsReachable:(NSString *)hostName
{
CFHostRef host;
assert(hostName != NULL);
/* Creates a new host object with the given name. */
host = CFHostCreateWithName(kCFAllocatorDefault, (CFStringRef)hostName);
assert(host != NULL);
SCNetworkReachabilityRef target =
SCNetworkReachabilityCreateWithName(NULL, [hostName
cStringUsingEncoding:NSUTF8StringEncoding]);
assert( target != NULL);
SCNetworkConnectionFlags flags;
SCNetworkReachabilityGetFlags(target, &flags);
BOOL result = (flags & kSCNetworkFlagsReachable);
NSLog(@"PLHostReachability: host %@ is reachable: %@", hostName, result
? @"yes" : @"no");
CFRelease(target);
return result;
}
However, no matter if I'm connected to the network or not,
SCNetworkReachabilityGetFlags() always returns any host to be reachable. Am I
missing something? Should I look for other flags? Any way to do this in Cocoa?
Thanks in advance!
-Laurent.
--
Laurent Daudelin
AIM/iChat/Skype:LaurentDaudelin
http://nemesys.dyndns.org
Logiciels Nemesys Software
[email protected]
Photo Gallery Store: http://laurentdaudelin.shutterbugstorefront.com/g/galleries
_______________________________________________
Cocoa-dev mailing list ([email protected])
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to [email protected]