SCNetworkReachabilityCreateWithAddress() & Callback?
SCNetworkReachabilityCreateWithAddress() & Callback?
- Subject: SCNetworkReachabilityCreateWithAddress() & Callback?
- From: Karl Moskowski <email@hidden>
- Date: Thu, 28 May 2009 21:07:55 -0400
I'm trying to implement a network reachability check in my Leopard app
(on 10.5.7), and I'm seeing different behaviour depending on wether I
use SCNetworkReachabilityCreateWithName() or
SCNetworkReachabilityCreateWithAddress().
If I use SCNetworkReachabilityCreateWithName(), passing a host name,
the callback method is triggered correctly. If I use
SCNetworkReachabilityCreateWithAddress(), passing an IP address, the
callback function is never called. The code below illustrates this.
Am I missing something or does it just not work with
SCNetworkReachabilityCreateWithAddress()?
TIA.
----
Karl Moskowski <email@hidden>
Voodoo Ergonomics Inc. <http://voodooergonomics.com/>
#import <Foundation/Foundation.h>
#import <SystemConfiguration/SCNetworkReachability.h>
#include <netinet/in.h>
#include <arpa/inet.h>
static void ReachabilityCallback(SCNetworkReachabilityRef target,
SCNetworkConnectionFlags flags, void *info) {
NSLog(@"SCNetworkReachability Callback flags: %d", flags);
}
int main (int argc, const char * argv[]) {
struct sockaddr_in sin;
bzero(&sin, sizeof(sin));
sin.sin_len = sizeof(sin);
sin.sin_family = AF_INET;
inet_aton("17.251.200.32", &sin.sin_addr);
// doesn't work:
SCNetworkReachabilityRef reachability =
SCNetworkReachabilityCreateWithAddress(NULL, (struct sockaddr *)&sin);
// works:
// SCNetworkReachabilityRef reachability =
SCNetworkReachabilityCreateWithName(NULL, "www.apple.com");
SCNetworkReachabilityContext context = {0, NULL, NULL, NULL, NULL};
SCNetworkReachabilitySetCallback(reachability, ReachabilityCallback,
&context);
SCNetworkReachabilityScheduleWithRunLoop(reachability, [[NSRunLoop
currentRunLoop] getCFRunLoop], kCFRunLoopDefaultMode);
[[NSRunLoop currentRunLoop] run];
return 0;
}
_______________________________________________
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