2 * Copyright (c) 2003-2015 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@
24 #ifndef _SCNETWORKREACHABILITYINTERNAL_H
25 #define _SCNETWORKREACHABILITYINTERNAL_H
27 #include <Availability.h>
28 #include <TargetConditionals.h>
29 #include <sys/cdefs.h>
30 #include <CoreFoundation/CoreFoundation.h>
31 #include <CoreFoundation/CFRuntime.h>
32 #include <SystemConfiguration/SystemConfiguration.h>
33 #include <SystemConfiguration/SCPrivate.h>
34 #include <dispatch/dispatch.h>
38 #include <sys/socket.h>
42 #include <network/private.h>
45 #pragma mark SCNetworkReachability
47 #define kSCNetworkReachabilityFlagsMask 0x00ffffff // top 8-bits reserved for implementation
58 // by-address SCNetworkReachability targets
59 reachabilityTypeAddress
,
60 reachabilityTypeAddressPair
,
61 // by-name SCNetworkReachability targets
64 } ReachabilityAddressType
;
66 #define isReachabilityTypeAddress(type) (type < reachabilityTypeName)
67 #define isReachabilityTypeName(type) (type >= reachabilityTypeName)
71 /* base CFType information */
78 ReachabilityAddressType type
;
80 /* target host name */
81 nw_endpoint_t hostnameEndpoint
;
83 /* local & remote addresses */
84 nw_endpoint_t localAddressEndpoint
;
85 nw_endpoint_t remoteAddressEndpoint
;
87 /* run loop source, callout, context, rl scheduling info */
89 Boolean sentFirstUpdate
;
90 CFRunLoopSourceRef rls
;
91 SCNetworkReachabilityCallBack rlsFunction
;
92 SCNetworkReachabilityContext rlsContext
;
93 CFMutableArrayRef rlList
;
95 dispatch_queue_t dispatchQueue
; // SCNetworkReachabilitySetDispatchQueue
97 Boolean resolverBypass
; // set this flag to bypass resolving the name
102 nw_parameters_t parameters
;
103 nw_path_evaluator_t pathEvaluator
;
105 nw_parameters_t lastPathParameters
;
106 nw_resolver_t resolver
;
107 nw_resolver_status_t lastResolverStatus
;
108 nw_array_t lastResolvedEndpoints
;
109 Boolean lastResolvedEndpointHasFlags
;
110 SCNetworkReachabilityFlags lastResolvedEndpointFlags
;
111 uint lastResolvedEndpointInterfaceIndex
;
113 } SCNetworkReachabilityPrivate
, *SCNetworkReachabilityPrivateRef
;
116 // ------------------------------------------------------------
122 _SCNetworkReachabilityCopyTargetDescription (SCNetworkReachabilityRef target
);
125 static __inline__ CFStringRef
126 __SCNetworkReachabilityCopyFlags(SCNetworkReachabilityFlags flags
, CFStringRef prefix
, Boolean debug
)
128 CFMutableStringRef str
= CFStringCreateMutable(NULL
, 0);
131 if (prefix
!= NULL
) {
132 CFStringAppend(str
, prefix
);
135 CFStringAppendFormat(str
, NULL
, CFSTR("0x%08x ("), flags
);
139 CFStringAppend(str
, CFSTR("Not Reachable"));
141 if (flags
& kSCNetworkReachabilityFlagsReachable
) {
142 flags
&= ~kSCNetworkReachabilityFlagsReachable
;
143 CFStringAppendFormat(str
, NULL
, CFSTR("Reachable%s"),
144 flags
!= 0 ? ", " : "");
146 if (flags
& kSCNetworkReachabilityFlagsTransientConnection
) {
147 flags
&= ~kSCNetworkReachabilityFlagsTransientConnection
;
148 CFStringAppendFormat(str
, NULL
, CFSTR("Transient Connection%s"),
149 flags
!= 0 ? ", " : "");
151 if (flags
& kSCNetworkReachabilityFlagsConnectionRequired
) {
152 flags
&= ~kSCNetworkReachabilityFlagsConnectionRequired
;
153 CFStringAppendFormat(str
, NULL
, CFSTR("Connection Required%s"),
154 flags
!= 0 ? ", " : "");
156 if (flags
& kSCNetworkReachabilityFlagsConnectionOnTraffic
) {
157 flags
&= ~kSCNetworkReachabilityFlagsConnectionOnTraffic
;
158 CFStringAppendFormat(str
, NULL
, CFSTR("Automatic Connection On Traffic%s"),
159 flags
!= 0 ? ", " : "");
161 if (flags
& kSCNetworkReachabilityFlagsConnectionOnDemand
) {
162 flags
&= ~kSCNetworkReachabilityFlagsConnectionOnDemand
;
163 CFStringAppendFormat(str
, NULL
, CFSTR("Automatic Connection On Demand%s"),
164 flags
!= 0 ? ", " : "");
166 if (flags
& kSCNetworkReachabilityFlagsInterventionRequired
) {
167 flags
&= ~kSCNetworkReachabilityFlagsInterventionRequired
;
168 CFStringAppendFormat(str
, NULL
, CFSTR("Intervention Required%s"),
169 flags
!= 0 ? ", " : "");
171 if (flags
& kSCNetworkReachabilityFlagsIsLocalAddress
) {
172 flags
&= ~kSCNetworkReachabilityFlagsIsLocalAddress
;
173 CFStringAppendFormat(str
, NULL
, CFSTR("Local Address%s"),
174 flags
!= 0 ? ", " : "");
176 if (flags
& kSCNetworkReachabilityFlagsIsDirect
) {
177 flags
&= ~kSCNetworkReachabilityFlagsIsDirect
;
178 CFStringAppendFormat(str
, NULL
, CFSTR("Directly Reachable Address%s"),
179 flags
!= 0 ? ", " : "");
182 if (flags
& kSCNetworkReachabilityFlagsIsWWAN
) {
183 flags
&= ~kSCNetworkReachabilityFlagsIsWWAN
;
184 CFStringAppendFormat(str
, NULL
, CFSTR("WWAN%s"), flags
!= 0 ? ", " : "");
186 #endif // TARGET_OS_IPHONE
188 CFStringAppendFormat(str
, NULL
, CFSTR("0x%08x"), flags
);
192 CFStringAppend(str
, CFSTR(")"));
201 #endif // _SCNETWORKREACHABILITYINTERNAL_H