void SCNetworkEventPublisher::addHostname( const SCNetworkSubscriptionContextRef& sc) { auto target = SCNetworkReachabilityCreateWithName(nullptr, sc->target.c_str()); target_names_.push_back(sc->target); addTarget(sc, target); }
int main (int argc, const char * argv[]) { SCNetworkReachabilityRef r = SCNetworkReachabilityCreateWithName(NULL, "api.del.icio.us"); if(r == NULL) { printf("Error creating reachability reference.\n"); goto bail; } if(!SCNetworkReachabilitySetCallback(r, my_SCNetworkReachabilityCallBack, NULL)) { printf("Unable to set reachability callback\n"); goto bail; } if(!SCNetworkReachabilityScheduleWithRunLoop(r, CFRunLoopGetCurrent(), kCFRunLoopCommonModes)) { printf("Unable to schedule run loop monitoring on run loop.\n"); goto bail; } printf("Starting run loop. Enable and disable network interfaces to fire the callback.\n"); CFRunLoopRun(); printf("Run loop stopped\n"); bail: if(r) CFRelease(r); return 0; }
lastfm::InternetConnectionMonitor::InternetConnectionMonitor( QObject *parent ) : QObject( parent ) , m_up( true ) { #ifdef __APPLE__ if (monitors.isEmpty()) { SCNetworkReachabilityRef ref = SCNetworkReachabilityCreateWithName( NULL, LASTFM_WS_HOSTNAME ); SCNetworkReachabilityScheduleWithRunLoop( ref, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode ); SCNetworkReachabilitySetCallback( ref, callback, NULL ); CFRelease( ref ); } QPointer<InternetConnectionMonitor> p = this; monitors += p; #endif #ifdef WIN32 m_ndisEventsProxy = new NdisEventsProxy(this); m_ndisEventsProxy->registerForNdisEvents(); #endif }
Boolean SCNetworkCheckReachabilityByName(const char *nodename, SCNetworkConnectionFlags *flags) { SCNetworkReachabilityRef networkAddress; Boolean ok; if (!nodename) { _SCErrorSet(kSCStatusInvalidArgument); return FALSE; } networkAddress = SCNetworkReachabilityCreateWithName(NULL, nodename); if (networkAddress == NULL) { return FALSE; } ok = SCNetworkReachabilityGetFlags(networkAddress, flags); CFRelease(networkAddress); return ok; }
void NetworkStatus::InitializeLoop() { primaryTarget = SCNetworkReachabilityCreateWithName(0, "www.google.com"); secondaryTarget = SCNetworkReachabilityCreateWithName(0, "www.yahoo.com"); }