//
//  main.m
//  SCTest
//
//

#import <Cocoa/Cocoa.h>

#import <SystemConfiguration/SCNetworkReachability.h>
#include <netinet/in.h>

static void ReachabilityCallback(SCNetworkReachabilityRef target, SCNetworkConnectionFlags flags, void *info)
{
	NSLog(@"SCNetworkReachability Callback flags is %d", flags);
}

int main(int argc, char *argv[])
{
	SCNetworkReachabilityRef reachability;
	SCNetworkConnectionFlags flags;
	
	struct sockaddr_in zeroAddress;
	bzero(&zeroAddress, sizeof(zeroAddress));
	zeroAddress.sin_len = sizeof(zeroAddress);
	zeroAddress.sin_family = AF_INET;

	reachability = SCNetworkReachabilityCreateWithAddress(NULL, (struct sockaddr *)&zeroAddress);

	if(SCNetworkReachabilityGetFlags(reachability, &flags) == YES) {
		NSLog(@"SCNetworkReachabilityGetFlags flags is %d", flags);
	} else {
		NSLog(@"SCNetworkReachabilityGetFlags is the status could not be determined");
	}
	
	SCNetworkReachabilityContext	context = {0, NULL, NULL, NULL, NULL};
	SCNetworkReachabilitySetCallback(reachability, ReachabilityCallback, &context);
	SCNetworkReachabilityScheduleWithRunLoop(reachability, [[NSRunLoop currentRunLoop] getCFRunLoop], kCFRunLoopDefaultMode);
	
    return NSApplicationMain(argc,  (const char **) argv);
}
