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