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")
191 #pragma mark SCError()
195 @function _SCErrorSet
196 @discussion Sets the last SystemConfiguration.framework API error code.
197 @param error The error encountered.
199 void _SCErrorSet (int error
);
203 #pragma mark Serialization/Unserialization
207 @function _SCSerialize
208 @discussion Serialize a CFPropertyList object for passing
210 @param obj CFPropertyList object to serialize
211 @param xml A pointer to a CFDataRef, NULL if data should be
213 @param dataRef A pointer to the newly allocated/serialized data
214 @param dataLen A pointer to the length in bytes of the newly
215 allocated/serialized data
217 Boolean
_SCSerialize (CFPropertyListRef obj
,
223 @function _SCUnserialize
224 @discussion Unserialize a stream of bytes passed from/to configd
225 into a CFPropertyList object.
226 @param obj A pointer to memory that will be filled with the CFPropertyList
227 associated with the stream of bytes.
228 @param xml CFDataRef with the serialized data
229 @param dataRef A pointer to the serialized data
230 @param dataLen A pointer to the length of the serialized data
232 Specify either "xml" or "data/dataLen".
234 Boolean
_SCUnserialize (CFPropertyListRef
*obj
,
240 @function _SCSerializeString
241 @discussion Serialize a CFString object for passing
243 @param str CFString key to serialize
244 @param data A pointer to a CFDataRef, NULL if storage should be
246 @param dataRef A pointer to the newly allocated/serialized data
247 @param dataLen A pointer to the length in bytes of the newly
248 allocated/serialized data
250 Boolean
_SCSerializeString (CFStringRef str
,
256 @function _SCUnserializeString
257 @discussion Unserialize a stream of bytes passed from/to configd
258 into a CFString object.
259 @param str A pointer to memory that will be filled with the CFString
260 associated with the stream of bytes.
261 @param utf8 CFDataRef with the serialized data
262 @param dataRef A pointer to the serialized data
263 @param dataLen A pointer to the length of the serialized data
265 Specify either "utf8" or "data/dataLen".
267 Boolean
_SCUnserializeString (CFStringRef
*str
,
273 @function _SCSerializeData
274 @discussion Serialize a CFData object for passing
276 @param data CFData key to serialize
277 @param dataRef A pointer to the newly allocated/serialized data
278 @param dataLen A pointer to the length in bytes of the newly
279 allocated/serialized data
281 Boolean
_SCSerializeData (CFDataRef data
,
286 @function _SCUnserializeData
287 @discussion Unserialize a stream of bytes passed from/to configd
288 into a CFData object.
289 @param data A pointer to memory that will be filled with the CFData
290 associated with the stream of bytes.
291 @param dataRef A pointer to the serialized data
292 @param dataLen A pointer to the length of the serialized data
294 Boolean
_SCUnserializeData (CFDataRef
*data
,
299 @function _SCSerializeMultiple
300 @discussion Convert a CFDictionary containing a set of CFPropertlyList
301 values into a CFDictionary containing a set of serialized CFData
303 @param dict The CFDictionary with CFPropertyList values.
304 @result The serialized CFDictionary with CFData values
307 CFDictionaryRef
_SCSerializeMultiple (CFDictionaryRef dict
);
310 @function _SCUnserializeMultiple
311 @discussion Convert a CFDictionary containing a set of CFData
312 values into a CFDictionary containing a set of serialized
313 CFPropertlyList values.
314 @param dict The CFDictionary with CFData values.
315 @result The serialized CFDictionary with CFPropertyList values
318 CFDictionaryRef
_SCUnserializeMultiple (CFDictionaryRef dict
);
325 @function _SCCreatePropertyListFromResource
326 @discussion Reads a property list referenced by a file URL.
327 @param url The file URL.
328 @result The CFPropertyList content of the URL.
331 _SCCreatePropertyListFromResource (CFURLRef url
);
335 #pragma mark String conversion
339 @function _SC_cfstring_to_cstring
340 @discussion Extracts a C-string from a CFString.
341 @param cfstr The CFString to extract the data from.
342 @param buf A user provided buffer of the specified length. If NULL,
343 a new buffer will be allocated to contain the C-string. It
344 is the responsiblity of the caller to free an allocated
346 @param bufLen The size of the user provided buffer.
347 @param encoding The string encoding
348 @result If the extraction (conversion) is successful then a pointer
349 to the user provided (or allocated) buffer is returned, NULL
350 if the string could not be extracted.
352 char * _SC_cfstring_to_cstring (CFStringRef cfstr
,
355 CFStringEncoding encoding
);
358 * @function _SC_sockaddr_to_string
359 * @discussion Formats a "struct sockaddr" for reporting
360 * @param address The address to format
361 * @param buf A user provided buffer of the specified length.
362 * @param bufLen The size of the user provided buffer.
364 void _SC_sockaddr_to_string (const struct sockaddr
*address
,
370 * @function _SC_string_to_sockaddr
371 * @discussion Parses a string into a "struct sockaddr"
372 * @param str The address string to parse
373 * @param af Allowed address families (AF_UNSPEC, AF_INET, AF_INET6)
374 * @param buf A user provided buffer of the specified length; NULL
375 * if a new buffer should be allocated (and deallocated by the
377 * @param bufLen The size of the user provided buffer.
378 * @result A pointer to the parsed "struct sockaddr"; NULL if
379 * the string could not be parsed as an IP[v6] address.
382 _SC_string_to_sockaddr (const char *str
,
388 * @function _SC_trimDomain
389 * @discussion Trims leading and trailing "."s from a domain or host name
390 * @param domain The domain name to trim
391 * @result The trimmed domain name.
394 CFStringRef
_SC_trimDomain (CFStringRef domain
);
398 #pragma mark Mach IPC
402 @function _SC_sendMachMessage
403 @discussion Sends a trivial mach message (one with just a
404 message ID) to the specified port.
405 @param port The mach port.
406 @param msg_id The message id.
408 void _SC_sendMachMessage (mach_port_t port
,
409 mach_msg_id_t msg_id
);
417 @function _SC_LOG_DEFAULT
418 @discussion Maps a syslog/asl logging level to an os_log level.
419 @param level The syslog/asl logging level
420 @result The os_log level
422 os_log_t
_SC_LOG_DEFAULT ();
426 @function _SC_syslog_os_log_mapping
427 @discussion Maps a syslog/asl logging level to an os_log level.
428 @param level The syslog/asl logging level
429 @result The os_log level
431 os_log_type_t
_SC_syslog_os_log_mapping (int level
);
435 @function _SCCopyDescription
436 @discussion Returns a formatted textual description of a CF object.
437 @param cf The CFType object (a generic reference of type CFTypeRef) from
438 which to derive a description.
439 @param formatOptions A dictionary containing formatting options for the object.
440 @result A string that contains a formatted description of cf.
442 CFStringRef
_SCCopyDescription (CFTypeRef cf
,
443 CFDictionaryRef formatOptions
);
448 @discussion Conditionally issue a log message.
449 @param condition A boolean value indicating if the message should be logged
450 @param level A syslog(3) logging priority.
451 @param formatString The format string
452 @result The specified message will be written to the system message
453 logger (See syslogd(8)).
455 void SCLog (Boolean condition
,
457 CFStringRef formatString
,
458 ...) CF_FORMAT_FUNCTION(3, 4);
461 typedef CF_ENUM(uint32_t, SCLoggerFlags
) {
462 kSCLoggerFlagsNone
= 0x0,
463 kSCLoggerFlagsDefault
= 0x1,
464 kSCLoggerFlagsFile
= 0x2
467 typedef struct SCLogger
* SCLoggerRef
;
471 @function SCLoggerLog
472 @discussion Logs messages using SCLoggerRef
473 @param logger A SCLoggerRef which keeps information about how logging
474 needs to be done. Passing NULL uses the default logger instance.
475 @param level An asl(3) logging priority. Passing the complement of a logging
476 priority (e.g. ~ASL_LEVEL_NOTICE) will result in log message lines
477 NOT being split by a "\n".
478 @param formatString The format string followed by format arguments
479 @result The specified message will be written to the system message
480 logger (See syslogd(8)). If logger is in verbose mode, the message
481 will be also written to a file specified in the ASL Module
483 void SCLoggerLog (SCLoggerRef logger
,
485 CFStringRef formatString
,
486 ...) CF_FORMAT_FUNCTION(3, 4)
487 __OSX_AVAILABLE_STARTING(__MAC_10_8
,__IPHONE_6_0
);
490 @function SCLoggerVLog
491 @discussion Logs messages using SCLoggerRef
492 @param logger A SCLoggerRef which keeps information about how logging
493 needs to be done. Passing NULL uses the default logger instance.
494 @param level An asl(3) logging priority. Passing the complement of a logging
495 priority (e.g. ~ASL_LEVEL_NOTICE) will result in log message lines
496 NOT being split by a "\n".
497 @param formatString The format string
498 @param args The va_list representing the arguments
499 @result The specified message will be written to the system message
500 logger (See syslogd(8)). If logger is in verbose mode, the message
501 will be also written to a file specified in the ASL Module
503 void SCLoggerVLog (SCLoggerRef logger
,
505 CFStringRef formatString
,
506 va_list args
) __OSX_AVAILABLE_STARTING(__MAC_10_9
,__IPHONE_7_0
);
511 @discussion Issue a log message.
512 @param asl An asl client handle to be used for logging. If NULL, a shared
514 @param msg An asl msg structure to be used for logging. If NULL, a default
515 asl msg will be used.
516 @param level A asl(3) logging priority. Passing the complement of a logging
517 priority (e.g. ~ASL_LEVEL_NOTICE) will result in log message lines
518 NOT being split by a "\n".
519 @param formatString The format string
520 @result The specified message will be written to the system message
521 logger (See syslogd(8)).
523 void SCLOG (asl_object_t asl
,
526 CFStringRef formatString
,
527 ...) CF_FORMAT_FUNCTION(4, 5);
532 @discussion Issue an os_log() message.
534 Note: By default, the log messages will be associated with the
535 "com.apple.SystemConfiguration" subsystem. This behavior
536 can be overwritten by #define'ing SC_LOG_HANDLE with the name
537 of an os_log_t global (or a function that returns an os_log_t)
538 *BEFORE* this header is #include'd. In that case, the noted
539 log handle will be used.
541 Also, by #define'ing SC_LOG_OR_PRINT, we will check the "_sc_log"
542 global to see if the messages should [also] be directed to stdout/stderr.
544 @param level The syslog(3 logging priority.
545 @param __string The format string
546 @result The specified message will be written to the unified logging system.
550 #ifndef SC_LOG_HANDLE
551 #define SC_LOG_HANDLE _SC_LOG_DEFAULT() // use [SC] default os_log handle
553 #ifndef SC_LOG_OR_PRINT
554 #define USE_SC_LOG_OR_PRINT // use '_sc_log' to control os_log, printf
555 #endif // !SC_LOG_OR_PRINT
557 #endif // !SC_LOG_HANDLE
559 #ifdef USE_SC_LOG_OR_PRINT
561 #define SC_log(__level, __format, ...) \
563 os_log_t __handle = SC_LOG_HANDLE; \
564 os_log_type_t __type = _SC_syslog_os_log_mapping(__level); \
566 if ((_sc_log != 1) || os_log_type_enabled(__handle, __type)) { \
576 #else // USE_SC_LOG_OR_PRINT
578 #define SC_log(__level, __format, ...) \
580 os_log_type_t __type = _SC_syslog_os_log_mapping(__level); \
581 os_log_with_type(SC_LOG_HANDLE, __type, __format, ## __VA_ARGS__); \
584 #endif // USE_SC_LOG_OR_PRINT
591 @discussion Issue a log message w/os_log(3) or printf(3).
592 @param level A syslog(3) logging priority. If less than 0, log message is multi-line
593 @param format_CF The format string (as a CFString for stdout/stderr)
594 @param log The os_log_t handle (for logging)
595 @param type The os_log_type_t type (for logging)
596 @param format The format string (for logging)
597 @result The specified message will be written to the system message
601 void __SC_Log (int level
,
602 CFStringRef format_CF
,
606 ...) CF_FORMAT_FUNCTION(2, 6) __attribute__((format(os_log
, 5, 6)));
611 @discussion Conditionally issue a debug message.
612 @param condition A boolean value indicating if the message should be written
613 @param stream The output stream for the log message.
614 @param formatString The format string
615 @result The message will be written to the specified stream
618 void SCPrint (Boolean condition
,
620 CFStringRef formatString
,
621 ...) CF_FORMAT_FUNCTION(3, 4);
626 @function SCLoggerCreate
627 @discussion Create a reference to logger which stores information like verbose mode or not, loggerID, etc.
628 loggerID and moduleName both need to be non NULL, or else the function returns NULL.
629 If the moduleName points to a module which doesn't exist, then SCLoggerCreate will fail and
631 @param loggerID CFStringRef which will be appended to the log message when in verbose mode. It will also be
632 used to identify the module where the rules are being defined.
635 SCLoggerCreate (CFStringRef loggerID
);
638 @function SCLoggerGetFlags
639 @discussion Returns the log flags for the logging reference
640 @param logger Reference which points to the logger information
643 SCLoggerGetFlags (SCLoggerRef logger
);
646 @function SCLoggerSetFlags
647 @discussion Sets the log flags for the logger reference
648 @param logger A reference to the logger
649 @param flags SCLoggerFlags value determining where the logs from the logger will be directed
651 void SCLoggerSetFlags (SCLoggerRef logger
,
652 SCLoggerFlags flags
);
659 @function SCNetworkProxiesCopyMatching
661 @param globalConfiguration the proxy dictionary currently returned
662 by SCDynamicStoreCopyProxies().
663 @param server A CFString specying the hostname of interest; NULL if
664 no specific hostname should be used in selecting the proxy
666 @param interface A CFString specifying that the proxy configuration
667 for the provided network interface (e.g. "en0", "en1", ...)
668 should be returned; NULL if proxy usage will not be scoped
670 @result A CFArray containing the proxy configurations associated
671 with the requested server and/or network interface.
675 SCNetworkProxiesCopyMatching (CFDictionaryRef globalConfiguration
,
677 CFStringRef interface
) __OSX_AVAILABLE_STARTING(__MAC_10_7
,__IPHONE_5_0
/*SPI*/);
679 #define kSCProxiesMatchServer CFSTR("Server") /* CFString */
680 #define kSCProxiesMatchInterface CFSTR("Interface") /* CFString */
681 #define kSCProxiesMatchExecutableUUID CFSTR("UUID") /* CFUUID */
684 @function SCNetworkProxiesCopyMatchingWithOptions
686 @param globalConfiguration the proxy dictionary currently returned
687 by SCDynamicStoreCopyProxies().
688 @param options A dictionary containing any (or none) of the following:
689 key value description
690 ------------------------------------------------------------------------------------------------
691 kSCProxiesMatchServer CFString The hostname of interest; do not include if no
692 specific hostname should be used in selecting the
693 proxy configurations.
694 kSCProxiesMatchInterface CFString If present, specifies the network interface
695 (e.g. "en0", "en1", ...) whose proxy configuration
696 should be returned. If not present, then proxy usage
697 will not be scoped to an interface.
698 kSCProxiesMatchExecutableUUID CFUUID If present, specifies the Mach-O UUID of the executable
699 on whose behalf the match operation is being performed.
700 If kSCProxiesMatchInterface is present then this option
701 is ignored. If not present, then the Mach-O UUID of
702 the current process is used. The Mach-O UUID is used
703 to match application-specific proxy configurations
704 (i.e., if per-app VPN rules are in effect).
705 @result A CFArray containing the proxy configurations associated with the given options.
708 SCNetworkProxiesCopyMatchingWithOptions (CFDictionaryRef globalConfiguration
,
709 CFDictionaryRef options
) __OSX_AVAILABLE_STARTING(__MAC_10_10
,__IPHONE_8_0
/*SPI*/);
711 extern const CFStringRef kSCProxiesNoGlobal
;
714 @function SCNetworkProxiesCreateProxyAgentData
717 @param proxyConfig A dictionary representing a proxy configuration
718 @result returns a CFData representing a proxy configuration. This data is readable by all
719 "config-agents" (Agents with domain as "SystemConfig") via config_agent_copy_proxy_information().
720 You must release the returned value.
723 SCNetworkProxiesCreateProxyAgentData(CFDictionaryRef proxyConfig
) __OSX_AVAILABLE_STARTING(__MAC_10_12
,__IPHONE_10_0
/*SPI*/);
726 @function SCDynamicStoreCopyProxiesWithOptions
729 @param store An SCDynamicStoreRef representing the dynamic store
730 session that should be used for communication with the server.
731 If NULL, a temporary session will be used.
732 @param options A dictionary of proxy options which can include 1 (or more) of the following :
733 key value description
734 ---------------------------------------------------------------------------------------
735 kSCProxiesNoGlobal CFBoolean Bypass any "global" proxy configuration
737 @result Returns a dictionary containing key-value pairs that represent
738 the current internet proxy settings;
739 NULL if no proxy settings have been defined or if an error
741 You must release the returned value.
744 SCDynamicStoreCopyProxiesWithOptions(SCDynamicStoreRef store
, CFDictionaryRef options
) __OSX_AVAILABLE_STARTING(__MAC_10_9
,__IPHONE_7_0
/*SPI*/);
747 #pragma mark Reachability
751 @function SCNetworkReachabilityCopyResolvedAddress
752 @discussion Return the resolved addresses associated with the
754 @result A CFArray[CFData], where each CFData is a (struct sockaddr)
757 SCNetworkReachabilityCopyResolvedAddress (SCNetworkReachabilityRef target
,
761 @function SCNetworkReachabilityCreateWithOptions
762 @discussion Creates a reference to a specified network host. The
763 options allow the caller to specify the node name and/or
764 the service name. This reference can be used later to
765 monitor the reachability of the target host.
766 @param allocator The CFAllocator that should be used to allocate
767 memory for the SCNetworkReachability object.
768 This parameter may be NULL in which case the current
769 default CFAllocator is used. If this reference is not
770 a valid CFAllocator, the behavior is undefined.
771 @param options A CFDictionary containing options specifying the
772 network host. The options reflect the arguments that would
773 be passed to getaddrinfo().
775 SCNetworkReachabilityRef
776 SCNetworkReachabilityCreateWithOptions (CFAllocatorRef allocator
,
777 CFDictionaryRef options
);
780 @function _SC_checkResolverReachabilityByAddress
781 @discussion Check the reachability of a reverse DNS query
784 _SC_checkResolverReachabilityByAddress (SCDynamicStoreRef
*storeP
,
785 SCNetworkReachabilityFlags
*flags
,
787 struct sockaddr
*sa
);
790 @function SCNetworkReachabilityGetInterfaceIndex
791 @discussion Returns the interface index associated with network interface that will
792 be used to interact with the target host.
793 @param target The SCNetworkReachability reference associated with the address or
794 name to be checked for reachability.
795 @result Returns the interface index associated with the target. Returning -1 means that
796 the target is not reachable.
799 SCNetworkReachabilityGetInterfaceIndex (SCNetworkReachabilityRef target
);
805 @function _SC_domainEndsWithDomain
806 @discussion Checks if one domain is a subset of another
807 @param compare_domain The domain to be compared.
808 @param match_domain The domain to be matched.
809 @return TRUE if the match_domain is contained in the compare_domain.
813 _SC_domainEndsWithDomain (CFStringRef compare_domain
,
814 CFStringRef match_domain
);
817 @function _SC_hostMatchesDomain
818 @discussion Checks if a hostname matches a domain. "*" not accepted as a domain. Top-level domain matching not supported.
819 The algorithm is as follows:
821 1. Trim .’s and *’s from the front and back of hostname and domain.
822 2. If the number of .’s left in the hostname and domain are equal, require an exact match.
823 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.
827 www.apple.com > * : NO
828 www.apple.com > apple.com : YES
829 www.badapple.com > apple.com : NO
830 www.apple.com > .com : NO
831 foobar > foobar : YES
832 www.apple.com > www.apple.com : YES
833 www.apple.com... > .*.apple.com. : YES
835 @param hostname The specific hostname to check.
836 @param domain The domain to be matched.
837 @return TRUE if the hostname matches the domain. FALSE otherwise.
840 _SC_hostMatchesDomain (CFStringRef hostname
,
847 #if !TARGET_OS_IPHONE
849 * DOS encoding/codepage
852 _SC_dos_encoding_and_codepage (CFStringEncoding macEncoding
,
854 CFStringEncoding
*dosEncoding
,
855 UInt32
*dosCodepage
);
856 #endif // !TARGET_OS_IPHONE
866 _SC_CFBundleGet (void);
869 _SC_CFBundleCopyNonLocalizedString (CFBundleRef bundle
,
872 CFStringRef tableName
);
882 _SC_CFMachPortCreateWithPort (const char * portDescription
,
884 CFMachPortCallBack callout
,
885 CFMachPortContext
*context
);
890 static __inline__ Boolean
891 _SC_CFEqual(CFTypeRef val1
, CFTypeRef val2
)
896 if (val1
!= NULL
&& val2
!= NULL
) {
897 return CFEqual(val1
, val2
);
902 static __inline__ Boolean
903 _SC_isAppleInternal()
905 static int isInternal
= 0;
907 if (isInternal
== 0) {
911 ret
= stat("/AppleInternal", &statbuf
);
912 isInternal
= (ret
== 0) ? 1 : 2;
915 return (isInternal
== 1);
919 _SC_isInstallEnvironment (void);
921 #define MODEL CFSTR("Model")
924 _SC_hw_model (Boolean trim
);
927 _SC_dlopen (const char *framework
);
933 #ifdef DEBUG_MACH_PORT_ALLOCATIONS
934 #define __MACH_PORT_DEBUG(cond, str, port) \
936 if (cond) _SC_logMachPortReferences(str, port); \
938 #else // DEBUG_MACH_PORT_ALLOCATIONS
939 #define __MACH_PORT_DEBUG(cond, str, port)
940 #endif // DEBUG_MACH_PORT_ALLOCATIONS
943 _SC_logMachPortStatus (void);
946 _SC_logMachPortReferences (const char *str
,
950 _SC_copyBacktrace (void);
953 _SC_crash (const char *crash_info
,
954 CFStringRef notifyHeader
,
955 CFStringRef notifyMessage
);
958 _SC_getconninfo (int socket
,
959 struct sockaddr_storage
*src_addr
,
960 struct sockaddr_storage
*dest_addr
,
966 #endif /* _SCPRIVATE_H */