• 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
Re: SCNetworkReachabilityCreateWithAddress() & Callback?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: SCNetworkReachabilityCreateWithAddress() & Callback?


  • Subject: Re: SCNetworkReachabilityCreateWithAddress() & Callback?
  • From: Allan Nathanson <email@hidden>
  • Date: Thu, 28 May 2009 21:26:09 -0400

A callback is issued when there is a CHANGE in the reachability. For names, the change occurs once the name has been resolved. For addresses, the reachability flags are already known so there's no change to report. In short, for addresses, follow your call to SCNetworkReachabilitySCheduleWithRunLoop() with a call to SCNetworkReachabilityGetFlags(). That will give you the current reachability status and you'll get a notification should that status ever change. For names, you "can" call SCNetworkReachabilityGetFlags () after scheduling and then, after the name resolution process has completed, you'll get a callback.

- Allan



On May 28, 2009, at 9:07 PM, Karl Moskowski wrote:


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



_______________________________________________
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


References: 
 >SCNetworkReachabilityCreateWithAddress() & Callback? (From: Karl Moskowski <email@hidden>)

  • Prev by Date: SCNetworkReachabilityCreateWithAddress() & Callback?
  • Next by Date: Re: Crash in CFReadStreamOpen
  • Previous by thread: SCNetworkReachabilityCreateWithAddress() & Callback?
  • Index(es):
    • Date
    • Thread