2 * Copyright (c) 2015, 2018, 2020 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 #if !defined(USING_PUBLIC_SDK)
39 @import SystemConfiguration;
40 @import SystemConfiguration_Private;
41 #else // !defined(USING_PUBLIC_SDK)
42 #include <Foundation/Foundation.h>
43 #include <SystemConfiguration/SystemConfiguration.h>
44 #endif // !defined(USING_PUBLIC_SDK)
46 #if TARGET_OS_MACCATALYST
47 #pragma message "Building for IOS_MAC"
50 #define MY_APP_NAME CFSTR("SCTestObjC")
51 #define TARGET_HOST "www.apple.com"
54 #if !TARGET_OS_SIMULATOR && !defined(USING_PUBLIC_SDK)
58 NSLog(@"\n\n*** SCDynamicStore ***\n\n");
62 SCDynamicStoreRef store;
64 store = SCDynamicStoreCreate(NULL, MY_APP_NAME, NULL, NULL);
65 key = SCDynamicStoreKeyCreateNetworkGlobalEntity(NULL, kSCDynamicStoreDomainState, kSCEntNetIPv4);
66 dict = SCDynamicStoreCopyValue(store, key);
67 intf = CFDictionaryGetValue(dict, kSCDynamicStorePropNetPrimaryInterface);
68 NSLog(@"- Primary Interface is %@\n", intf);
74 #endif // !TARGET_OS_SIMULATOR && !defined(USING_PUBLIC_SDK)
76 #if !TARGET_OS_SIMULATOR && !defined(USING_PUBLIC_SDK)
78 test_SCNetworkConfiguration()
80 NSLog(@"\n\n*** SCNetworkConfiguration ***\n\n");
83 CFArrayRef interfaces;
85 interfaces = SCNetworkInterfaceCopyAll();
86 count = CFArrayGetCount(interfaces);
87 NSLog(@"Network Interfaces:\n");
88 for (idx=0; idx < count; idx++) {
89 SCNetworkInterfaceRef intf;
92 intf = CFArrayGetValueAtIndex(interfaces, idx);
93 bsdName = SCNetworkInterfaceGetBSDName(intf);
94 NSLog(@"- %@", bsdName);
97 CFRelease(interfaces);
99 #endif // !TARGET_OS_SIMULATOR && !defined(USING_PUBLIC_SDK)
102 test_SCNetworkReachability()
104 NSLog(@"\n\n*** SCNetworkReachability ***\n\n");
105 SCNetworkReachabilityFlags flags;
106 SCNetworkReachabilityRef target;
108 target = SCNetworkReachabilityCreateWithName(NULL, TARGET_HOST);
109 (void)SCNetworkReachabilityGetFlags(target, &flags);
110 NSLog(@"- Reachability flags for "TARGET_HOST": %#x", flags);
115 #if !TARGET_OS_SIMULATOR && !defined(USING_PUBLIC_SDK)
119 NSLog(@"\n\n*** SCPreferences ***\n\n");
122 CFStringRef model = NULL;
123 SCPreferencesRef prefs;
126 prefs = SCPreferencesCreate(NULL, MY_APP_NAME, NULL);
127 model = SCPreferencesGetValue(prefs, CFSTR("Model"));
129 NSLog(@"Current model is %@", model);
132 services = SCNetworkServiceCopyAll(prefs);
133 count = CFArrayGetCount(services);
134 NSLog(@"Network Services:\n");
135 for (idx = 0; idx < count; idx++) {
136 SCNetworkServiceRef serv;
137 CFStringRef servName;
139 serv = CFArrayGetValueAtIndex(services, idx);
140 servName = SCNetworkServiceGetName(serv);
141 NSLog(@"- %@\n", servName);
147 #endif // !TARGET_OS_SIMULATOR && !defined(USING_PUBLIC_SDK)
153 #if !TARGET_OS_SIMULATOR && !defined(USING_PUBLIC_SDK)
154 test_SCDynamicStore();
155 #endif // !TARGET_OS_SIMULATOR && !defined(USING_PUBLIC_SDK)
157 #if !TARGET_OS_SIMULATOR && !defined(USING_PUBLIC_SDK)
158 test_SCNetworkConfiguration();
159 #endif // !TARGET_OS_SIMULATOR && !defined(USING_PUBLIC_SDK)
161 test_SCNetworkReachability();
163 #if !TARGET_OS_SIMULATOR && !defined(USING_PUBLIC_SDK)
164 test_SCPreferences();
165 #endif // !TARGET_OS_SIMULATOR && !defined(USING_PUBLIC_SDK)
170 main(int argc, const char * argv[]) {
171 #pragma unused(argc, argv)
173 #if TARGET_OS_MACCATALYST
174 #if !defined(USING_PUBLIC_SDK)
175 #include <CoreFoundation/CFPriv.h>
176 #else // !defined(USING_PUBLIC_SDK)
177 extern Boolean _CFMZEnabled(void);
178 #endif // !defined(USING_PUBLIC_SDK)
179 if (_CFMZEnabled()) {
180 NSLog(@"*** IOS_MAC ***\n");