2 * Copyright (c) 2003-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@
24 #ifndef _SCNETWORKREACHABILITYINTERNAL_H
25 #define _SCNETWORKREACHABILITYINTERNAL_H
27 #include <os/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>
37 #include <sys/socket.h>
41 #if __has_include(<nw/private.h>)
42 #include <nw/private.h>
43 #else // __has_include(<nw/private.h>)
44 #include <network/private.h>
45 #endif // __has_include(<nw/private.h>)
48 #pragma mark SCNetworkReachability
50 #define kSCNetworkReachabilityFlagsMask 0x00ffffff // top 8-bits reserved for implementation
60 ReachabilityRankNone
= 0,
61 ReachabilityRankConnectionRequired
= 1,
62 ReachabilityRankReachable
= 2
63 } ReachabilityRankType
;
66 // by-address SCNetworkReachability targets
67 reachabilityTypeAddress
,
68 reachabilityTypeAddressPair
,
69 // by-name SCNetworkReachability targets
72 } ReachabilityAddressType
;
74 #define isReachabilityTypeAddress(type) (type < reachabilityTypeName)
75 #define isReachabilityTypeName(type) (type >= reachabilityTypeName)
79 /* base CFType information */
86 ReachabilityAddressType type
;
88 /* target host name */
89 nw_endpoint_t hostnameEndpoint
;
91 /* local & remote addresses */
92 nw_endpoint_t localAddressEndpoint
;
93 nw_endpoint_t remoteAddressEndpoint
;
95 /* run loop source, callout, context, rl scheduling info */
97 Boolean sentFirstUpdate
;
98 CFRunLoopSourceRef rls
;
99 SCNetworkReachabilityCallBack rlsFunction
;
100 SCNetworkReachabilityContext rlsContext
;
101 CFMutableArrayRef rlList
;
103 dispatch_queue_t dispatchQueue
; // SCNetworkReachabilitySetDispatchQueue
105 Boolean resolverBypass
; // set this flag to bypass resolving the name
110 nw_parameters_t parameters
;
111 nw_path_evaluator_t pathEvaluator
;
113 nw_parameters_t lastPathParameters
;
114 nw_resolver_t resolver
;
115 nw_resolver_status_t lastResolverStatus
;
116 nw_array_t lastResolvedEndpoints
;
117 Boolean lastResolvedEndpointHasFlags
;
118 SCNetworkReachabilityFlags lastResolvedEndpointFlags
;
119 uint lastResolvedEndpointInterfaceIndex
;
121 } SCNetworkReachabilityPrivate
, *SCNetworkReachabilityPrivateRef
;
124 // ------------------------------------------------------------
129 static __inline__ ReachabilityRankType
130 __SCNetworkReachabilityRank(SCNetworkReachabilityFlags flags
)
132 ReachabilityRankType rank
= ReachabilityRankNone
;
134 if ((flags
& kSCNetworkReachabilityFlagsReachable
) != 0) {
135 rank
= ReachabilityRankReachable
;
136 if ((flags
& kSCNetworkReachabilityFlagsConnectionRequired
) != 0) {
137 rank
= ReachabilityRankConnectionRequired
;
146 #endif // _SCNETWORKREACHABILITYINTERNAL_H