]> git.saurik.com Git - apple/configd.git/blob - SystemConfiguration.fproj/SCNetworkReachabilityInternal.h
configd-1061.0.2.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 #include <nw/private.h>
42
43 #pragma mark -
44 #pragma mark SCNetworkReachability
45
46 #define kSCNetworkReachabilityFlagsMask 0x00ffffff // top 8-bits reserved for implementation
47
48
49 typedef enum {
50 NO = 0,
51 YES,
52 UNKNOWN
53 } lazyBoolean;
54
55 typedef enum {
56 ReachabilityRankNone = 0,
57 ReachabilityRankConnectionRequired = 1,
58 ReachabilityRankReachable = 2
59 } ReachabilityRankType;
60
61 typedef enum {
62 // by-address SCNetworkReachability targets
63 reachabilityTypeAddress,
64 reachabilityTypeAddressPair,
65 // by-name SCNetworkReachability targets
66 reachabilityTypeName,
67 reachabilityTypePTR
68 } ReachabilityAddressType;
69
70 #define isReachabilityTypeAddress(type) (type < reachabilityTypeName)
71 #define isReachabilityTypeName(type) (type >= reachabilityTypeName)
72
73 typedef struct {
74
75 /* base CFType information */
76 CFRuntimeBase cfBase;
77
78 /* lock */
79 pthread_mutex_t lock;
80
81 /* address type */
82 ReachabilityAddressType type;
83
84 /* target host name */
85 nw_endpoint_t hostnameEndpoint;
86
87 /* local & remote addresses */
88 nw_endpoint_t localAddressEndpoint;
89 nw_endpoint_t remoteAddressEndpoint;
90
91 /* run loop source, callout, context, rl scheduling info */
92 Boolean scheduled;
93 Boolean sentFirstUpdate;
94 CFRunLoopSourceRef rls;
95 SCNetworkReachabilityCallBack rlsFunction;
96 SCNetworkReachabilityContext rlsContext;
97 CFMutableArrayRef rlList;
98
99 dispatch_queue_t dispatchQueue; // SCNetworkReachabilitySetDispatchQueue
100
101 Boolean resolverBypass; // set this flag to bypass resolving the name
102
103 /* logging */
104 char log_prefix[32];
105
106 nw_parameters_t parameters;
107 nw_path_evaluator_t pathEvaluator;
108 nw_path_t lastPath;
109 nw_parameters_t lastPathParameters;
110 nw_resolver_t resolver;
111 nw_resolver_status_t lastResolverStatus;
112 nw_array_t lastResolvedEndpoints;
113 Boolean lastResolvedEndpointHasFlags;
114 SCNetworkReachabilityFlags lastResolvedEndpointFlags;
115 uint lastResolvedEndpointInterfaceIndex;
116
117 } SCNetworkReachabilityPrivate, *SCNetworkReachabilityPrivateRef;
118
119
120 // ------------------------------------------------------------
121
122
123 __BEGIN_DECLS
124
125 static __inline__ ReachabilityRankType
126 __SCNetworkReachabilityRank(SCNetworkReachabilityFlags flags)
127 {
128 ReachabilityRankType rank = ReachabilityRankNone;
129
130 if ((flags & kSCNetworkReachabilityFlagsReachable) != 0) {
131 rank = ReachabilityRankReachable;
132 if ((flags & kSCNetworkReachabilityFlagsConnectionRequired) != 0) {
133 rank = ReachabilityRankConnectionRequired;
134 }
135 }
136 return rank;
137 }
138
139
140 __END_DECLS
141
142 #endif // _SCNETWORKREACHABILITYINTERNAL_H