2 * Copyright (c) 2000-2016 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@
27 #include <sys/cdefs.h>
28 #include <sys/socket.h>
31 #include <sys/syslog.h>
32 #include <mach/message.h>
33 #include <os/activity.h>
35 #include <sys/sysctl.h>
37 #include <CoreFoundation/CoreFoundation.h>
39 /* SCDynamicStore SPIs */
40 #include <SystemConfiguration/SCDynamicStorePrivate.h>
41 #include <SystemConfiguration/SCDynamicStoreCopySpecificPrivate.h>
42 #include <SystemConfiguration/SCDynamicStoreSetSpecificPrivate.h>
44 /* SCPreferences SPIs */
45 #include <SystemConfiguration/SCPreferencesPrivate.h>
46 #include <SystemConfiguration/SCPreferencesGetSpecificPrivate.h>
47 #include <SystemConfiguration/SCPreferencesSetSpecificPrivate.h>
49 /* [private] Schema Definitions (for SCDynamicStore and SCPreferences) */
50 #include <SystemConfiguration/SCSchemaDefinitionsPrivate.h>
52 /* SCNetworkConfiguration SPIs */
53 #include <SystemConfiguration/SCNetworkConfigurationPrivate.h>
55 /* SCNetworkConnection SPIs */
56 #include <SystemConfiguration/SCNetworkConnectionPrivate.h>
59 #include <SystemConfiguration/SCPreferencesKeychainPrivate.h>
66 /* "server" defines */
67 #if !TARGET_OS_SIMULATOR
68 #define _SC_SERVER_PROG "configd"
69 #else // !TARGET_OS_SIMULATOR
70 #define _SC_SERVER_PROG "configd_sim"
71 #endif // !TARGET_OS_SIMULATOR
74 /* atomic operations */
75 #define _SC_ATOMIC_CMPXCHG(p, o, n) __sync_bool_compare_and_swap((p), (o), (n))
76 #define _SC_ATOMIC_INC(p) __sync_fetch_and_add((p), 1) // return (n++);
77 #define _SC_ATOMIC_DEC(p) __sync_sub_and_fetch((p), 1) // return (--n);
78 #define _SC_ATOMIC_ZERO(p) __sync_fetch_and_and((p), 0) // old_n = n; n = 0; return(old_n);
83 #define SYSTEMCONFIGURATION_FRAMEWORK_PATH "/System/Library/Frameworks/SystemConfiguration.framework"
85 #define SYSTEMCONFIGURATION_FRAMEWORK_PATH "/System/Library/PrivateFrameworks/SystemConfiguration.framework"
89 /* get-network-info script path */
90 #if !TARGET_OS_EMBEDDED
91 #define SYSTEMCONFIGURATION_GET_NETWORK_INFO_PATH SYSTEMCONFIGURATION_FRAMEWORK_PATH "/Resources/get-network-info"
93 #define SYSTEMCONFIGURATION_GET_NETWORK_INFO_PATH SYSTEMCONFIGURATION_FRAMEWORK_PATH "/get-network-info"
97 /* framework variables */
98 extern int _sc_debug
; /* non-zero if debugging enabled */
99 extern int _sc_verbose
; /* non-zero if verbose logging enabled */
100 extern int _sc_log
; /* 0 if SC messages should be written to stdout/stderr,
101 1 if SC messages should be logged w/asl(3),
102 2 if SC messages should be written to stdout/stderr AND logged */
107 #define _SC_NOTIFY_PREFIX "com.apple.system.config"
108 #define _SC_NOTIFY_NETWORK_CHANGE _SC_NOTIFY_PREFIX ".network_change"
109 #define _SC_NOTIFY_NETWORK_CHANGE_DNS _SC_NOTIFY_NETWORK_CHANGE ".dns"
110 #define _SC_NOTIFY_NETWORK_CHANGE_NWI _SC_NOTIFY_NETWORK_CHANGE ".nwi"
111 #define _SC_NOTIFY_NETWORK_CHANGE_PROXY _SC_NOTIFY_PREFIX ".proxy_change"
115 @group SCNetworkReachabilityCreateWithOptions #defines
116 @discussion The following defines the keys and values that can
117 be passed to the SCNetworkReachabilityCreateWithOptions
122 @constant kSCNetworkReachabilityOptionNodeName
123 @discussion A CFString that will be passed to getaddrinfo(3). An acceptable
124 value is either a valid host name or a numeric host address string
125 consisting of a dotted decimal IPv4 address or an IPv6 address.
127 #define kSCNetworkReachabilityOptionNodeName CFSTR("nodename")
130 @constant kSCNetworkReachabilityOptionLocalAddress
131 @discussion A CFData wrapping a "struct sockaddr" that represents
132 local address associated with a network connection.
134 #define kSCNetworkReachabilityOptionLocalAddress CFSTR("local-address")
137 @constant kSCNetworkReachabilityOptionPTRAddress
138 @discussion A CFData wrapping a "struct sockaddr" that represents
139 the reverse-address to be queried.
141 #define kSCNetworkReachabilityOptionPTRAddress CFSTR("ptr-address")
144 @constant kSCNetworkReachabilityOptionRemoteAddress
145 @discussion A CFData wrapping a "struct sockaddr" that represents
146 remote address associated with a network connection.
148 #define kSCNetworkReachabilityOptionRemoteAddress CFSTR("remote-address")
151 @constant kSCNetworkReachabilityOptionInterface
152 @discussion A CFString specifying that the reachability query should be
153 limited to the provided network interface (e.g. "en0", "en1", ...).
155 #define kSCNetworkReachabilityOptionInterface CFSTR("interface")
159 @constant kSCNetworkReachabilityOptionConnectionOnDemandBypass
160 @discussion A CFBoolean that indicates if we should bypass the VPNOnDemand
161 checks for this target.
163 #define kSCNetworkReachabilityOptionConnectionOnDemandBypass CFSTR("ConnectionOnDemandBypass")
166 @constant kSCNetworkReachabilityOptionResolverBypass
167 @discussion A CFBoolean that indicates if we should bypass resolving any
168 node names. Instead, the status of the DNS server configuration
169 associated with the name will be returned. */
170 #define kSCNetworkReachabilityOptionResolverBypass CFSTR("ResolverBypass")
174 @constant kSCNetworkReachabilityOptionServerBypass
175 @discussion A CFBoolean that indicates if we should bypass usage of the
176 SCNetworkReachability "server" for this target.
178 #define kSCNetworkReachabilityOptionServerBypass CFSTR("ServerBypass")
190 #pragma mark SCError()
194 @function _SCErrorSet
195 @discussion Sets the last SystemConfiguration.framework API error code.
196 @param error The error encountered.
198 void _SCErrorSet (int error
);
202 #pragma mark Serialization/Unserialization
206 @function _SCSerialize
207 @discussion Serialize a CFPropertyList object for passing
209 @param obj CFPropertyList object to serialize
210 @param xml A pointer to a CFDataRef, NULL if data should be
212 @param dataRef A pointer to the newly allocated/serialized data
213 @param dataLen A pointer to the length in bytes of the newly
214 allocated/serialized data
216 Boolean
_SCSerialize (CFPropertyListRef obj
,
222 @function _SCUnserialize
223 @discussion Unserialize a stream of bytes passed from/to configd
224 into a CFPropertyList object.
225 @param obj A pointer to memory that will be filled with the CFPropertyList
226 associated with the stream of bytes.
227 @param xml CFDataRef with the serialized data
228 @param dataRef A pointer to the serialized data
229 @param dataLen A pointer to the length of the serialized data
231 Specify either "xml" or "data/dataLen".
233 Boolean
_SCUnserialize (CFPropertyListRef
*obj
,
239 @function _SCSerializeString
240 @discussion Serialize a CFString object for passing
242 @param str CFString key to serialize
243 @param data A pointer to a CFDataRef, NULL if storage should be
245 @param dataRef A pointer to the newly allocated/serialized data
246 @param dataLen A pointer to the length in bytes of the newly
247 allocated/serialized data
249 Boolean
_SCSerializeString (CFStringRef str
,
255 @function _SCUnserializeString
256 @discussion Unserialize a stream of bytes passed from/to configd
257 into a CFString object.
258 @param str A pointer to memory that will be filled with the CFString
259 associated with the stream of bytes.
260 @param utf8 CFDataRef with the serialized data
261 @param dataRef A pointer to the serialized data
262 @param dataLen A pointer to the length of the serialized data
264 Specify either "utf8" or "data/dataLen".
266 Boolean
_SCUnserializeString (CFStringRef
*str
,
272 @function _SCSerializeData
273 @discussion Serialize a CFData object for passing
275 @param data CFData key to serialize
276 @param dataRef A pointer to the newly allocated/serialized data
277 @param dataLen A pointer to the length in bytes of the newly
278 allocated/serialized data
280 Boolean
_SCSerializeData (CFDataRef data
,
285 @function _SCUnserializeData
286 @discussion Unserialize a stream of bytes passed from/to configd
287 into a CFData object.
288 @param data A pointer to memory that will be filled with the CFData
289 associated with the stream of bytes.
290 @param dataRef A pointer to the serialized data
291 @param dataLen A pointer to the length of the serialized data
293 Boolean
_SCUnserializeData (CFDataRef
*data
,
298 @function _SCSerializeMultiple
299 @discussion Convert a CFDictionary containing a set of CFPropertlyList
300 values into a CFDictionary containing a set of serialized CFData
302 @param dict The CFDictionary with CFPropertyList values.
303 @result The serialized CFDictionary with CFData values
306 CFDictionaryRef
_SCSerializeMultiple (CFDictionaryRef dict
);
309 @function _SCUnserializeMultiple
310 @discussion Convert a CFDictionary containing a set of CFData
311 values into a CFDictionary containing a set of serialized
312 CFPropertlyList values.
313 @param dict The CFDictionary with CFData values.
314 @result The serialized CFDictionary with CFPropertyList values
317 CFDictionaryRef
_SCUnserializeMultiple (CFDictionaryRef dict
);
324 @function _SCCreatePropertyListFromResource
325 @discussion Reads a property list referenced by a file URL.
326 @param url The file URL.
327 @result The CFPropertyList content of the URL.
330 _SCCreatePropertyListFromResource (CFURLRef url
);
334 #pragma mark String conversion
338 @function _SC_cfstring_to_cstring
339 @discussion Extracts a C-string from a CFString.
340 @param cfstr The CFString to extract the data from.
341 @param buf A user provided buffer of the specified length. If NULL,
342 a new buffer will be allocated to contain the C-string. It
343 is the responsiblity of the caller to free an allocated
345 @param bufLen The size of the user provided buffer.
346 @param encoding The string encoding
347 @result If the extraction (conversion) is successful then a pointer
348 to the user provided (or allocated) buffer is returned, NULL
349 if the string could not be extracted.
351 char * _SC_cfstring_to_cstring (CFStringRef cfstr
,
354 CFStringEncoding encoding
);
357 * @function _SC_sockaddr_to_string
358 * @discussion Formats a "struct sockaddr" for reporting
359 * @param address The address to format
360 * @param buf A user provided buffer of the specified length.
361 * @param bufLen The size of the user provided buffer.
363 void _SC_sockaddr_to_string (const struct sockaddr
*address
,
369 * @function _SC_string_to_sockaddr
370 * @discussion Parses a string into a "struct sockaddr"
371 * @param str The address string to parse
372 * @param af Allowed address families (AF_UNSPEC, AF_INET, AF_INET6)
373 * @param buf A user provided buffer of the specified length; NULL
374 * if a new buffer should be allocated (and deallocated by the
376 * @param bufLen The size of the user provided buffer.
377 * @result A pointer to the parsed "struct sockaddr"; NULL if
378 * the string could not be parsed as an IP[v6] address.
381 _SC_string_to_sockaddr (const char *str
,
387 * @function _SC_trimDomain
388 * @discussion Trims leading and trailing "."s from a domain or host name
389 * @param domain The domain name to trim
390 * @result The trimmed domain name.
393 CFStringRef
_SC_trimDomain (CFStringRef domain
);
397 #pragma mark Mach IPC
401 @function _SC_sendMachMessage
402 @discussion Sends a trivial mach message (one with just a
403 message ID) to the specified port.
404 @param port The mach port.
405 @param msg_id The message id.
407 void _SC_sendMachMessage (mach_port_t port
,
408 mach_msg_id_t msg_id
);
416 @function _SC_LOG_DEFAULT
417 @discussion Maps a syslog/asl logging level to an os_log level.
418 @param level The syslog/asl logging level
419 @result The os_log level
421 os_log_t
_SC_LOG_DEFAULT ();
425 @function _SC_syslog_os_log_mapping
426 @discussion Maps a syslog/asl logging level to an os_log level.
427 @param level The syslog/asl logging level
428 @result The os_log level
430 os_log_type_t
_SC_syslog_os_log_mapping (int level
);
434 @function _SCCopyDescription
435 @discussion Returns a formatted textual description of a CF object.
436 @param cf The CFType object (a generic reference of type CFTypeRef) from
437 which to derive a description.
438 @param formatOptions A dictionary containing formatting options for the object.
439 @result A string that contains a formatted description of cf.
441 CFStringRef
_SCCopyDescription (CFTypeRef cf
,
442 CFDictionaryRef formatOptions
);
447 @discussion Conditionally issue a log message.
448 @param condition A boolean value indicating if the message should be logged
449 @param level A syslog(3) logging priority.
450 @param formatString The format string
451 @result The specified message will be written to the system message
452 logger (See syslogd(8)).
454 void SCLog (Boolean condition
,
456 CFStringRef formatString
,
457 ...) CF_FORMAT_FUNCTION(3, 4);
460 typedef CF_ENUM(uint32_t, SCLoggerFlags
) {
461 kSCLoggerFlagsNone
= 0x0,
462 kSCLoggerFlagsDefault
= 0x1,
463 kSCLoggerFlagsFile
= 0x2
466 typedef struct SCLogger
* SCLoggerRef
;
470 @function SCLoggerLog
471 @discussion Logs messages using SCLoggerRef
472 @param logger A SCLoggerRef which keeps information about how logging
473 needs to be done. Passing NULL uses the default logger instance.
474 @param level An asl(3) logging priority. Passing the complement of a logging
475 priority (e.g. ~ASL_LEVEL_NOTICE) will result in log message lines
476 NOT being split by a "\n".
477 @param formatString The format string followed by format arguments
478 @result The specified message will be written to the system message
479 logger (See syslogd(8)). If logger is in verbose mode, the message
480 will be also written to a file specified in the ASL Module
482 void SCLoggerLog (SCLoggerRef logger
,
484 CFStringRef formatString
,
485 ...) CF_FORMAT_FUNCTION(3, 4)
486 __OSX_AVAILABLE_STARTING(__MAC_10_8
,__IPHONE_6_0
);
489 @function SCLoggerVLog
490 @discussion Logs messages using SCLoggerRef
491 @param logger A SCLoggerRef which keeps information about how logging
492 needs to be done. Passing NULL uses the default logger instance.
493 @param level An asl(3) logging priority. Passing the complement of a logging
494 priority (e.g. ~ASL_LEVEL_NOTICE) will result in log message lines
495 NOT being split by a "\n".
496 @param formatString The format string
497 @param args The va_list representing the arguments
498 @result The specified message will be written to the system message
499 logger (See syslogd(8)). If logger is in verbose mode, the message
500 will be also written to a file specified in the ASL Module
502 void SCLoggerVLog (SCLoggerRef logger
,
504 CFStringRef formatString
,
505 va_list args
) __OSX_AVAILABLE_STARTING(__MAC_10_9
,__IPHONE_7_0
);
510 @discussion Issue a log message.
511 @param asl An asl client handle to be used for logging. If NULL, a shared
513 @param msg An asl msg structure to be used for logging. If NULL, a default
514 asl msg will be used.
515 @param level A asl(3) logging priority. Passing the complement of a logging
516 priority (e.g. ~ASL_LEVEL_NOTICE) will result in log message lines
517 NOT being split by a "\n".
518 @param formatString The format string
519 @result The specified message will be written to the system message
520 logger (See syslogd(8)).
522 void SCLOG (asl_object_t asl
,
525 CFStringRef formatString
,
526 ...) CF_FORMAT_FUNCTION(4, 5);
531 @discussion Issue an os_log() message.
533 Note: By default, the log messages will be associated with the
534 "com.apple.SystemConfiguration" subsystem. This behavior
535 can be overwritten by #define'ing SC_LOG_HANDLE with the name
536 of an os_log_t global (or a function that returns an os_log_t)
537 *BEFORE* this header is #include'd. In that case, the noted
538 log handle will be used.
540 Also, by #define'ing SC_LOG_OR_PRINT, we will check the "_sc_log"
541 global to see if the messages should [also] be directed to stdout/stderr.
543 @param level The syslog(3 logging priority.
544 @param __string The format string
545 @result The specified message will be written to the unified logging system.
549 #ifndef SC_LOG_HANDLE
550 #define SC_LOG_HANDLE _SC_LOG_DEFAULT() // use [SC] default os_log handle
552 #ifndef SC_LOG_OR_PRINT
553 #define USE_SC_LOG_OR_PRINT // use '_sc_log' to control os_log, printf
554 #endif // !SC_LOG_OR_PRINT
556 #endif // !SC_LOG_HANDLE
558 #ifdef USE_SC_LOG_OR_PRINT
560 #define SC_log(__level, __format, ...) \
562 os_log_t __handle = SC_LOG_HANDLE; \
563 os_log_type_t __type = _SC_syslog_os_log_mapping(__level); \
565 if ((_sc_log != 1) || os_log_type_enabled(__handle, __type)) { \
575 #else // USE_SC_LOG_OR_PRINT
577 #define SC_log(__level, __format, ...) \
579 os_log_type_t __type = _SC_syslog_os_log_mapping(__level); \
580 os_log_with_type(SC_LOG_HANDLE, __type, __format, ## __VA_ARGS__); \
583 #endif // USE_SC_LOG_OR_PRINT
590 @discussion Issue a log message w/os_log(3) or printf(3).
591 @param level A syslog(3) logging priority. If less than 0, log message is multi-line
592 @param format_CF The format string (as a CFString for stdout/stderr)
593 @param log The os_log_t handle (for logging)
594 @param type The os_log_type_t type (for logging)
595 @param format The format string (for logging)
596 @result The specified message will be written to the system message
600 void __SC_Log (int level
,
601 CFStringRef format_CF
,
605 ...) CF_FORMAT_FUNCTION(2, 6) __attribute__((format(os_log
, 5, 6)));
610 @discussion Conditionally issue a debug message.
611 @param condition A boolean value indicating if the message should be written
612 @param stream The output stream for the log message.
613 @param formatString The format string
614 @result The message will be written to the specified stream
617 void SCPrint (Boolean condition
,
619 CFStringRef formatString
,
620 ...) CF_FORMAT_FUNCTION(3, 4);
625 @function SCLoggerCreate
626 @discussion Create a reference to logger which stores information like verbose mode or not, loggerID, etc.
627 loggerID and moduleName both need to be non NULL, or else the function returns NULL.
628 If the moduleName points to a module which doesn't exist, then SCLoggerCreate will fail and
630 @param loggerID CFStringRef which will be appended to the log message when in verbose mode. It will also be
631 used to identify the module where the rules are being defined.
634 SCLoggerCreate (CFStringRef loggerID
);
637 @function SCLoggerGetFlags
638 @discussion Returns the log flags for the logging reference
639 @param logger Reference which points to the logger information
642 SCLoggerGetFlags (SCLoggerRef logger
);
645 @function SCLoggerSetFlags
646 @discussion Sets the log flags for the logger reference
647 @param logger A reference to the logger
648 @param flags SCLoggerFlags value determining where the logs from the logger will be directed
650 void SCLoggerSetFlags (SCLoggerRef logger
,
651 SCLoggerFlags flags
);
658 @function SCNetworkProxiesCopyMatching
660 @param globalConfiguration the proxy dictionary currently returned
661 by SCDynamicStoreCopyProxies().
662 @param server A CFString specying the hostname of interest; NULL if
663 no specific hostname should be used in selecting the proxy
665 @param interface A CFString specifying that the proxy configuration
666 for the provided network interface (e.g. "en0", "en1", ...)
667 should be returned; NULL if proxy usage will not be scoped
669 @result A CFArray containing the proxy configurations associated
670 with the requested server and/or network interface.
674 SCNetworkProxiesCopyMatching (CFDictionaryRef globalConfiguration
,
676 CFStringRef interface
) __OSX_AVAILABLE_STARTING(__MAC_10_7
,__IPHONE_5_0
/*SPI*/);
678 #define kSCProxiesMatchServer CFSTR("Server") /* CFString */
679 #define kSCProxiesMatchInterface CFSTR("Interface") /* CFString */
680 #define kSCProxiesMatchExecutableUUID CFSTR("UUID") /* CFUUID */
683 @function SCNetworkProxiesCopyMatchingWithOptions
685 @param globalConfiguration the proxy dictionary currently returned
686 by SCDynamicStoreCopyProxies().
687 @param options A dictionary containing any (or none) of the following:
688 key value description
689 ------------------------------------------------------------------------------------------------
690 kSCProxiesMatchServer CFString The hostname of interest; do not include if no
691 specific hostname should be used in selecting the
692 proxy configurations.
693 kSCProxiesMatchInterface CFString If present, specifies the network interface
694 (e.g. "en0", "en1", ...) whose proxy configuration
695 should be returned. If not present, then proxy usage
696 will not be scoped to an interface.
697 kSCProxiesMatchExecutableUUID CFUUID If present, specifies the Mach-O UUID of the executable
698 on whose behalf the match operation is being performed.
699 If kSCProxiesMatchInterface is present then this option
700 is ignored. If not present, then the Mach-O UUID of
701 the current process is used. The Mach-O UUID is used
702 to match application-specific proxy configurations
703 (i.e., if per-app VPN rules are in effect).
704 @result A CFArray containing the proxy configurations associated with the given options.
707 SCNetworkProxiesCopyMatchingWithOptions (CFDictionaryRef globalConfiguration
,
708 CFDictionaryRef options
) __OSX_AVAILABLE_STARTING(__MAC_10_10
,__IPHONE_8_0
/*SPI*/);
710 extern const CFStringRef kSCProxiesNoGlobal
;
713 @function SCDynamicStoreCopyProxiesWithOptions
716 @param store An SCDynamicStoreRef representing the dynamic store
717 session that should be used for communication with the server.
718 If NULL, a temporary session will be used.
719 @param options A dictionary of proxy options which can include 1 (or more) of the following :
720 key value description
721 ---------------------------------------------------------------------------------------
722 kSCProxiesNoGlobal CFBoolean Bypass any "global" proxy configuration
724 @result Returns a dictionary containing key-value pairs that represent
725 the current internet proxy settings;
726 NULL if no proxy settings have been defined or if an error
728 You must release the returned value.
731 SCDynamicStoreCopyProxiesWithOptions(SCDynamicStoreRef store
, CFDictionaryRef options
) __OSX_AVAILABLE_STARTING(__MAC_10_9
,__IPHONE_7_0
/*SPI*/);
735 #pragma mark Reachability
739 @function SCNetworkReachabilityCopyResolvedAddress
740 @discussion Return the resolved addresses associated with the
742 @result A CFArray[CFData], where each CFData is a (struct sockaddr)
745 SCNetworkReachabilityCopyResolvedAddress (SCNetworkReachabilityRef target
,
749 @function SCNetworkReachabilityCreateWithOptions
750 @discussion Creates a reference to a specified network host. The
751 options allow the caller to specify the node name and/or
752 the service name. This reference can be used later to
753 monitor the reachability of the target host.
754 @param allocator The CFAllocator that should be used to allocate
755 memory for the SCNetworkReachability object.
756 This parameter may be NULL in which case the current
757 default CFAllocator is used. If this reference is not
758 a valid CFAllocator, the behavior is undefined.
759 @param options A CFDictionary containing options specifying the
760 network host. The options reflect the arguments that would
761 be passed to getaddrinfo().
763 SCNetworkReachabilityRef
764 SCNetworkReachabilityCreateWithOptions (CFAllocatorRef allocator
,
765 CFDictionaryRef options
);
768 @function _SC_checkResolverReachabilityByAddress
769 @discussion Check the reachability of a reverse DNS query
772 _SC_checkResolverReachabilityByAddress (SCDynamicStoreRef
*storeP
,
773 SCNetworkReachabilityFlags
*flags
,
775 struct sockaddr
*sa
);
778 @function SCNetworkReachabilityGetInterfaceIndex
779 @discussion Returns the interface index associated with network interface that will
780 be used to interact with the target host.
781 @param target The SCNetworkReachability reference associated with the address or
782 name to be checked for reachability.
783 @result Returns the interface index associated with the target. Returning -1 means that
784 the target is not reachable.
787 SCNetworkReachabilityGetInterfaceIndex (SCNetworkReachabilityRef target
);
793 @function _SC_domainEndsWithDomain
794 @discussion Checks if one domain is a subset of another
795 @param compare_domain The domain to be compared.
796 @param match_domain The domain to be matched.
797 @return TRUE if the match_domain is contained in the compare_domain.
801 _SC_domainEndsWithDomain (CFStringRef compare_domain
,
802 CFStringRef match_domain
);
805 @function _SC_hostMatchesDomain
806 @discussion Checks if a hostname matches a domain. "*" not accepted as a domain. Top-level domain matching not supported.
807 The algorithm is as follows:
809 1. Trim .’s and *’s from the front and back of hostname and domain.
810 2. If the number of .’s left in the hostname and domain are equal, require an exact match.
811 3. Else, if the number of .’s in the hostname is greater than the number of .’s in the domain, and the number of .’s in the domain is greater than zero, append a . to the front of the domain and do a suffix match on the hostname.
815 www.apple.com > * : NO
816 www.apple.com > apple.com : YES
817 www.badapple.com > apple.com : NO
818 www.apple.com > .com : NO
819 foobar > foobar : YES
820 www.apple.com > www.apple.com : YES
821 www.apple.com... > .*.apple.com. : YES
823 @param hostname The specific hostname to check.
824 @param domain The domain to be matched.
825 @return TRUE if the hostname matches the domain. FALSE otherwise.
828 _SC_hostMatchesDomain (CFStringRef hostname
,
835 #if !TARGET_OS_IPHONE
837 * DOS encoding/codepage
840 _SC_dos_encoding_and_codepage (CFStringEncoding macEncoding
,
842 CFStringEncoding
*dosEncoding
,
843 UInt32
*dosCodepage
);
844 #endif // !TARGET_OS_IPHONE
854 _SC_CFBundleGet (void);
857 _SC_CFBundleCopyNonLocalizedString (CFBundleRef bundle
,
860 CFStringRef tableName
);
870 _SC_CFMachPortCreateWithPort (const char * portDescription
,
872 CFMachPortCallBack callout
,
873 CFMachPortContext
*context
);
878 static __inline__ Boolean
879 _SC_CFEqual(CFTypeRef val1
, CFTypeRef val2
)
884 if (val1
!= NULL
&& val2
!= NULL
) {
885 return CFEqual(val1
, val2
);
890 static __inline__ Boolean
891 _SC_isAppleInternal()
893 static int isInternal
= 0;
895 if (isInternal
== 0) {
899 ret
= stat("/AppleInternal", &statbuf
);
900 isInternal
= (ret
== 0) ? 1 : 2;
903 return (isInternal
== 1);
907 _SC_isInstallEnvironment (void);
909 #define MODEL CFSTR("Model")
912 _SC_hw_model (Boolean trim
);
915 _SC_dlopen (const char *framework
);
921 #ifdef DEBUG_MACH_PORT_ALLOCATIONS
922 #define __MACH_PORT_DEBUG(cond, str, port) \
924 if (cond) _SC_logMachPortReferences(str, port); \
926 #else // DEBUG_MACH_PORT_ALLOCATIONS
927 #define __MACH_PORT_DEBUG(cond, str, port)
928 #endif // DEBUG_MACH_PORT_ALLOCATIONS
931 _SC_logMachPortStatus (void);
934 _SC_logMachPortReferences (const char *str
,
938 _SC_copyBacktrace (void);
941 _SC_crash (const char *crash_info
,
942 CFStringRef notifyHeader
,
943 CFStringRef notifyMessage
);
946 _SC_getconninfo (int socket
,
947 struct sockaddr_storage
*src_addr
,
948 struct sockaddr_storage
*dest_addr
,
954 #endif /* _SCPRIVATE_H */