2 * Copyright (c) 2015, 2018 Apple Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
25 * Modification History
27 * April 21, 2015 Sushant Chavan
32 * A Objective-C test target to test SC APIs
35 #import <TargetConditionals.h>
37 @import SystemConfiguration;
38 @import SystemConfiguration_Private;
40 #define MY_APP_NAME CFSTR("SCTestObjC")
41 #define TARGET_HOST "www.apple.com"
44 #if !TARGET_OS_SIMULATOR
48 NSLog(@"\n\n*** SCDynamicStore ***\n\n");
52 SCDynamicStoreRef store;
54 store = SCDynamicStoreCreate(NULL, MY_APP_NAME, NULL, NULL);
55 key = SCDynamicStoreKeyCreateNetworkGlobalEntity(NULL, kSCDynamicStoreDomainState, kSCEntNetIPv4);
56 dict = SCDynamicStoreCopyValue(store, key);
57 intf = CFDictionaryGetValue(dict, kSCDynamicStorePropNetPrimaryInterface);
58 NSLog(@"- Primary Interface is %@\n", intf);
64 #endif // !TARGET_OS_SIMULATOR
66 #if !TARGET_OS_SIMULATOR
68 test_SCNetworkConfiguration()
70 NSLog(@"\n\n*** SCNetworkConfiguration ***\n\n");
73 CFArrayRef interfaces;
75 interfaces = SCNetworkInterfaceCopyAll();
76 count = CFArrayGetCount(interfaces);
77 NSLog(@"Network Interfaces:\n");
78 for (idx=0; idx < count; idx++) {
79 SCNetworkInterfaceRef intf;
82 intf = CFArrayGetValueAtIndex(interfaces, idx);
83 bsdName = SCNetworkInterfaceGetBSDName(intf);
84 NSLog(@"- %@", bsdName);
87 CFRelease(interfaces);
89 #endif // !TARGET_OS_SIMULATOR
92 test_SCNetworkReachability()
94 NSLog(@"\n\n*** SCNetworkReachability ***\n\n");
95 SCNetworkReachabilityFlags flags;
96 SCNetworkReachabilityRef target;
98 target = SCNetworkReachabilityCreateWithName(NULL, TARGET_HOST);
99 (void)SCNetworkReachabilityGetFlags(target, &flags);
100 NSLog(@"- Reachability flags for "TARGET_HOST": %#x", flags);
105 #if !TARGET_OS_SIMULATOR
109 NSLog(@"\n\n*** SCPreferences ***\n\n");
112 CFStringRef model = NULL;
113 SCPreferencesRef prefs;
116 prefs = SCPreferencesCreate(NULL, MY_APP_NAME, NULL);
117 model = SCPreferencesGetValue(prefs, CFSTR("Model"));
119 NSLog(@"Current model is %@", model);
122 services = SCNetworkServiceCopyAll(prefs);
123 count = CFArrayGetCount(services);
124 NSLog(@"Network Services:\n");
125 for (idx = 0; idx < count; idx++) {
126 SCNetworkServiceRef serv;
127 CFStringRef servName;
129 serv = CFArrayGetValueAtIndex(services, idx);
130 servName = SCNetworkServiceGetName(serv);
131 NSLog(@"- %@\n", servName);
137 #endif // !TARGET_OS_SIMULATOR
143 #if !TARGET_OS_SIMULATOR
144 test_SCDynamicStore();
145 #endif // !TARGET_OS_SIMULATOR
147 #if !TARGET_OS_SIMULATOR
148 test_SCNetworkConfiguration();
149 #endif // !TARGET_OS_SIMULATOR
151 test_SCNetworkReachability();
153 #if !TARGET_OS_SIMULATOR
154 test_SCPreferences();
155 #endif // !TARGET_OS_SIMULATOR
159 int main(int argc, const char * argv[]) {
160 #pragma unused(argc, argv)