]> git.saurik.com Git - apple/configd.git/blob - SystemConfiguration.fproj/SCNetworkReachability.h
7024fc173f7ec2786321d34a8e2036b177a638e5
[apple/configd.git] / SystemConfiguration.fproj / SCNetworkReachability.h
1 /*
2 * Copyright (c) 2003-2005, 2008-2010, 2015 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 _SCNETWORKREACHABILITY_H
25 #define _SCNETWORKREACHABILITY_H
26
27 #include <Availability.h>
28 #include <TargetConditionals.h>
29 #include <sys/cdefs.h>
30 #include <sys/types.h>
31 #include <sys/socket.h>
32 #include <CoreFoundation/CoreFoundation.h>
33 #include <SystemConfiguration/SCNetwork.h>
34 #include <dispatch/dispatch.h>
35
36 CF_IMPLICIT_BRIDGING_ENABLED
37 CF_ASSUME_NONNULL_BEGIN
38
39 /*!
40 @header SCNetworkReachability
41 @discussion The SCNetworkReachability API allows an application to
42 determine the status of a system's current network
43 configuration and the reachability of a target host.
44 In addition, reachability can be monitored with notifications
45 that are sent when the status has changed.
46
47 "Reachability" reflects whether a data packet, sent by
48 an application into the network stack, can leave the local
49 computer.
50 Note that reachability does <i>not</i> guarantee that the data
51 packet will actually be received by the host.
52 */
53
54 /*!
55 @typedef SCNetworkReachabilityRef
56 @discussion This is the handle to a network address or name.
57 */
58 typedef const struct CF_BRIDGED_TYPE(id) __SCNetworkReachability * SCNetworkReachabilityRef;
59
60
61 /*!
62 @typedef SCNetworkReachabilityContext
63 Structure containing user-specified data and callbacks for SCNetworkReachability.
64 @field version The version number of the structure type being passed
65 in as a parameter to the SCDynamicStore creation function.
66 This structure is version 0.
67 @field info A C pointer to a user-specified block of data.
68 @field retain The callback used to add a retain for the info field.
69 If this parameter is not a pointer to a function of the correct
70 prototype, the behavior is undefined. The value may be NULL.
71 @field release The calllback used to remove a retain previously added
72 for the info field. If this parameter is not a pointer to a
73 function of the correct prototype, the behavior is undefined.
74 The value may be NULL.
75 @field copyDescription The callback used to provide a description of
76 the info field.
77 */
78 typedef struct {
79 CFIndex version;
80 void * __nullable info;
81 const void * __nonnull (* __nullable retain)(const void *info);
82 void (* __nullable release)(const void *info);
83 CFStringRef __nonnull (* __nullable copyDescription)(const void *info);
84 } SCNetworkReachabilityContext;
85
86 /*!
87 @enum SCNetworkReachabilityFlags
88 @discussion Flags that indicate whether the specified network
89 nodename or address is reachable, whether a connection is
90 required, and whether some user intervention may be required
91 when establishing a connection.
92 @constant kSCNetworkReachabilityFlagsTransientConnection
93 This flag indicates that the specified nodename or address can
94 be reached via a transient connection, such as PPP.
95 @constant kSCNetworkReachabilityFlagsReachable
96 This flag indicates that the specified nodename or address can
97 be reached using the current network configuration.
98 @constant kSCNetworkReachabilityFlagsConnectionRequired
99 This flag indicates that the specified nodename or address can
100 be reached using the current network configuration, but a
101 connection must first be established.
102
103 As an example, this status would be returned for a dialup
104 connection that was not currently active, but could handle
105 network traffic for the target system.
106 @constant kSCNetworkReachabilityFlagsConnectionOnTraffic
107 This flag indicates that the specified nodename or address can
108 be reached using the current network configuration, but a
109 connection must first be established. Any traffic directed
110 to the specified name or address will initiate the connection.
111
112 Note: this flag was previously named kSCNetworkReachabilityFlagsConnectionAutomatic
113 @constant kSCNetworkReachabilityFlagsInterventionRequired
114 This flag indicates that the specified nodename or address can
115 be reached using the current network configuration, but a
116 connection must first be established. In addition, some
117 form of user intervention will be required to establish this
118 connection, such as providing a password, an authentication
119 token, etc.
120
121 Note: At the present time, this flag will only be returned
122 in the case where you have a dial-on-traffic configuration
123 (ConnectionOnTraffic), where an attempt to connect has
124 already been made, and where some error (e.g. no dial tone,
125 no answer, bad password, ...) was encountered during the
126 automatic connection attempt. In this case the PPP controller
127 will stop attempting to establish a connection until the user
128 has intervened.
129 @constant kSCNetworkReachabilityFlagsConnectionOnDemand
130 This flag indicates that the specified nodename or address can
131 be reached using the current network configuration, but a
132 connection must first be established.
133 The connection will be established "On Demand" by the
134 CFSocketStream APIs.
135 Other APIs will not establish the connection.
136 @constant kSCNetworkReachabilityFlagsIsLocalAddress
137 This flag indicates that the specified nodename or address
138 is one associated with a network interface on the current
139 system.
140 @constant kSCNetworkReachabilityFlagsIsDirect
141 This flag indicates that network traffic to the specified
142 nodename or address will not go through a gateway, but is
143 routed directly to one of the interfaces in the system.
144 #if TARGET_OS_IPHONE
145 @constant kSCNetworkReachabilityFlagsIsWWAN
146 This flag indicates that the specified nodename or address can
147 be reached via an EDGE, GPRS, or other "cell" connection.
148 #endif // TARGET_OS_IPHONE
149 */
150 typedef CF_OPTIONS(uint32_t, SCNetworkReachabilityFlags) {
151 kSCNetworkReachabilityFlagsTransientConnection = 1<<0,
152 kSCNetworkReachabilityFlagsReachable = 1<<1,
153 kSCNetworkReachabilityFlagsConnectionRequired = 1<<2,
154 kSCNetworkReachabilityFlagsConnectionOnTraffic = 1<<3,
155 kSCNetworkReachabilityFlagsInterventionRequired = 1<<4,
156 kSCNetworkReachabilityFlagsConnectionOnDemand = 1<<5, // __OSX_AVAILABLE_STARTING(__MAC_10_6,__IPHONE_3_0)
157 kSCNetworkReachabilityFlagsIsLocalAddress = 1<<16,
158 kSCNetworkReachabilityFlagsIsDirect = 1<<17,
159 #if TARGET_OS_IPHONE
160 kSCNetworkReachabilityFlagsIsWWAN = 1<<18,
161 #endif // TARGET_OS_IPHONE
162
163 kSCNetworkReachabilityFlagsConnectionAutomatic = kSCNetworkReachabilityFlagsConnectionOnTraffic
164 };
165
166 /*!
167 @typedef SCNetworkReachabilityCallBack
168 @discussion Type of the callback function used when the
169 reachability of a network address or name changes.
170 @param target The SCNetworkReachability reference being monitored
171 for changes.
172 @param flags The new SCNetworkReachabilityFlags representing the
173 reachability status of the network address/name.
174 @param info A C pointer to a user-specified block of data.
175 */
176 typedef void (*SCNetworkReachabilityCallBack) (
177 SCNetworkReachabilityRef target,
178 SCNetworkReachabilityFlags flags,
179 void * __nullable info
180 );
181
182 __BEGIN_DECLS
183
184 /*!
185 @function SCNetworkReachabilityCreateWithAddress
186 @discussion Creates a reference to the specified network
187 address. This reference can be used later to monitor the
188 reachability of the target host.
189 @param address The address of the desired host.
190 @result Returns a reference to the new immutable SCNetworkReachabilityRef.
191
192 You must release the returned value.
193 */
194 SCNetworkReachabilityRef __nullable
195 SCNetworkReachabilityCreateWithAddress (
196 CFAllocatorRef __nullable allocator,
197 const struct sockaddr *address
198 ) __OSX_AVAILABLE_STARTING(__MAC_10_3,__IPHONE_2_0);
199
200 /*!
201 @function SCNetworkReachabilityCreateWithAddressPair
202 @discussion Creates a reference to the specified network
203 address. This reference can be used later to monitor the
204 reachability of the target host.
205 @param localAddress The local address associated with a network
206 connection. If NULL, only the remote address is of interest.
207 @param remoteAddress The remote address associated with a network
208 connection. If NULL, only the local address is of interest.
209 @result Returns a reference to the new immutable SCNetworkReachabilityRef.
210
211 You must release the returned value.
212 */
213 SCNetworkReachabilityRef __nullable
214 SCNetworkReachabilityCreateWithAddressPair (
215 CFAllocatorRef __nullable allocator,
216 const struct sockaddr * __nullable localAddress,
217 const struct sockaddr * __nullable remoteAddress
218 ) __OSX_AVAILABLE_STARTING(__MAC_10_3,__IPHONE_2_0);
219
220 /*!
221 @function SCNetworkReachabilityCreateWithName
222 @discussion Creates a reference to the specified network host or node
223 name. This reference can be used later to monitor the
224 reachability of the target host.
225 @param nodename The node name of the desired host.
226 This name would be the same as that passed to the
227 gethostbyname(3) or getaddrinfo(3) functions.
228 @result Returns a reference to the new immutable SCNetworkReachabilityRef.
229
230 You must release the returned value.
231 */
232 SCNetworkReachabilityRef __nullable
233 SCNetworkReachabilityCreateWithName (
234 CFAllocatorRef __nullable allocator,
235 const char *nodename
236 ) __OSX_AVAILABLE_STARTING(__MAC_10_3,__IPHONE_2_0);
237
238 /*!
239 @function SCNetworkReachabilityGetTypeID
240 @discussion Returns the type identifier of all SCNetworkReachability
241 instances.
242 */
243 CFTypeID
244 SCNetworkReachabilityGetTypeID (void) __OSX_AVAILABLE_STARTING(__MAC_10_3,__IPHONE_2_0);
245
246
247 /*!
248 @function SCNetworkReachabilityGetFlags
249 @discussion Determines if the given target is reachable using the
250 current network configuration.
251 @param target The network reference associated with the address or name
252 to be checked for reachability.
253 @param flags A pointer to memory that will be filled with the
254 SCNetworkReachabilityFlags detailing the reachability
255 of the specified target.
256 @result Returns TRUE if the network connection flags are valid;
257 FALSE if the status could not be determined.
258 */
259 Boolean
260 SCNetworkReachabilityGetFlags (
261 SCNetworkReachabilityRef target,
262 SCNetworkReachabilityFlags *flags
263 ) __OSX_AVAILABLE_STARTING(__MAC_10_3,__IPHONE_2_0);
264
265 /*!
266 @function SCNetworkReachabilitySetCallback
267 @discussion Assigns a client to a target, which receives callbacks
268 when the reachability of the target changes.
269 @param target The network reference associated with the address or
270 name to be checked for reachability.
271 @param callout The function to be called when the reachability of the
272 target changes. If NULL, the current client for the target
273 is removed.
274 @param context The SCNetworkReachabilityContext associated with
275 the callout. The value may be NULL.
276 @result Returns TRUE if the notification client was successfully set.
277 */
278 Boolean
279 SCNetworkReachabilitySetCallback (
280 SCNetworkReachabilityRef target,
281 SCNetworkReachabilityCallBack __nullable callout,
282 SCNetworkReachabilityContext * __nullable context
283 ) __OSX_AVAILABLE_STARTING(__MAC_10_3,__IPHONE_2_0);
284
285 /*!
286 @function SCNetworkReachabilityScheduleWithRunLoop
287 @discussion Schedules the given target with the given run loop and mode.
288 @param target The address or name that is set up for asynchronous
289 notifications. Must be non-NULL.
290 @param runLoop A reference to a run loop on which the target should
291 be scheduled. Must be non-NULL.
292 @param runLoopMode The mode on which to schedule the target.
293 Must be non-NULL.
294 @result Returns TRUE if the target is scheduled successfully;
295 FALSE otherwise.
296 */
297 Boolean
298 SCNetworkReachabilityScheduleWithRunLoop (
299 SCNetworkReachabilityRef target,
300 CFRunLoopRef runLoop,
301 CFStringRef runLoopMode
302 ) __OSX_AVAILABLE_STARTING(__MAC_10_3,__IPHONE_2_0);
303
304 /*!
305 @function SCNetworkReachabilityUnscheduleFromRunLoop
306 @discussion Unschedules the given target from the given run loop
307 and mode.
308 @param target The address or name that is set up for asynchronous
309 notifications. Must be non-NULL.
310 @param runLoop A reference to a run loop from which the target
311 should be unscheduled. Must be non-NULL.
312 @param runLoopMode The mode on which to unschedule the target.
313 Must be non-NULL.
314 @result Returns TRUE if the target is unscheduled successfully;
315 FALSE otherwise.
316 */
317 Boolean
318 SCNetworkReachabilityUnscheduleFromRunLoop (
319 SCNetworkReachabilityRef target,
320 CFRunLoopRef runLoop,
321 CFStringRef runLoopMode
322 ) __OSX_AVAILABLE_STARTING(__MAC_10_3,__IPHONE_2_0);
323
324 /*!
325 @function SCNetworkReachabilitySetDispatchQueue
326 @discussion Schedules callbacks for the given target on the given
327 dispatch queue.
328 @param target The address or name that is set up for asynchronous
329 notifications. Must be non-NULL.
330 @param queue A libdispatch queue to run the callback on. Pass NULL to disable notifications, and release queue.
331 @result Returns TRUE if the target is unscheduled successfully;
332 FALSE otherwise.
333 */
334 Boolean
335 SCNetworkReachabilitySetDispatchQueue (
336 SCNetworkReachabilityRef target,
337 dispatch_queue_t __nullable queue
338 ) __OSX_AVAILABLE_STARTING(__MAC_10_6,__IPHONE_4_0);
339
340 __END_DECLS
341
342 CF_ASSUME_NONNULL_END
343 CF_IMPLICIT_BRIDGING_DISABLED
344
345 #endif /* _SCNETWORKREACHABILITY_H */