1/*
2 * Copyright (c) 2000-2014 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 _SCPRIVATE_H
25#define _SCPRIVATE_H
26
27#include <sys/cdefs.h>
28#include <sys/socket.h>
29#include <sys/stat.h>
30#include <asl.h>
31#include <sys/syslog.h>
32#include <mach/message.h>
33#include <sys/sysctl.h>
34
35#include <CoreFoundation/CoreFoundation.h>
36
37/* SCDynamicStore SPIs */
38#include <SystemConfiguration/SCDynamicStorePrivate.h>
39#include <SystemConfiguration/SCDynamicStoreCopySpecificPrivate.h>
40#include <SystemConfiguration/SCDynamicStoreSetSpecificPrivate.h>
41
42/* SCPreferences SPIs */
43#include <SystemConfiguration/SCPreferencesPrivate.h>
44#include <SystemConfiguration/SCPreferencesGetSpecificPrivate.h>
45#include <SystemConfiguration/SCPreferencesSetSpecificPrivate.h>
46
47/* [private] Schema Definitions (for SCDynamicStore and SCPreferences) */
48#include <SystemConfiguration/SCSchemaDefinitionsPrivate.h>
49
50/* SCNetworkConfiguration SPIs */
51#include <SystemConfiguration/SCNetworkConfigurationPrivate.h>
52
53/* SCNetworkConnection SPIs */
54#include <SystemConfiguration/SCNetworkConnectionPrivate.h>
55
56/* Keychain SPIs */
57#include <SystemConfiguration/SCPreferencesKeychainPrivate.h>
58
59/*!
60	@header SCPrivate
61 */
62
63
64/* "server" defines */
65#if	!TARGET_IPHONE_SIMULATOR
66#define _SC_SERVER_PROG			"configd"
67#else	// !TARGET_IPHONE_SIMULATOR
68#define _SC_SERVER_PROG			"configd_sim"
69#endif	// !TARGET_IPHONE_SIMULATOR
70
71#define INSTALL_ENVIRONMENT	"__OSINSTALL_ENVIRONMENT"
72#define INSTALL_FACILITY	"install"
73
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);
79
80
81/* framework variables */
82extern int	_sc_debug;	/* non-zero if debugging enabled */
83extern int	_sc_verbose;	/* non-zero if verbose logging enabled */
84extern int	_sc_log;	/* 0 if SC messages should be written to stdout/stderr,
85				   1 if SC messages should be logged w/asl(3),
86				   2 if SC messages should be written to stdout/stderr AND logged */
87
88/* notify(3) keys */
89
90#if	!TARGET_IPHONE_SIMULATOR
91#define _SC_NOTIFY_PREFIX	"com.apple.system.config"
92#else	// !TARGET_IPHONE_SIMULATOR
93#define _SC_NOTIFY_PREFIX	"com.apple.iOS_Simulator.config"
94#endif	// !TARGET_IPHONE_SIMULATOR
95
96#define _SC_NOTIFY_NETWORK_CHANGE	_SC_NOTIFY_PREFIX ".network_change"
97#define _SC_NOTIFY_NETWORK_CHANGE_DNS	_SC_NOTIFY_NETWORK_CHANGE ".dns"
98#define _SC_NOTIFY_NETWORK_CHANGE_NWI	_SC_NOTIFY_NETWORK_CHANGE ".nwi"
99#define _SC_NOTIFY_NETWORK_CHANGE_PROXY	_SC_NOTIFY_PREFIX ".proxy_change"
100
101
102/*!
103	@group SCNetworkReachabilityCreateWithOptions #defines
104	@discussion The following defines the keys and values that can
105		be passed to the SCNetworkReachabilityCreateWithOptions
106		API.
107 */
108
109/*!
110	@constant kSCNetworkReachabilityOptionNodeName
111	@discussion A CFString that will be passed to getaddrinfo(3).  An acceptable
112		value is either a valid host name or a numeric host address string
113		consisting of a dotted decimal IPv4 address or an IPv6 address.
114 */
115#define kSCNetworkReachabilityOptionNodeName			CFSTR("nodename")
116
117/*!
118	@constant kSCNetworkReachabilityOptionLocalAddress
119	@discussion A CFData wrapping a "struct sockaddr" that represents
120		local address associated with a network connection.
121 */
122#define kSCNetworkReachabilityOptionLocalAddress		CFSTR("local-address")
123
124/*!
125	@constant kSCNetworkReachabilityOptionPTRAddress
126	@discussion A CFData wrapping a "struct sockaddr" that represents
127		the reverse-address to be queried.
128 */
129#define kSCNetworkReachabilityOptionPTRAddress			CFSTR("ptr-address")
130
131/*!
132	@constant kSCNetworkReachabilityOptionRemoteAddress
133	@discussion A CFData wrapping a "struct sockaddr" that represents
134		remote address associated with a network connection.
135 */
136#define kSCNetworkReachabilityOptionRemoteAddress		CFSTR("remote-address")
137
138/*!
139	@constant kSCNetworkReachabilityOptionInterface
140	@discussion A CFString specifying that the reachability query should be
141		limited to the provided network interface (e.g. "en0", "en1", ...).
142 */
143#define kSCNetworkReachabilityOptionInterface			CFSTR("interface")
144
145
146/*!
147	@constant kSCNetworkReachabilityOptionConnectionOnDemandBypass
148	@discussion A CFBoolean that indicates if we should bypass the VPNOnDemand
149		checks for this target.
150 */
151#define kSCNetworkReachabilityOptionConnectionOnDemandBypass	CFSTR("ConnectionOnDemandBypass")
152
153/*!
154	@constant kSCNetworkReachabilityOptionResolverBypass
155	@discussion A CFBoolean that indicates if we should bypass resolving any
156		node names.  Instead, the status of the DNS server configuration
157		associated with the name will be returned. */
158#define kSCNetworkReachabilityOptionResolverBypass		CFSTR("ResolverBypass")
159
160
161/*!
162	@constant kSCNetworkReachabilityOptionServerBypass
163	@discussion A CFBoolean that indicates if we should bypass usage of the
164		SCNetworkReachability "server" for this target.
165 */
166#define kSCNetworkReachabilityOptionServerBypass		CFSTR("ServerBypass")
167
168
169
170
171/*!
172	@group
173 */
174
175__BEGIN_DECLS
176
177
178#pragma mark -
179#pragma mark SCError()
180
181
182/*!
183	@function _SCErrorSet
184	@discussion Sets the last SystemConfiguration.framework API error code.
185	@param error The error encountered.
186 */
187void		_SCErrorSet			(int			error);
188
189
190#pragma mark -
191#pragma mark Serialization/Unserialization
192
193
194/*!
195	@function _SCSerialize
196	@discussion Serialize a CFPropertyList object for passing
197		to/from configd.
198	@param obj CFPropertyList object to serialize
199	@param xml A pointer to a CFDataRef, NULL if data should be
200		vm_allocated.
201	@param dataRef A pointer to the newly allocated/serialized data
202	@param dataLen A pointer to the length in bytes of the newly
203		allocated/serialized data
204 */
205Boolean		_SCSerialize			(CFPropertyListRef	obj,
206						 CFDataRef		*xml,
207						 void			**dataRef,
208						 CFIndex		*dataLen);
209
210/*!
211	@function _SCUnserialize
212	@discussion Unserialize a stream of bytes passed from/to configd
213		into a CFPropertyList object.
214	@param obj A pointer to memory that will be filled with the CFPropertyList
215		associated with the stream of bytes.
216	@param xml CFDataRef with the serialized data
217	@param dataRef A pointer to the serialized data
218	@param dataLen A pointer to the length of the serialized data
219
220	Specify either "xml" or "data/dataLen".
221 */
222Boolean		_SCUnserialize			(CFPropertyListRef	*obj,
223						 CFDataRef		xml,
224						 void			*dataRef,
225						 CFIndex		dataLen);
226
227/*!
228	@function _SCSerializeString
229	@discussion Serialize a CFString object for passing
230		to/from configd.
231	@param str CFString key to serialize
232	@param data A pointer to a CFDataRef, NULL if storage should be
233		vm_allocated.
234	@param dataRef A pointer to the newly allocated/serialized data
235	@param dataLen A pointer to the length in bytes of the newly
236		allocated/serialized data
237 */
238Boolean		_SCSerializeString		(CFStringRef		str,
239						 CFDataRef		*data,
240						 void			**dataRef,
241						 CFIndex		*dataLen);
242
243/*!
244	@function _SCUnserializeString
245	@discussion Unserialize a stream of bytes passed from/to configd
246		into a CFString object.
247	@param str A pointer to memory that will be filled with the CFString
248		associated with the stream of bytes.
249	@param utf8 CFDataRef with the serialized data
250	@param dataRef A pointer to the serialized data
251	@param dataLen A pointer to the length of the serialized data
252
253	Specify either "utf8" or "data/dataLen".
254 */
255Boolean		_SCUnserializeString		(CFStringRef		*str,
256						 CFDataRef		utf8,
257						 void			*dataRef,
258						 CFIndex		dataLen);
259
260/*!
261	@function _SCSerializeData
262	@discussion Serialize a CFData object for passing
263		to/from configd.
264	@param data CFData key to serialize
265	@param dataRef A pointer to the newly allocated/serialized data
266	@param dataLen A pointer to the length in bytes of the newly
267		allocated/serialized data
268 */
269Boolean		_SCSerializeData		(CFDataRef		data,
270						 void			**dataRef,
271						 CFIndex		*dataLen);
272
273/*!
274	@function _SCUnserializeData
275	@discussion Unserialize a stream of bytes passed from/to configd
276		into a CFData object.
277	@param data A pointer to memory that will be filled with the CFData
278		associated with the stream of bytes.
279	@param dataRef A pointer to the serialized data
280	@param dataLen A pointer to the length of the serialized data
281 */
282Boolean		_SCUnserializeData		(CFDataRef		*data,
283						 void			*dataRef,
284						 CFIndex		dataLen);
285
286/*!
287	@function _SCSerializeMultiple
288	@discussion Convert a CFDictionary containing a set of CFPropertlyList
289		values into a CFDictionary containing a set of serialized CFData
290		values.
291	@param dict The CFDictionary with CFPropertyList values.
292	@result The serialized CFDictionary with CFData values
293 */
294CF_RETURNS_RETAINED
295CFDictionaryRef	_SCSerializeMultiple		(CFDictionaryRef	dict);
296
297/*!
298	@function _SCUnserializeMultiple
299	@discussion Convert a CFDictionary containing a set of CFData
300		values into a CFDictionary containing a set of serialized
301		CFPropertlyList values.
302	@param dict The CFDictionary with CFData values.
303	@result The serialized CFDictionary with CFPropertyList values
304 */
305CF_RETURNS_RETAINED
306CFDictionaryRef	_SCUnserializeMultiple		(CFDictionaryRef	dict);
307
308
309#pragma mark -
310#pragma mark String conversion
311
312
313/*!
314	@function _SC_cfstring_to_cstring
315	@discussion Extracts a C-string from a CFString.
316	@param cfstr The CFString to extract the data from.
317	@param buf A user provided buffer of the specified length.  If NULL,
318		a new buffer will be allocated to contain the C-string.  It
319		is the responsiblity of the caller to free an allocated
320		buffer.
321	@param bufLen The size of the user provided buffer.
322	@param encoding The string encoding
323	@result If the extraction (conversion) is successful then a pointer
324		to the user provided (or allocated) buffer is returned, NULL
325		if the string could not be extracted.
326 */
327char *		_SC_cfstring_to_cstring		(CFStringRef		cfstr,
328						 char			*buf,
329						 CFIndex		bufLen,
330						 CFStringEncoding	encoding);
331
332/*!
333 *      @function _SC_sockaddr_to_string
334 *      @discussion Formats a "struct sockaddr" for reporting
335 *      @param address The address to format
336 *	@param buf A user provided buffer of the specified length.
337 *	@param bufLen The size of the user provided buffer.
338 */
339void		_SC_sockaddr_to_string		(const struct sockaddr  *address,
340						 char			*buf,
341						 size_t			bufLen);
342
343
344/*!
345 *	@function _SC_string_to_sockaddr
346 *	@discussion Parses a string into a "struct sockaddr"
347 *	@param str The address string to parse
348 *	@param af Allowed address families (AF_UNSPEC, AF_INET, AF_INET6)
349 *	@param buf A user provided buffer of the specified length; NULL
350 *		if a new buffer should be allocated (and deallocated by the
351 *		caller).
352 *	@param bufLen The size of the user provided buffer.
353 *	@result A pointer to the parsed "struct sockaddr"; NULL if
354 *		the string could not be parsed as an IP[v6] address.
355 */
356struct sockaddr *
357_SC_string_to_sockaddr				(const char		*str,
358						 sa_family_t		af,
359						 void			*buf,
360						 size_t			bufLen);
361
362/*!
363 *	@function _SC_trimDomain
364 *	@discussion Trims leading and trailing "."s from a domain or host name
365 *	@param domain The domain name to trim
366 *	@result The trimmed domain name.
367 */
368CF_RETURNS_RETAINED
369CFStringRef	_SC_trimDomain			(CFStringRef		domain);
370
371
372#pragma mark -
373#pragma mark Mach IPC
374
375
376/*!
377	@function _SC_sendMachMessage
378	@discussion Sends a trivial mach message (one with just a
379		message ID) to the specified port.
380	@param port The mach port.
381	@param msg_id The message id.
382 */
383void		_SC_sendMachMessage		(mach_port_t		port,
384						 mach_msg_id_t		msg_id);
385
386
387#pragma mark -
388#pragma mark Logging
389
390
391/*!
392	@function _SCCopyDescription
393	@discussion Returns a formatted textual description of a CF object.
394	@param cf The CFType object (a generic reference of type CFTypeRef) from
395		which to derive a description.
396	@param formatOptions A dictionary containing formatting options for the object.
397	@result A string that contains a formatted description of cf.
398 */
399CFStringRef	_SCCopyDescription		(CFTypeRef		cf,
400						 CFDictionaryRef	formatOptions);
401
402
403/*!
404	@function SCLog
405	@discussion Conditionally issue a log message.
406	@param condition A boolean value indicating if the message should be logged
407	@param level A syslog(3) logging priority.
408	@param formatString The format string
409	@result The specified message will be written to the system message
410		logger (See syslogd(8)).
411 */
412void		SCLog				(Boolean		condition,
413						 int			level,
414						 CFStringRef		formatString,
415						 ...)	CF_FORMAT_FUNCTION(3, 4);
416
417enum {
418	kSCLoggerFlagsNone		= 0x0,
419	kSCLoggerFlagsDefault	= 0x1,
420	kSCLoggerFlagsFile		= 0x2
421};
422typedef uint32_t	SCLoggerFlags;
423
424typedef struct SCLogger * SCLoggerRef;
425
426
427/*!
428	@function SCLoggerLog
429	@discussion Logs messages using SCLoggerRef
430	@param	logger A SCLoggerRef which keeps information about how logging
431		needs to be done. Passing NULL uses the default logger instance.
432	@param level An asl(3) logging priority. Passing the complement of a logging
433		priority (e.g. ~ASL_LEVEL_NOTICE) will result in log message lines
434		NOT being split by a "\n".
435	@param formatString The format string followed by format arguments
436	@result The specified message will be written to the system message
437		logger (See syslogd(8)). If logger is in verbose mode, the message
438		will be also written to a file specified in the ASL Module
439 */
440void		SCLoggerLog			(SCLoggerRef	logger,
441						 int		level,
442						 CFStringRef	formatString,
443						 ...)	CF_FORMAT_FUNCTION(3, 4)
444							__OSX_AVAILABLE_STARTING(__MAC_10_8,__IPHONE_6_0);
445
446/*!
447	@function SCLoggerVLog
448	@discussion Logs messages using SCLoggerRef
449	@param logger A SCLoggerRef which keeps information about how logging
450		needs to be done. Passing NULL uses the default logger instance.
451	@param level An asl(3) logging priority. Passing the complement of a logging
452		priority (e.g. ~ASL_LEVEL_NOTICE) will result in log message lines
453		NOT being split by a "\n".
454	@param formatString The format string
455	@param args The va_list representing the arguments
456	@result The specified message will be written to the system message
457		logger (See syslogd(8)). If logger is in verbose mode, the message
458		will be also written to a file specified in the ASL Module
459 */
460void		SCLoggerVLog			(SCLoggerRef	logger,
461						 int		level,
462						 CFStringRef	formatString,
463						 va_list	args)	__OSX_AVAILABLE_STARTING(__MAC_10_9,__IPHONE_7_0);
464
465
466#ifdef	USE_NEW_SCLOG
467#define SCLOG(sclogger, level, __string, ...)	SCLoggerLog(sclogger, level, CFSTR(__string), ## __VA_ARGS__)	// temporary, remove once all "old" clients have migrated
468#else
469/*!
470	@function SCLOG
471	@discussion Issue a log message.
472	@param asl An asl client handle to be used for logging. If NULL, a shared
473		handle will be used.
474	@param msg An asl msg structure to be used for logging. If NULL, a default
475		asl msg will be used.
476	@param level A asl(3) logging priority. Passing the complement of a logging
477		priority (e.g. ~ASL_LEVEL_NOTICE) will result in log message lines
478		NOT being split by a "\n".
479	@param formatString The format string
480	@result The specified message will be written to the system message
481		logger (See syslogd(8)).
482 */
483void		SCLOG				(asl_object_t		asl,
484						 asl_object_t		msg,
485						 int			level,
486						 CFStringRef		formatString,
487						 ...)	CF_FORMAT_FUNCTION(4, 5);
488
489
490#endif
491
492/*!
493	@function SCPrint
494	@discussion Conditionally issue a debug message.
495	@param condition A boolean value indicating if the message should be written
496	@param stream The output stream for the log message.
497	@param formatString The format string
498	@result The message will be written to the specified stream
499		stream.
500 */
501void		SCPrint				(Boolean		condition,
502						 FILE			*stream,
503						 CFStringRef		formatString,
504						 ...)	CF_FORMAT_FUNCTION(3, 4);
505
506
507
508/*!
509	@function SCTrace
510	@discussion Conditionally issue a debug message with a time stamp.
511	@param condition A boolean value indicating if the message should be written
512	@param stream The output stream for the log message.
513	@param formatString The format string
514	@result The message will be written to the specified stream
515		stream.
516 */
517void		SCTrace				(Boolean		condition,
518						 FILE			*stream,
519						 CFStringRef		formatString,
520						 ...)	CF_FORMAT_FUNCTION(3, 4);
521
522/*!
523	@function SCLoggerCreate
524	@discussion Create a reference to logger which stores information like verbose mode or not, loggerID, etc.
525			loggerID and moduleName both need to be non NULL, or else the function returns NULL.
526			If the moduleName points to a module which doesn't exist, then SCLoggerCreate will fail and
527			return NULL;
528	@param loggerID CFStringRef which will be appended to the log message when in verbose mode. It will also be
529			used to identify the module where the rules are being defined.
530 */
531SCLoggerRef
532SCLoggerCreate					(CFStringRef loggerID);
533
534/*!
535	@function SCLoggerGetFlags
536	@discussion Returns the log flags for the logging reference
537	@param	logger Reference which points to the logger information
538 */
539SCLoggerFlags
540SCLoggerGetFlags				(SCLoggerRef logger);
541
542/*!
543	@function SCLoggerSetFlags
544	@discussion Sets the log flags for the logger reference
545	@param	logger A reference to the logger
546	@param	flags SCLoggerFlags value determining where the logs from the logger will be directed
547 */
548void		SCLoggerSetFlags		(SCLoggerRef logger,
549						 SCLoggerFlags flags);
550
551#pragma mark -
552#pragma mark Proxies
553
554
555/*!
556	@function SCNetworkProxiesCopyMatching
557	@discussion
558	@param globalConfiguration the proxy dictionary currently returned
559		by SCDynamicStoreCopyProxies().
560	@param server A CFString specying the hostname of interest; NULL if
561		no specific hostname should be used in selecting the proxy
562		configurations.
563	@param interface A CFString specifying that the proxy configuration
564		for the provided network interface (e.g. "en0", "en1", ...)
565		should be returned; NULL if proxy usage will not be scoped
566		to an interface.
567	@result A CFArray containing the proxy configurations associated
568		with the requested server and/or network interface.
569
570 */
571CFArrayRef
572SCNetworkProxiesCopyMatching			(CFDictionaryRef	globalConfiguration,
573						 CFStringRef		server,
574						 CFStringRef		interface)	__OSX_AVAILABLE_STARTING(__MAC_10_7,__IPHONE_5_0/*SPI*/);
575
576#define kSCProxiesMatchServer		CFSTR("Server")		/* CFString */
577#define kSCProxiesMatchInterface	CFSTR("Interface")	/* CFString */
578#define kSCProxiesMatchExecutableUUID	CFSTR("UUID")		/* CFUUID */
579
580/*!
581	@function SCNetworkProxiesCopyMatchingWithOptions
582	@discussion
583	@param globalConfiguration the proxy dictionary currently returned
584		by SCDynamicStoreCopyProxies().
585	@param options A dictionary containing any (or none) of the following:
586		key				value		description
587		------------------------------------------------------------------------------------------------
588		kSCProxiesMatchServer		CFString	The hostname of interest; do not include if no
589								specific hostname should be used in selecting the
590								proxy configurations.
591		kSCProxiesMatchInterface	CFString	If present, specifies the network interface
592								(e.g. "en0", "en1", ...) whose proxy configuration
593								should be returned. If not present, then proxy usage
594								will not be scoped to an interface.
595		kSCProxiesMatchExecutableUUID	CFUUID		If present, specifies the Mach-O UUID of the executable
596								on whose behalf the match operation is being performed.
597								If kSCProxiesMatchInterface is present then this option
598							   	is ignored. If not present, then the Mach-O UUID of
599							   	the current process is used. The Mach-O UUID is used
600							   	to match application-specific proxy configurations
601							   	(i.e., if per-app VPN rules are in effect).
602	@result A CFArray containing the proxy configurations associated with the given options.
603 */
604CFArrayRef
605SCNetworkProxiesCopyMatchingWithOptions		(CFDictionaryRef	globalConfiguration,
606						 CFDictionaryRef	options)	__OSX_AVAILABLE_STARTING(__MAC_10_10,__IPHONE_8_0/*SPI*/);
607
608extern const CFStringRef	kSCProxiesNoGlobal;
609
610/*!
611 @function SCDynamicStoreCopyProxiesWithOptions
612 @discussion
613
614	@param	store An SCDynamicStoreRef representing the dynamic store
615		session that should be used for communication with the server.
616		If NULL, a temporary session will be used.
617	@param	options  A dictionary of proxy options which can include 1 (or more) of the following :
618		key				value		description
619		---------------------------------------------------------------------------------------
620		kSCProxiesNoGlobal		CFBoolean	Bypass any "global" proxy configuration
621		...
622	@result Returns a dictionary containing key-value pairs that represent
623		the current internet proxy settings;
624		NULL if no proxy settings have been defined or if an error
625		was encountered.
626		You must release the returned value.
627*/
628CFDictionaryRef
629SCDynamicStoreCopyProxiesWithOptions(SCDynamicStoreRef store, CFDictionaryRef options)	__OSX_AVAILABLE_STARTING(__MAC_10_9,__IPHONE_7_0/*SPI*/);
630
631#pragma mark -
632#pragma mark Reachability
633
634
635/*!
636	@function SCNetworkReachabilityCopyOnDemandService
637	@discussion For target hosts that require an OnDemand connection, returns
638		the SCNetworkService associated with the connection and user
639		options to use with SCNetworkConnectionStart.
640	@result The SCNetworkService for the target; NULL if there is
641		no associated OnDemand service.
642 */
643SCNetworkServiceRef
644SCNetworkReachabilityCopyOnDemandService	(SCNetworkReachabilityRef	target,
645						 CFDictionaryRef		*userOptions);
646
647/*!
648	@function SCNetworkReachabilityCopyResolvedAddress
649	@discussion Return the resolved addresses associated with the
650		target host.
651	@result A CFArray[CFData], where each CFData is a (struct sockaddr)
652 */
653CFArrayRef
654SCNetworkReachabilityCopyResolvedAddress	(SCNetworkReachabilityRef	target,
655						 int				*error_num);
656
657/*!
658	@function SCNetworkReachabilityCreateWithOptions
659	@discussion Creates a reference to a specified network host.  The
660		options allow the caller to specify the node name and/or
661		the service name.  This reference can be used later to
662		monitor the reachability of the target host.
663	@param allocator The CFAllocator that should be used to allocate
664		memory for the SCNetworkReachability object.
665		This parameter may be NULL in which case the current
666		default CFAllocator is used. If this reference is not
667		a valid CFAllocator, the behavior is undefined.
668	@param options A CFDictionary containing options specifying the
669		network host.  The options reflect the arguments that would
670		be passed to getaddrinfo().
671  */
672SCNetworkReachabilityRef
673SCNetworkReachabilityCreateWithOptions		(CFAllocatorRef		allocator,
674						 CFDictionaryRef	options);
675
676/*!
677	@function _SC_checkResolverReachabilityByAddress
678	@discussion Check the reachability of a reverse DNS query
679 */
680Boolean
681_SC_checkResolverReachabilityByAddress		(SCDynamicStoreRef		*storeP,
682						 SCNetworkReachabilityFlags	*flags,
683						 Boolean			*haveDNS,
684						 struct sockaddr		*sa);
685
686/*!
687	@function SCNetworkReachabilityGetInterfaceIndex
688	@discussion Returns the interface index associated with network interface that will
689		be used to interact with the target host.
690	@param target The SCNetworkReachability reference associated with the address or
691		name to be checked for reachability.
692	@result Returns the interface index associated with the target.  Returning -1 means that
693		the target is not reachable.
694 */
695int
696SCNetworkReachabilityGetInterfaceIndex		(SCNetworkReachabilityRef	target);
697
698
699#pragma mark -
700#pragma mark Domain
701/*!
702	@function    _SC_domainEndsWithDomain
703	@discussion  Checks if one domain is a subset of another
704	@param compare_domain The domain to be compared.
705	@param match_domain The domain to be matched.
706	@return TRUE if the match_domain is contained in the compare_domain.
707		 FLASE otherwise.
708 */
709Boolean
710_SC_domainEndsWithDomain			(CFStringRef			compare_domain,
711						 CFStringRef 			match_domain);
712
713/*!
714 @function    _SC_hostMatchesDomain
715 @discussion  Checks if a hostname matches a domain. "*" not accepted as a domain. Top-level domain matching not supported.
716 The algorithm is as follows:
717
718 1. Trim .’s and *’s from the front and back of hostname and domain.
719 2. If the number of .’s left in the hostname and domain are equal, require an exact match.
720 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.
721 4. Else, fail.
722
723 Examples
724 www.apple.com > * : NO
725 www.apple.com > apple.com : YES
726 www.badapple.com > apple.com : NO
727 www.apple.com > .com : NO
728 foobar > foobar : YES
729 www.apple.com > www.apple.com : YES
730 www.apple.com... > .*.apple.com. : YES
731
732 @param hostname The specific hostname to check.
733 @param domain The domain to be matched.
734 @return TRUE if the hostname matches the domain. FALSE otherwise.
735 */
736Boolean
737_SC_hostMatchesDomain				(CFStringRef			hostname,
738						 CFStringRef			domain);
739
740#pragma mark -
741#pragma mark NetBIOS
742
743
744#if	!TARGET_OS_IPHONE
745/*
746 * DOS encoding/codepage
747 */
748void
749_SC_dos_encoding_and_codepage			(CFStringEncoding	macEncoding,
750						 UInt32			macRegion,
751						 CFStringEncoding	*dosEncoding,
752						 UInt32			*dosCodepage);
753#endif	// !TARGET_OS_IPHONE
754
755#pragma mark -
756#pragma mark ScheduleWithRunLoop/UnscheduleFromRunLoop
757
758
759/*
760 * object / CFRunLoop  management
761 */
762void
763_SC_signalRunLoop				(CFTypeRef		obj,
764						 CFRunLoopSourceRef     rls,
765						 CFArrayRef		rlList);
766
767Boolean
768_SC_isScheduled					(CFTypeRef		obj,
769						 CFRunLoopRef		runLoop,
770						 CFStringRef		runLoopMode,
771						 CFMutableArrayRef      rlList);
772
773void
774_SC_schedule					(CFTypeRef		obj,
775						 CFRunLoopRef		runLoop,
776						 CFStringRef		runLoopMode,
777						 CFMutableArrayRef      rlList);
778
779Boolean
780_SC_unschedule					(CFTypeRef		obj,
781						 CFRunLoopRef		runLoop,
782						 CFStringRef		runLoopMode,
783						 CFMutableArrayRef      rlList,
784						 Boolean		all);
785
786#pragma mark -
787#pragma mark Bundle
788
789
790/*
791 * bundle access
792 */
793CFBundleRef
794_SC_CFBundleGet					(void);
795
796CFStringRef
797_SC_CFBundleCopyNonLocalizedString		(CFBundleRef		bundle,
798						 CFStringRef		key,
799						 CFStringRef		value,
800						 CFStringRef		tableName);
801
802#pragma mark -
803#pragma mark Misc
804
805
806/*
807 * mach port access
808 */
809CFMachPortRef
810_SC_CFMachPortCreateWithPort			(const char *		portDescription,
811						 mach_port_t		portNum,
812						 CFMachPortCallBack	callout,
813						 CFMachPortContext	*context);
814
815/*
816 * misc
817 */
818static __inline__ Boolean
819_SC_CFEqual(CFTypeRef val1, CFTypeRef val2)
820{
821	if (val1 == val2) {
822	    return TRUE;
823	}
824	if (val1 != NULL && val2 != NULL) {
825		return CFEqual(val1, val2);
826	}
827	return FALSE;
828}
829
830static __inline__ Boolean
831_SC_isAppleInternal()
832{
833	static int isInternal	= 0;
834
835	if (isInternal == 0) {
836		int		ret;
837		struct stat	statbuf;
838
839		ret = stat("/AppleInternal", &statbuf);
840		isInternal = (ret == 0) ? 1 : 2;
841	}
842
843	return (isInternal == 1);
844}
845
846#define	MODEL			CFSTR("Model")
847
848CFStringRef
849_SC_hw_model					(Boolean		trim);
850
851/*
852 * debugging
853 */
854
855#ifdef	DEBUG_MACH_PORT_ALLOCATIONS
856	#define __MACH_PORT_DEBUG(cond, str, port)		\
857	do {							\
858		if (cond) _SC_logMachPortReferences(str, port);	\
859	} while (0)
860#else	// DEBUG_MACH_PORT_ALLOCATIONS
861	#define __MACH_PORT_DEBUG(cond, str, port)
862#endif	// DEBUG_MACH_PORT_ALLOCATIONS
863
864void
865_SC_logMachPortStatus				(void);
866
867void
868_SC_logMachPortReferences			(const char		*str,
869						 mach_port_t		port);
870
871CFStringRef
872_SC_copyBacktrace				(void);
873
874void
875_SC_crash					(const char		*crash_info,
876						 CFStringRef		notifyHeader,
877						 CFStringRef		notifyMessage);
878
879Boolean
880_SC_getconninfo					(int				socket,
881						 struct sockaddr_storage	*src_addr,
882						 struct sockaddr_storage	*dest_addr,
883						 int				*if_index,
884						 uint32_t			*flags);
885
886__END_DECLS
887
888#endif	/* _SCPRIVATE_H */
889