]> git.saurik.com Git - apple/configd.git/blob - SystemConfiguration.fproj/SCNetworkReachabilityInternal.h
configd-963.200.27.tar.gz
[apple/configd.git] / SystemConfiguration.fproj / SCNetworkReachabilityInternal.h
1 /*
2 * Copyright (c) 2003-2018 Apple Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
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
11 * file.
12 *
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.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24 #ifndef _SCNETWORKREACHABILITYINTERNAL_H
25 #define _SCNETWORKREACHABILITYINTERNAL_H
26
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>
35
36 #include <netdb.h>
37 #include <sys/socket.h>
38 #include <net/if.h>
39 #include <xpc/xpc.h>
40
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>)
46
47 #pragma mark -
48 #pragma mark SCNetworkReachability
49
50 #define kSCNetworkReachabilityFlagsMask 0x00ffffff // top 8-bits reserved for implementation
51
52
53 typedef enum {
54 NO = 0,
55 YES,
56 UNKNOWN
57 } lazyBoolean;
58
59 typedef enum {
60 ReachabilityRankNone = 0,
61 ReachabilityRankConnectionRequired = 1,
62 ReachabilityRankReachable = 2
63 } ReachabilityRankType;
64
65 typedef enum {
66 // by-address SCNetworkReachability targets
67 reachabilityTypeAddress,
68 reachabilityTypeAddressPair,
69 // by-name SCNetworkReachability targets
70 reachabilityTypeName,
71 reachabilityTypePTR
72 } ReachabilityAddressType;
73
74 #define isReachabilityTypeAddress(type) (type < reachabilityTypeName)
75 #define isReachabilityTypeName(type) (type >= reachabilityTypeName)
76
77 typedef struct {
78
79 /* base CFType information */
80 CFRuntimeBase cfBase;
81
82 /* lock */
83 pthread_mutex_t lock;
84
85 /* address type */
86 ReachabilityAddressType type;
87
88 /* target host name */
89 nw_endpoint_t hostnameEndpoint;
90
91 /* local & remote addresses */
92 nw_endpoint_t localAddressEndpoint;
93 nw_endpoint_t remoteAddressEndpoint;
94
95 /* run loop source, callout, context, rl scheduling info */
96 Boolean scheduled;
97 Boolean sentFirstUpdate;
98 CFRunLoopSourceRef rls;
99 SCNetworkReachabilityCallBack rlsFunction;
100 SCNetworkReachabilityContext rlsContext;
101 CFMutableArrayRef rlList;
102
103 dispatch_queue_t dispatchQueue; // SCNetworkReachabilitySetDispatchQueue
104
105 Boolean resolverBypass; // set this flag to bypass resolving the name
106
107 /* logging */
108 char log_prefix[32];
109
110 nw_parameters_t parameters;
111 nw_path_evaluator_t pathEvaluator;
112 nw_path_t lastPath;
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;
120
121 } SCNetworkReachabilityPrivate, *SCNetworkReachabilityPrivateRef;
122
123
124 // ------------------------------------------------------------
125
126
127 __BEGIN_DECLS
128
129 static __inline__ ReachabilityRankType
130 __SCNetworkReachabilityRank(SCNetworkReachabilityFlags flags)
131 {
132 ReachabilityRankType rank = ReachabilityRankNone;
133
134 if ((flags & kSCNetworkReachabilityFlagsReachable) != 0) {
135 rank = ReachabilityRankReachable;
136 if ((flags & kSCNetworkReachabilityFlagsConnectionRequired) != 0) {
137 rank = ReachabilityRankConnectionRequired;
138 }
139 }
140 return rank;
141 }
142
143
144 __END_DECLS
145
146 #endif // _SCNETWORKREACHABILITYINTERNAL_H