2 * Copyright (c) 2003-2012 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 <dispatch/dispatch.h>
37 #include <sys/socket.h>
40 #if ((__MAC_OS_X_VERSION_MIN_REQUIRED >= 1080) || (__IPHONE_OS_VERSION_MIN_REQUIRED >= 50000)) && !TARGET_IPHONE_SIMULATOR
41 #define HAVE_REACHABILITY_SERVER
43 #endif // ((__MAC_OS_X_VERSION_MIN_REQUIRED >= 1080) || (__IPHONE_OS_VERSION_MIN_REQUIRED >= 50000)) && !TARGET_IPHONE_SIMULATOR
47 #pragma mark SCNetworkReachability
50 #define kSCNetworkReachabilityFlagsFirstResolvePending (1<<31)
53 typedef enum { NO
= 0, YES
, UNKNOWN
} lazyBoolean
;
57 reachabilityTypeAddress
,
58 reachabilityTypeAddressPair
,
60 } ReachabilityAddressType
;
65 SCNetworkReachabilityFlags flags
;
66 unsigned int if_index
;
67 char if_name
[IFNAMSIZ
];
74 /* base CFType information */
81 ReachabilityAddressType type
;
83 /* target host name */
86 struct addrinfo hints
;
88 CFArrayRef resolvedAddress
; /* CFArray[CFData] */
89 int resolvedAddressError
;
91 /* [scoped routing] interface constraints */
92 unsigned int if_index
;
93 char if_name
[IFNAMSIZ
];
95 /* local & remote addresses */
96 struct sockaddr
*localAddress
;
97 struct sockaddr
*remoteAddress
;
99 /* current reachability flags */
101 ReachabilityInfo info
;
102 ReachabilityInfo last_notify
;
104 /* run loop source, callout, context, rl scheduling info */
106 CFRunLoopSourceRef rls
;
107 SCNetworkReachabilityCallBack rlsFunction
;
108 SCNetworkReachabilityContext rlsContext
;
109 CFMutableArrayRef rlList
;
111 dispatch_group_t dispatchGroup
;
112 dispatch_queue_t dispatchQueue
; // SCNetworkReachabilitySetDispatchQueue
114 /* [async] DNS query info */
116 mach_port_t dnsMP
; // != MACH_PORT_NULL (if active)
117 CFMachPortRef dnsPort
; // for CFRunLoop queries
118 CFRunLoopSourceRef dnsRLS
; // for CFRunLoop queries
119 dispatch_source_t dnsSource
; // for dispatch queries
120 struct timeval dnsQueryStart
;
121 struct timeval dnsQueryEnd
;
122 dispatch_source_t dnsRetry
; // != NULL if DNS retry request queued
123 int dnsRetryCount
; // number of retry attempts
125 /* [async] processing info */
126 struct timeval last_dns
;
127 struct timeval last_network
;
128 #if !TARGET_OS_IPHONE
129 struct timeval last_power
;
130 #endif // !TARGET_OS_IPHONE
131 struct timeval last_push
;
134 Boolean onDemandBypass
;
135 CFStringRef onDemandName
;
136 CFStringRef onDemandRemoteAddress
;
137 SCNetworkReachabilityRef onDemandServer
;
138 CFStringRef onDemandServiceID
;
143 DNSServiceRef llqTarget
;
144 dispatch_source_t llqTimer
; // != NULL while waiting for first callback
146 #ifdef HAVE_REACHABILITY_SERVER
147 /* SCNetworkReachability server "client" info */
148 Boolean serverActive
;
149 Boolean serverBypass
;
150 Boolean serverScheduled
;
151 ReachabilityInfo serverInfo
;
153 /* SCNetworkReachability server "server" info */
154 CFDataRef serverDigest
;
155 dispatch_group_t serverGroup
;
156 Boolean serverInfoValid
;
157 unsigned int serverQueryActive
; // 0 == no query active, else # waiting on group
158 dispatch_queue_t serverQueue
;
159 unsigned int serverReferences
; // how many [client] targets
160 CFMutableDictionaryRef serverWatchers
; // [client_id/target_id] watchers
161 #endif // HAVE_REACHABILITY_SERVER
162 Boolean resolverBypass
; // set this flag to bypass resolving the name
167 } SCNetworkReachabilityPrivate
, *SCNetworkReachabilityPrivateRef
;
170 #ifdef HAVE_REACHABILITY_SERVER
172 // ------------------------------------------------------------
175 #pragma mark [XPC] Reachability Server
178 #define REACH_SERVER_VERSION 20110323
179 #define REACH_SERVICE_NAME "com.apple.SystemConfiguration.SCNetworkReachability"
181 // ------------------------------------------------------------
185 #pragma mark [XPC] Reachability Server (client->server request)
188 #define REACH_CLIENT_PROC_NAME "proc_name" // string
189 #define REACH_CLIENT_TARGET_ID "target_id" // uint64
191 #define REACH_REQUEST "request_op" // int64
194 REACH_REQUEST_CREATE
= 0x0001,
195 REACH_REQUEST_REMOVE
,
196 REACH_REQUEST_SCHEDULE
,
197 REACH_REQUEST_STATUS
,
198 REACH_REQUEST_UNSCHEDULE
,
199 REACH_REQUEST_SNAPSHOT
= 0x0101,
202 #define REACH_TARGET_NAME "name" // string
203 #define REACH_TARGET_SERV "serv" // string
204 #define REACH_TARGET_HINTS "hints" // data (struct addrinfo)
205 #define REACH_TARGET_IF_INDEX "if_index" // int64
206 #define REACH_TARGET_IF_NAME "if_name" // string
207 #define REACH_TARGET_LOCAL_ADDR "localAddress" // data (struct sockaddr)
208 #define REACH_TARGET_REMOTE_ADDR "remoteAddress" // data (struct sockaddr)
209 #define REACH_TARGET_ONDEMAND_BYPASS "onDemandBypass" // bool
210 #define REACH_TARGET_RESOLVER_BYPASS "resolverBypass" // bool
213 #define REACH_REQUEST_REPLY "reply" // int64
214 #define REACH_REQUEST_REPLY_DETAIL "reply_detail" // string
217 REACH_REQUEST_REPLY_OK
= 0x0000,
218 REACH_REQUEST_REPLY_FAILED
,
219 REACH_REQUEST_REPLY_UNKNOWN
,
223 // ------------------------------------------------------------
227 #pragma mark [XPC] Reachability Server (server->client request)
230 #define MESSAGE_NOTIFY "notify_op" // int64
233 MESSAGE_REACHABILITY_STATUS
= 0x1001,
236 #define REACH_STATUS_CYCLE "cycle" // uint64
237 #define REACH_STATUS_FLAGS "flags" // uint64
238 #define REACH_STATUS_IF_INDEX "if_index" // uint64
239 #define REACH_STATUS_IF_NAME "if_name" // data (char if_name[IFNAMSIZ])
240 #define REACH_STATUS_RESOLVED_ADDRESS "resolvedAddress" // array[data]
241 #define REACH_STATUS_RESOLVED_ADDRESS_ERROR "resolvedAddressError" // int64
242 #define REACH_STATUS_SLEEPING "sleeping" // bool
245 // ------------------------------------------------------------
247 #endif // HAVE_REACHABILITY_SERVER
253 _SCNetworkReachabilityCopyTargetDescription (SCNetworkReachabilityRef target
);
256 _SCNetworkReachabilityCopyTargetFlags (SCNetworkReachabilityRef target
);
258 #ifdef HAVE_REACHABILITY_SERVER
261 __SCNetworkReachability_concurrent_queue (void);
264 __SCNetworkReachabilityPerformNoLock (SCNetworkReachabilityRef target
);
267 #pragma mark [XPC] Reachability Server (client APIs)
270 _SCNetworkReachabilityServer_snapshot (void);
273 __SCNetworkReachabilityServer_targetAdd (SCNetworkReachabilityRef target
);
276 __SCNetworkReachabilityServer_targetRemove (SCNetworkReachabilityRef target
);
279 __SCNetworkReachabilityServer_targetSchedule (SCNetworkReachabilityRef target
);
282 __SCNetworkReachabilityServer_targetStatus (SCNetworkReachabilityRef target
);
285 __SCNetworkReachabilityServer_targetUnschedule (SCNetworkReachabilityRef target
);
288 __SC_checkResolverReachabilityInternal (SCDynamicStoreRef
*storeP
,
289 SCNetworkReachabilityFlags
*flags
,
291 const char *nodename
,
292 const char *servname
,
293 uint32_t *resolver_if_index
,
294 int *dns_config_index
);
296 #endif // HAVE_REACHABILITY_SERVER
300 #endif // _SCNETWORKREACHABILITYINTERNAL_H