• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
SCNetworkReachabilityCreateWithAddress() & Callback?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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
  • Follow-Ups:
    • Re: SCNetworkReachabilityCreateWithAddress() & Callback?
      • From: Allan Nathanson <email@hidden>
  • Prev by Date: Re: Crash in CFReadStreamOpen
  • Next by Date: Re: SCNetworkReachabilityCreateWithAddress() & Callback?
  • Previous by thread: Re: Posted read() hangs on socket disconnect
  • Next by thread: Re: SCNetworkReachabilityCreateWithAddress() & Callback?
  • Index(es):
    • Date
    • Thread