2 * Copyright (c) 2003-2006, 2008-2010, 2015 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 _SCNETWORKCONNECTION_H
25 #ifdef USE_SYSTEMCONFIGURATION_PRIVATE_HEADERS
26 #include <SystemConfiguration/_SCNetworkConnection.h>
27 #else /* USE_SYSTEMCONFIGURATION_PRIVATE_HEADERS */
28 #define _SCNETWORKCONNECTION_H
30 #include <Availability.h>
31 #include <TargetConditionals.h>
32 #include <sys/cdefs.h>
33 #include <dispatch/dispatch.h>
34 #include <sys/types.h>
35 #include <sys/socket.h>
36 #include <CoreFoundation/CoreFoundation.h>
37 #include <SystemConfiguration/SystemConfiguration.h>
39 CF_IMPLICIT_BRIDGING_ENABLED
40 CF_ASSUME_NONNULL_BEGIN
43 @header SCNetworkConnection
44 @discussion The SCNetworkConnection API contains functions that allow
45 an application to control connection-oriented services defined
46 in the system and get connection-status information.
48 The functions in the SCNetworkConnection API allow you to
49 control and get information about existing services only.
50 If you need to create, change, or remove services, you
51 should use the SCNetworkConfiguration API instead.
53 Note: Currently, only PPP services can be controlled.
58 @typedef SCNetworkConnectionRef
59 @discussion This is the handle to manage a connection-oriented service.
61 typedef const struct CF_BRIDGED_TYPE(id
) __SCNetworkConnection
* SCNetworkConnectionRef
;
65 @typedef SCNetworkConnectionContext
66 @discussion Structure containing user-specified data and callbacks
67 for a SCNetworkConnection.
68 @field version The version number of the structure type being passed
69 in as a parameter to the SCNetworkConnectionCreateWithServiceID
70 function. This structure is version 0.
71 @field info A C pointer to a user-specified block of data.
72 @field retain The callback used to add a retain for the info field.
73 If this parameter is not a pointer to a function of the correct
74 prototype, the behavior is undefined. The value may be NULL.
75 @field release The calllback used to remove a retain previously added
76 for the info field. If this parameter is not a pointer to a
77 function of the correct prototype, the behavior is undefined.
78 The value may be NULL.
79 @field copyDescription The callback used to provide a description of
84 void * __nullable info
;
85 const void * __nonnull (* __nullable retain
)(const void *info
);
86 void (* __nullable release
)(const void *info
);
87 CFStringRef
__nonnull (* __nullable copyDescription
)(const void *info
);
88 } SCNetworkConnectionContext
;
93 @enum SCNetworkConnectionStatus
94 @discussion Status of the network connection.
95 This status is intended to be generic and high level.
96 An extended status, specific to the type of network
97 connection is also available for applications that
98 need additonal information.
99 @constant kSCNetworkConnectionInvalid
100 The network connection refers to an invalid service.
101 @constant kSCNetworkConnectionDisconnected
102 The network connection is disconnected.
103 @constant kSCNetworkConnectionConnecting
104 The network connection is connecting.
105 @constant kSCNetworkConnectionConnected
106 The network connection is connected.
107 @constant kSCNetworkConnectionDisconnecting
108 The network connection is disconnecting.
110 typedef CF_ENUM(int32_t, SCNetworkConnectionStatus
) {
111 kSCNetworkConnectionInvalid
= -1,
112 kSCNetworkConnectionDisconnected
= 0,
113 kSCNetworkConnectionConnecting
= 1,
114 kSCNetworkConnectionConnected
= 2,
115 kSCNetworkConnectionDisconnecting
= 3
120 @enum SCNetworkConnectionPPPStatus
121 @discussion PPP-specific status of the network connection.
122 This status is returned as part of the extended information
124 Note: additional status might be returned in the future.
125 Your application should be prepared to receive an unknown value.
126 @constant kSCNetworkConnectionPPPDisconnected
128 @constant kSCNetworkConnectionPPPInitializing
130 @constant kSCNetworkConnectionPPPConnectingLink
131 PPP is connecting the lower connection layer (for example,
132 the modem is dialing out).
133 @constant kSCNetworkConnectionPPPDialOnTraffic
134 PPP is waiting for networking traffic to automatically
135 establish the connection.
136 @constant kSCNetworkConnectionPPPNegotiatingLink
137 The PPP lower layer is connected and PPP is negotiating the
138 link layer (LCP protocol).
139 @constant kSCNetworkConnectionPPPAuthenticating
140 PPP is authenticating to the server (PAP, CHAP, MS-CHAP or
142 @constant kSCNetworkConnectionPPPWaitingForCallBack
143 PPP is waiting for the server to call back.
144 @constant kSCNetworkConnectionPPPNegotiatingNetwork
145 PPP is now authenticated and negotiating the networking
146 layer (IPCP or IPv6CP protocols)
147 @constant kSCNetworkConnectionPPPConnected
148 PPP is now fully connected for at least one networking layer.
149 Additional networking protocol might still be negotiating.
150 @constant kSCNetworkConnectionPPPTerminating
151 PPP networking and link protocols are terminating.
152 @constant kSCNetworkConnectionPPPDisconnectingLink
153 PPP is disconnecting the lower level (for example, the modem
155 @constant kSCNetworkConnectionPPPHoldingLinkOff
156 PPP is disconnected and maintaining the link temporarily off.
157 @constant kSCNetworkConnectionPPPSuspended
158 PPP is suspended as a result of the suspend command (for
159 example, when a V.92 Modem is On Hold).
160 @constant kSCNetworkConnectionPPPWaitingForRedial
161 PPP has found a busy server and is waiting for redial.
163 typedef CF_ENUM(int32_t, SCNetworkConnectionPPPStatus
) {
164 kSCNetworkConnectionPPPDisconnected
= 0,
165 kSCNetworkConnectionPPPInitializing
= 1,
166 kSCNetworkConnectionPPPConnectingLink
= 2,
167 kSCNetworkConnectionPPPDialOnTraffic
= 3,
168 kSCNetworkConnectionPPPNegotiatingLink
= 4,
169 kSCNetworkConnectionPPPAuthenticating
= 5,
170 kSCNetworkConnectionPPPWaitingForCallBack
= 6,
171 kSCNetworkConnectionPPPNegotiatingNetwork
= 7,
172 kSCNetworkConnectionPPPConnected
= 8,
173 kSCNetworkConnectionPPPTerminating
= 9,
174 kSCNetworkConnectionPPPDisconnectingLink
= 10,
175 kSCNetworkConnectionPPPHoldingLinkOff
= 11,
176 kSCNetworkConnectionPPPSuspended
= 12,
177 kSCNetworkConnectionPPPWaitingForRedial
= 13
181 @typedef SCNetworkConnectionCallBack
182 @discussion Type of the callback function used when a
183 status event is delivered.
184 @param status The connection status.
185 @param connection The connection reference.
186 @param info Application-specific information.
188 typedef void (*SCNetworkConnectionCallBack
) (
189 SCNetworkConnectionRef connection
,
190 SCNetworkConnectionStatus status
,
191 void * __nullable info
197 Keys for the statistics dictionary
200 #define kSCNetworkConnectionBytesIn CFSTR("BytesIn") /* CFNumber */
201 #define kSCNetworkConnectionBytesOut CFSTR("BytesOut") /* CFNumber */
202 #define kSCNetworkConnectionPacketsIn CFSTR("PacketsIn") /* CFNumber */
203 #define kSCNetworkConnectionPacketsOut CFSTR("PacketsOut") /* CFNumber */
204 #define kSCNetworkConnectionErrorsIn CFSTR("ErrorsIn") /* CFNumber */
205 #define kSCNetworkConnectionErrorsOut CFSTR("ErrorsOut") /* CFNumber */
209 Keys for the SCNetworkConnectionCopyUserPreferences() "selectionOptions"
214 @define kSCNetworkConnectionSelectionOptionOnDemandHostName
215 @discussion A host name that will be used to select the
216 "best" SCNetworkConnection.
218 #define kSCNetworkConnectionSelectionOptionOnDemandHostName CFSTR("OnDemandHostName") // CFString
219 // __OSX_AVAILABLE_STARTING(__MAC_10_6,__IPHONE_3_0/*SPI*/)
222 @define kSCNetworkConnectionSelectionOptionOnDemandRetry
223 @discussion A boolean value used to indicate whether a DNS query has
224 already been issued for the specified OnDemand host name.
226 #define kSCNetworkConnectionSelectionOptionOnDemandRetry CFSTR("OnDemandRetry") // CFBoolean
227 // __OSX_AVAILABLE_STARTING(__MAC_10_6,__IPHONE_3_0/*SPI*/)
232 @function SCNetworkConnectionGetTypeID
233 @discussion Returns the type identifier of all SCNetworkConnection
237 SCNetworkConnectionGetTypeID (void) __OSX_AVAILABLE_STARTING(__MAC_10_3
,__IPHONE_2_0
/*SPI*/);
241 @function SCNetworkConnectionCopyUserPreferences
242 @discussion Provides the default service ID and a dictionary of user
243 options for the connection. Applications can use the
244 returned serviceID and userOptions values to open a
245 connection on the fly.
246 @param selectionOptions Currently unimplemented. Pass NULL for this
248 @param serviceID Reference to the default serviceID for starting
249 connections, this value will be returned by the function.
250 @param userOptions Reference to default userOptions for starting
251 connections, this will be returned by the function.
252 @result Returns TRUE if there is a valid service to dial;
253 FALSE if the function was unable to retrieve a service to dial.
256 SCNetworkConnectionCopyUserPreferences (
257 CFDictionaryRef __nullable selectionOptions
,
258 CFStringRef __nonnull
* __nullable serviceID
,
259 CFDictionaryRef __nonnull
* __nullable userOptions
260 ) __OSX_AVAILABLE_STARTING(__MAC_10_3
,__IPHONE_2_0
/*SPI*/);
264 @function SCNetworkConnectionCreateWithServiceID
265 @discussion Creates a new connection reference to use for getting
266 the status or for connecting or disconnecting the associated
268 @param allocator The CFAllocator that should be used to allocate
269 memory for the connection structure. This parameter may be
270 NULL in which case the current default CFAllocator is used.
271 If this reference is not a valid CFAllocator, the behavior
273 @param serviceID A string that defines the service identifier
274 of the connection. Service identifiers uniquely identify
275 services in the system configuration database.
276 @param callout The function to be called when the status
277 of the connection changes. If this parameter is NULL, the
278 application will not receive notifications of status change
279 and will need to poll for updates.
280 @param context The SCNetworkConnectionContext associated with the
282 @result Returns a reference to the new SCNetworkConnection.
284 SCNetworkConnectionRef __nullable
285 SCNetworkConnectionCreateWithServiceID (
286 CFAllocatorRef __nullable allocator
,
287 CFStringRef serviceID
,
288 SCNetworkConnectionCallBack __nullable callout
,
289 SCNetworkConnectionContext
* __nullable context
290 ) __OSX_AVAILABLE_STARTING(__MAC_10_3
,__IPHONE_2_0
/*SPI*/);
294 @function SCNetworkConnectionCopyServiceID
295 @discussion Returns the service ID associated with the SCNetworkConnection.
296 @param connection The SCNetworkConnection to obtain status from.
297 @result Returns the service ID associated with the SCNetworkConnection.
299 CFStringRef __nullable
300 SCNetworkConnectionCopyServiceID (
301 SCNetworkConnectionRef connection
302 ) __OSX_AVAILABLE_STARTING(__MAC_10_3
,__IPHONE_2_0
/*SPI*/);
306 @function SCNetworkConnectionGetStatus
307 @discussion Returns the status of the SCNetworkConnection.
308 A status is one of the following values:
312 kSCNetworkConnectionInvalid
313 kSCNetworkConnectionDisconnected
314 kSCNetworkConnectionConnecting
315 kSCNetworkConnectionDisconnecting
316 kSCNetworkConnectionConnected
319 @param connection The SCNetworkConnection to obtain status from.
320 @result Returns the status value.
322 SCNetworkConnectionStatus
323 SCNetworkConnectionGetStatus (
324 SCNetworkConnectionRef connection
325 ) __OSX_AVAILABLE_STARTING(__MAC_10_3
,__IPHONE_2_0
/*SPI*/);
329 @function SCNetworkConnectionCopyExtendedStatus
330 @discussion Returns the extended status of the connection.
331 An extended status dictionary contains specific dictionaries
332 describing the status for each subcomponent of the service.
334 For example, a status dictionary will contain the following
335 sub-dictionaries, keys, and values:
339 IPv4 : Addresses : the assigned IP address.
341 PPP : Status : the PPP-specific status of type
342 SCNetworkConnectionPPPStatus.
344 LastCause : Available when the status is "Disconnected"
345 and contains the last error associated with
346 connecting or disconnecting.
348 ConnectTime : the time when the connection was
351 Modem : ConnectSpeed : the speed of the modem connection
354 IPSec : Status : the IPSec-specific status of type
355 SCNetworkConnectionIPSecStatus
357 ConnectTime : the time when the connection was
362 Other dictionaries could be present for PPPoE, PPTP, and L2TP.
364 The status dictionary may be extended in the future to contain
365 additional information.
366 @param connection The SCNetworkConnection to obtain status from.
367 @result Returns the status dictionary.
368 If NULL is returned, the error can be retrieved using the SCError function.
370 CFDictionaryRef __nullable
371 SCNetworkConnectionCopyExtendedStatus (
372 SCNetworkConnectionRef connection
373 ) __OSX_AVAILABLE_STARTING(__MAC_10_3
,__IPHONE_2_0
/*SPI*/);
377 @function SCNetworkConnectionCopyStatistics
378 @discussion Returns the statistics of the SCNetworkConnection.
379 A statistic dictionary contains specific dictionaries
380 with statistics for each subcomponent of the service.
382 For example, a statistics dictionary will contain the following
383 sub-dictionaries, keys, and values:
388 PPP : BytesOut : Contains the number of bytes going up into
389 (or coming out of) the network stack for
390 any networking protocol without the PPP
391 headers and trailers.
394 PPP : PacketsOut : Contains the number of packets going up into
395 (or coming out of) the network stack for
396 any networking protocol without the PPP
397 headers and trailers.
400 PPP : ErrorsOut : Contains the number of errors going up into
401 (or coming out of) the network stack for
402 any networking protocol without the PPP
403 headers and trailers.
406 The statistics dictionary may be extended in the future to
407 contain additional information.
408 @param connection The SCNetworkConnection to obtained statistics from.
409 @result Returns the statistics dictionary.
410 If NULL is returned, the error can be retrieved using the SCError function.
412 CFDictionaryRef __nullable
413 SCNetworkConnectionCopyStatistics (
414 SCNetworkConnectionRef connection
415 ) __OSX_AVAILABLE_STARTING(__MAC_10_3
,__IPHONE_2_0
/*SPI*/);
419 @function SCNetworkConnectionStart
420 @discussion Starts the connection for the SCNetworkConnection.
421 The connection process is asynchronous and the function will
422 return immediately. The connection status can be obtained
423 by polling or by callback. The connection is made with the
424 default settings from the administrator. Some of the settings
425 can be overridden for the duration of the connection. These
426 are specified in an options dictionary. The options dictionary
427 uses the same format as a network service defined in the system
428 configuration preferences schema.
430 Note: Starting and stopping of connections is implicitly
431 arbitrated. Calling SCNetworkConnectionStart on a connection
432 already started will indicate that the application has
433 interest in the connection and it shouldn't be stopped by
435 @param connection The SCNetworkConnection to start.
436 @param userOptions The options dictionary to start the connection with.
437 If userOptions is NULL, the default settings will be used.
438 If userOptions are specified, they must be in the same format
439 as network services stored in the system configuration
440 preferences schema. The options will override the default
441 settings defined for the service.
443 For security reasons, not all options can be overridden; the
444 appropriate merging of all settings will be done before the
445 connection is established, and inappropriate options will be
447 @param linger This parameter indicates whether or not the connection
448 can stay around when the application no longer has interest
449 in it. A typical application should pass FALSE, and the
450 connection will be automatically stopped when the reference
451 is released or if the application quits. If the application
452 passes TRUE, the application can release the reference or
453 exit and the connection will be maintained until a timeout
454 event, until a specific stop request occurs, or until an
455 error is encountered.
456 @result Returns TRUE if the connection was correctly started (the
457 actual connection is not established yet, and the connection
458 status needs to be periodically checked); FALSE if the
459 connection request was not started. The error must be
460 retrieved from the SCError function.
463 SCNetworkConnectionStart (
464 SCNetworkConnectionRef connection
,
465 CFDictionaryRef __nullable userOptions
,
467 ) __OSX_AVAILABLE_STARTING(__MAC_10_3
,__IPHONE_2_0
/*SPI*/);
471 @function SCNetworkConnectionStop
472 @discussion Stops the connection for the SCNetworkConnection.
473 The disconnection process is asynchronous and the function
474 will return immediately. The connection status can be
475 obtained by polling or by callback. This function performs
476 an arbitrated stop of the connection. If several applications
477 have marked their interest in the connection, by calling
478 SCNetworkConnectionStart, the call will succeed but the
479 actual connection will be maintained until the last interested
480 application calls SCNetworkConnectionStop.
482 In certain cases, you might want to stop the connection anyway.
483 In these cases, you set the forceDisconnect argument to TRUE.
484 @param connection The SCNetworkConnection to stop.
485 @result Returns TRUE if the disconnection request succeeded;
486 FALSE if the disconnection request failed.
487 The error must be retrieved from the SCError function.
490 SCNetworkConnectionStop (
491 SCNetworkConnectionRef connection
,
492 Boolean forceDisconnect
493 ) __OSX_AVAILABLE_STARTING(__MAC_10_3
,__IPHONE_2_0
/*SPI*/);
497 @function SCNetworkConnectionCopyUserOptions
498 @discussion Copies the user options used to start the connection.
499 This is a mechanism a client can use to retrieve the user options
500 previously passed to the SCNetworkConnectionStart function.
501 @param connection The SCNetworkConnection to obtain options from.
502 @result Returns the service dictionary containing the connection options.
503 The dictionary can be empty if no user options were used.
504 If NULL is returned, the error can be retrieved using the SCError function.
506 CFDictionaryRef __nullable
507 SCNetworkConnectionCopyUserOptions (
508 SCNetworkConnectionRef connection
509 ) __OSX_AVAILABLE_STARTING(__MAC_10_3
,__IPHONE_2_0
/*SPI*/);
513 @function SCNetworkConnectionScheduleWithRunLoop
514 @discussion Schedules a connection with the run loop.
515 @param connection The SCNetworkConnection to schedule.
516 @param runLoop The run loop to schedule with.
517 @param runLoopMode The run loop mode.
518 @result Returns TRUE if the connection is scheduled successfully;
519 FALSE if the scheduling failed.
520 The error can be retrieved using the SCError function.
523 SCNetworkConnectionScheduleWithRunLoop (
524 SCNetworkConnectionRef connection
,
525 CFRunLoopRef runLoop
,
526 CFStringRef runLoopMode
527 ) __OSX_AVAILABLE_STARTING(__MAC_10_3
,__IPHONE_2_0
/*SPI*/);
531 @function SCNetworkConnectionUnscheduleFromRunLoop
532 @discussion Unschedules a connection from the run loop.
533 @param connection The SCNetworkConnection to unschedule.
534 @param runLoop The run loop to unschedule from.
535 @param runLoopMode The run loop mode.
536 @result Returns TRUE if the connection is unscheduled successfully;
537 FALSE if the unscheduling failed.
538 The error can be retrieved using the SCError function.
541 SCNetworkConnectionUnscheduleFromRunLoop (
542 SCNetworkConnectionRef connection
,
543 CFRunLoopRef runLoop
,
544 CFStringRef runLoopMode
545 ) __OSX_AVAILABLE_STARTING(__MAC_10_3
,__IPHONE_2_0
/*SPI*/);
549 @function SCNetworkConnectionSetDispatchQueue
550 @discussion Caller provides a dispatch queue on which the callback contained in connection will run.
551 @param connection The SCNetworkConnection to notify.
552 @param queue The libdispatch queue to run the callback on.
553 Pass NULL to disable notifications, and release queue.
554 @result Returns TRUE if the notifications have been enabled/disabled as desired;
556 The error can be retrieved using the SCError function.
559 SCNetworkConnectionSetDispatchQueue (
560 SCNetworkConnectionRef connection
,
561 dispatch_queue_t __nullable queue
562 ) __OSX_AVAILABLE_STARTING(__MAC_10_6
,__IPHONE_4_0
/*SPI*/);
566 CF_ASSUME_NONNULL_END
567 CF_IMPLICIT_BRIDGING_DISABLED
569 #endif /* USE_SYSTEMCONFIGURATION_PRIVATE_HEADERS */
570 #endif /* _SCNETWORKCONNECTION_H */