2 * Copyright (c) 2015 Apple Inc. All rights reserved.
4 * A Objective-C test target to test SC APIs
6 * Created by Sushant Chavan on 4/21/15.
10 @import SystemConfiguration;
12 #define MY_APP_NAME CFSTR("SCTestObjC")
13 #define TARGET_HOST "www.apple.com"
16 test_SCNetworkConfiguration()
18 NSLog(@"\n\n*** SCNetworkConfiguration ***\n\n");
21 CFArrayRef interfaces;
23 interfaces = SCNetworkInterfaceCopyAll();
24 count = CFArrayGetCount(interfaces);
25 NSLog(@"Network Interfaces:\n");
26 for (idx=0; idx < count; idx++) {
27 SCNetworkInterfaceRef intf;
30 intf = CFArrayGetValueAtIndex(interfaces, idx);
31 bsdName = SCNetworkInterfaceGetBSDName(intf);
32 NSLog(@"- %@", bsdName);
35 CFRelease(interfaces);
41 NSLog(@"\n\n*** SCDynamicStore ***\n\n");
45 SCDynamicStoreRef store;
47 store = SCDynamicStoreCreate(NULL, MY_APP_NAME, NULL, NULL);
48 key = SCDynamicStoreKeyCreateNetworkGlobalEntity(NULL, kSCDynamicStoreDomainState, kSCEntNetIPv4);
49 dict = SCDynamicStoreCopyValue(store, key);
50 intf = CFDictionaryGetValue(dict, kSCDynamicStorePropNetPrimaryInterface);
51 NSLog(@"- Primary Interface is %@\n", intf);
61 NSLog(@"\n\n*** SCPreferences ***\n\n");
64 CFStringRef model = NULL;
65 SCPreferencesRef prefs;
68 prefs = SCPreferencesCreate(NULL, MY_APP_NAME, NULL);
69 model = SCPreferencesGetValue(prefs, CFSTR("Model"));
71 NSLog(@"Current model is %@", model);
74 services = SCNetworkServiceCopyAll(prefs);
75 count = CFArrayGetCount(services);
76 NSLog(@"Network Services:\n");
77 for (idx = 0; idx < count; idx++) {
78 SCNetworkServiceRef serv;
81 serv = CFArrayGetValueAtIndex(services, idx);
82 servName = SCNetworkServiceGetName(serv);
83 NSLog(@"- %@\n", servName);
91 test_SCNetworkReachability()
93 NSLog(@"\n\n*** SCNetworkReachability ***\n\n");
94 SCNetworkReachabilityFlags flags;
95 SCNetworkReachabilityRef target;
97 target = SCNetworkReachabilityCreateWithName(NULL, TARGET_HOST);
98 (void)SCNetworkReachabilityGetFlags(target, &flags);
99 NSLog(@"- Reachability flags for "TARGET_HOST": %#x", flags);
107 test_SCNetworkConfiguration();
108 test_SCNetworkReachability();
109 test_SCPreferences();
110 test_SCDynamicStore();
113 int main(int argc, const char * argv[]) {