-
Notifications
You must be signed in to change notification settings - Fork 3
/
listing34.html
executable file
·1064 lines (870 loc) · 39.4 KB
/
listing34.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd">
<html>
<head>
<!-- BEGIN META TAG INFO -->
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<link rel="home" href="http://developer.apple.com/">
<link rel="find" href="http://developer.apple.com/search/">
<link rel="stylesheet" type="text/css" href="../../documentation/css/adcstyle.css" title="fonts">
<script language="JavaScript" src="../../documentation/js/adc.js" type="text/javascript"></script>
<!-- END META TAG INFO -->
<!-- BEGIN TITLE -->
<title>QISA - /MoreIsBetter Bits/MoreIsBetter/MIB-Libraries/MoreSCF/MoreSCFHelpers.c</title>
<!-- END TITLE -->
<script language="JavaScript">
function JumpToNewPage() {
window.location=document.scpopupmenu.gotop.value;
return true;
}
</script>
</head>
<!-- BEGIN BODY OPEN -->
<body>
<!--END BODY OPEN -->
<!-- START CENTER OPEN -->
<center>
<!-- END CENTER OPEN -->
<!-- BEGIN LOGO AND SEARCH -->
<!--#include virtual="/includes/adcnavbar"-->
<!-- END LOGO AND SEARCH -->
<!-- START BREADCRUMB -->
<div id="breadcrumb">
<table width="680" border="0" cellpadding="0" cellspacing="0">
<tr>
<td scope="row"><img width="340" height="10" src="images/1dot.gif" alt=""></td>
<td><img width="340" height="10" src="images/1dot.gif" alt=""></td>
</tr>
<tr valign="middle">
<td align="left" colspan="2">
<a href="http://developer.apple.com/">ADC Home</a> > <a href="../../referencelibrary/index.html">Reference Library</a> > <a href="../../samplecode/index.html">Sample Code</a> > <a href="../../samplecode/Networking/index.html">Networking</a> > <a href="../../samplecode/Networking/idxDarwin-date.html">Darwin</a> > <A HREF="javascript:location.replace('index.html');">QISA</A> >
</td>
</tr>
<tr>
<td colspan="2" scope="row"><img width="680" height="35" src="images/1dot.gif" alt=""></td>
</tr>
</table>
</div>
<!-- END BREADCRUMB -->
<!-- START MAIN CONTENT -->
<!-- START TITLE GRAPHIC AND INTRO-->
<table width="680" border="0" cellpadding="0" cellspacing="0">
<tr align="left" valign="top">
<td><h1><div id="pagehead">QISA</div></h1></td>
</tr>
</table>
<!-- END TITLE GRAPHIC AND INTRO -->
<!-- START WIDE COLUMN -->
<table width="680" border="0" cellpadding="0" cellspacing="0">
<tr align="left" valign="top">
<td id="scdetails">
<h2>/MoreIsBetter Bits/MoreIsBetter/MIB-Libraries/MoreSCF/MoreSCFHelpers.c</h2>
<form name="scpopupmenu" onSubmit="return false;" method=post>
<p><strong>View Source Code:</strong>
<select name="gotop" onChange="JumpToNewPage();" style="width:340px"><option selected value="ingnore">Select File</option>
<option value="listing1.html">/MoreIsBetter Bits/MoreIsBetter/MIB-Libraries/MoreAppearance/MoreAppearance.cp</option>
<option value="listing2.html">/MoreIsBetter Bits/MoreIsBetter/MIB-Libraries/MoreAppearance/MoreAppearance.h</option>
<option value="listing3.html">/MoreIsBetter Bits/MoreIsBetter/MIB-Libraries/MoreAppleEvents/MoreAEDataModel.c</option>
<option value="listing4.html">/MoreIsBetter Bits/MoreIsBetter/MIB-Libraries/MoreAppleEvents/MoreAEDataModel.h</option>
<option value="listing5.html">/MoreIsBetter Bits/MoreIsBetter/MIB-Libraries/MoreAppleEvents/MoreAEObjects.c</option>
<option value="listing6.html">/MoreIsBetter Bits/MoreIsBetter/MIB-Libraries/MoreAppleEvents/MoreAEObjects.h</option>
<option value="listing7.html">/MoreIsBetter Bits/MoreIsBetter/MIB-Libraries/MoreAppleEvents/MoreAppleEvents.cp</option>
<option value="listing8.html">/MoreIsBetter Bits/MoreIsBetter/MIB-Libraries/MoreAppleEvents/MoreAppleEvents.h</option>
<option value="listing9.html">/MoreIsBetter Bits/MoreIsBetter/MIB-Libraries/MoreCarbonEvents/MoreCarbonEvents.c</option>
<option value="listing10.html">/MoreIsBetter Bits/MoreIsBetter/MIB-Libraries/MoreCarbonEvents/MoreCarbonEvents.h</option>
<option value="listing11.html">/MoreIsBetter Bits/MoreIsBetter/MIB-Libraries/MoreCFQ/MoreCFQ.c</option>
<option value="listing12.html">/MoreIsBetter Bits/MoreIsBetter/MIB-Libraries/MoreCFQ/MoreCFQ.h</option>
<option value="listing13.html">/MoreIsBetter Bits/MoreIsBetter/MIB-Libraries/MoreControls/MoreControls.cp</option>
<option value="listing14.html">/MoreIsBetter Bits/MoreIsBetter/MIB-Libraries/MoreControls/MoreControls.h</option>
<option value="listing15.html">/MoreIsBetter Bits/MoreIsBetter/MIB-Libraries/MoreDialogs/MoreDialogs.cp</option>
<option value="listing16.html">/MoreIsBetter Bits/MoreIsBetter/MIB-Libraries/MoreDialogs/MoreDialogs.h</option>
<option value="listing17.html">/MoreIsBetter Bits/MoreIsBetter/MIB-Libraries/MoreInterfaceLib/MoreInterfaceLib.c</option>
<option value="listing18.html">/MoreIsBetter Bits/MoreIsBetter/MIB-Libraries/MoreInterfaceLib/MoreInterfaceLib.h</option>
<option value="listing19.html">/MoreIsBetter Bits/MoreIsBetter/MIB-Libraries/MoreInterfaceLib/RemoteAccessInterface.h</option>
<option value="listing20.html">/MoreIsBetter Bits/MoreIsBetter/MIB-Libraries/MoreMemory/MoreMemory.c</option>
<option value="listing21.html">/MoreIsBetter Bits/MoreIsBetter/MIB-Libraries/MoreMemory/MoreMemory.h</option>
<option value="listing22.html">/MoreIsBetter Bits/MoreIsBetter/MIB-Libraries/MoreOSUtils/MoreOSUtils.c</option>
<option value="listing23.html">/MoreIsBetter Bits/MoreIsBetter/MIB-Libraries/MoreOSUtils/MoreOSUtils.h</option>
<option value="listing24.html">/MoreIsBetter Bits/MoreIsBetter/MIB-Libraries/MoreProcesses/MoreProcesses.cp</option>
<option value="listing25.html">/MoreIsBetter Bits/MoreIsBetter/MIB-Libraries/MoreProcesses/MoreProcesses.h</option>
<option value="listing26.html">/MoreIsBetter Bits/MoreIsBetter/MIB-Libraries/MoreQuickDraw/MoreQuickDraw.cp</option>
<option value="listing27.html">/MoreIsBetter Bits/MoreIsBetter/MIB-Libraries/MoreQuickDraw/MoreQuickDraw.h</option>
<option value="listing28.html">/MoreIsBetter Bits/MoreIsBetter/MIB-Libraries/MoreSCF/MoreSCF.c</option>
<option value="listing29.html">/MoreIsBetter Bits/MoreIsBetter/MIB-Libraries/MoreSCF/MoreSCF.h</option>
<option value="listing30.html">/MoreIsBetter Bits/MoreIsBetter/MIB-Libraries/MoreSCF/MoreSCFCCLScanner.c</option>
<option value="listing31.html">/MoreIsBetter Bits/MoreIsBetter/MIB-Libraries/MoreSCF/MoreSCFCCLScanner.h</option>
<option value="listing32.html">/MoreIsBetter Bits/MoreIsBetter/MIB-Libraries/MoreSCF/MoreSCFDigest.c</option>
<option value="listing33.html">/MoreIsBetter Bits/MoreIsBetter/MIB-Libraries/MoreSCF/MoreSCFDigest.h</option>
<option value="listing34.html">/MoreIsBetter Bits/MoreIsBetter/MIB-Libraries/MoreSCF/MoreSCFHelpers.c</option>
<option value="listing35.html">/MoreIsBetter Bits/MoreIsBetter/MIB-Libraries/MoreSCF/MoreSCFHelpers.h</option>
<option value="listing36.html">/MoreIsBetter Bits/MoreIsBetter/MIB-Libraries/MoreSCF/MoreSCFPortScanner.c</option>
<option value="listing37.html">/MoreIsBetter Bits/MoreIsBetter/MIB-Libraries/MoreSCF/MoreSCFPortScanner.h</option>
<option value="listing38.html">/MoreIsBetter Bits/MoreIsBetter/MIB-Libraries/MoreSecurity/MoreSecurity.c</option>
<option value="listing39.html">/MoreIsBetter Bits/MoreIsBetter/MIB-Libraries/MoreSecurity/MoreSecurity.h</option>
<option value="listing40.html">/MoreIsBetter Bits/MoreIsBetter/MIB-Libraries/MoreSetup.h</option>
<option value="listing41.html">/MoreIsBetter Bits/MoreIsBetter/MIB-Libraries/MoreTextUtils/MoreTextUtils.cp</option>
<option value="listing42.html">/MoreIsBetter Bits/MoreIsBetter/MIB-Libraries/MoreTextUtils/MoreTextUtils.h</option>
<option value="listing43.html">/MoreIsBetter Bits/MoreIsBetter/MIB-Libraries/MoreUNIX/MoreUNIX.c</option>
<option value="listing44.html">/MoreIsBetter Bits/MoreIsBetter/MIB-Libraries/MoreUNIX/MoreUNIX.h</option>
<option value="listing45.html">/MoreIsBetter Bits/MoreIsBetter/MIB-Libraries/MoreWindows/MoreWindows.cp</option>
<option value="listing46.html">/MoreIsBetter Bits/MoreIsBetter/MIB-Libraries/MoreWindows/MoreWindows.h</option>
<option value="listing47.html">/MoreIsBetter Bits/MoreIsBetter/MIB-Libraries/NetworkSetup/MoreNetworkSetup.c</option>
<option value="listing48.html">/MoreIsBetter Bits/MoreIsBetter/MIB-Libraries/NetworkSetup/MoreNetworkSetup.h</option>
<option value="listing49.html">/MoreIsBetter Bits/MoreIsBetter/MIB-Libraries/NetworkSetup/NetworkSetupHelpers.c</option>
<option value="listing50.html">/MoreIsBetter Bits/MoreIsBetter/MIB-Libraries/NetworkSetup/NetworkSetupHelpers.h</option>
<option value="listing51.html">/MoreIsBetter Bits/MoreIsBetter/MIB-Libraries/NetworkSetup/OldStyleAPI/OldOTConfigLib.h</option>
<option value="listing52.html">/QISA.c</option>
<option value="listing53.html">/QISA.h</option>
<option value="listing54.html">/QISAPanels.c</option>
<option value="listing55.html">/QISAPanels.h</option>
<option value="listing56.html">/QISAPlatform.c</option>
<option value="listing57.html">/QISAPlatform.h</option>
<option value="listing58.html">/QISAPlatformCFM/QISAPlatformCFM.c</option>
<option value="listing59.html">/QISAPlatformCFM/QISAPlatformCFMPrefix.h</option>
<option value="listing60.html">/QISAPlatformMach-O/QISAPlatformMach-O.c</option>
<option value="listing61.html">/QISAPlatformMach-O/QISASetupTool.c</option>
<option value="listing62.html">/ReadMeAboutQISA.html</option></select>
</p>
</form>
<p><strong><a href="QISA.zip">Download Sample</a></strong> (“QISA.zip”, 610.6K)<BR>
<strong><a href="QISA.dmg">Download Sample</a></strong> (“QISA.dmg”, 903.9K)</p>
<!--
<p><strong><a href="#">Download Sample</a></strong> (“filename.sit”, 500K)</p>
-->
</td>
</tr>
<tr>
<td scope="row"><img width="680" height="10" src="images/1dot.gif" alt=""><br>
<img height="1" width="680" src="images/1dot_919699.gif" alt=""><br>
<img width="680" height="20" src="images/1dot.gif" alt=""></td>
</tr>
<tr>
<td scope="row">
<!--googleon: index -->
<pre class="sourcecodebox">/* File: MoreSCFHelpers.c Contains: High-level System Configuration framework operations. Written by: Quinn Copyright: Copyright (c) 2001 by Apple Computer, Inc., All Rights Reserved. Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Computer, Inc. ("Apple") in consideration of your agreement to the following terms, and your use, installation, modification or redistribution of this Apple software constitutes acceptance of these terms. If you do not agree with these terms, please do not use, install, modify or redistribute this Apple software. In consideration of your agreement to abide by the following terms, and subject to these terms, Apple grants you a personal, non-exclusive license, under Apple's copyrights in this original Apple software (the "Apple Software"), to use, reproduce, modify and redistribute the Apple Software, with or without modifications, in source and/or binary forms; provided that if you redistribute the Apple Software in its entirety and without modifications, you must retain this notice and the following text and disclaimers in all such redistributions of the Apple Software. Neither the name, trademarks, service marks or logos of Apple Computer, Inc. may be used to endorse or promote products derived from the Apple Software without specific prior written permission from Apple. Except as expressly stated in this notice, no other rights or licenses, express or implied, are granted by Apple herein, including but not limited to any patent rights that may be infringed by your derivative works or by other works in which the Apple Software may be incorporated. The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Change History (most recent first):$Log: MoreSCFHelpers.c,v $Revision 1.6 2003/04/14 15:51:37 eskimo1Use CFQAllocate/Deallocate to prevent "malloc(0) returns NULL" problems.Revision 1.5 2003/02/26 12:44:47 eskimo1Reworked the code used to implement MoreSCMakeNewDialupSet to support new features (MoreSCMakeNewPPPoESet) and the newly exported routine (MoreSCMakeNewSingleServiceSet).Revision 1.4 2002/11/25 16:54:58 eskimo1Correct error in MoreSCMakeNewDialupSet that was found by a developer tripping over an assert.Revision 1.3 2002/11/09 00:02:01 eskimo1Include our prototype early to flush out any missing dependencies. Convert nil to NULL. Convert MoreAssertQ to assert.Revision 1.2 2002/01/22 06:22:50 eskimo1Adapt to the new port scanner API.Revision 1.1 2002/01/16 22:52:31 eskimo1First checked in.*//////////////////////////////////////////////////////////////////// Our prototypes#include "MoreSCFHelpers.h"// System interfaces#include <SystemConfiguration/SystemConfiguration.h>// MIB Interfaces#include "MoreCFQ.h"#include "MoreSCF.h"#include "MoreSCFPortScanner.h"/////////////////////////////////////////////////////////////////#pragma mark ***** AppleTalk On/Offextern pascal OSStatus MoreSCIsAppleTalkActive(CFStringRef setID, Boolean *active) // See comment in header.{ OSStatus err; CFArrayRef serviceIDs; assert(active != NULL); *active = false; serviceIDs = NULL; // Open a connection to SCF, get a list of all of the set's // services, iterate through those services to see whether any // of their AppleTalk entities are active. err = MoreSCOpen(false, false); if (err == noErr) { err = MoreSCCopyServiceIDs(setID, &serviceIDs, NULL); } if (err == noErr) { CFIndex serviceCount; CFIndex serviceIndex; serviceCount = CFArrayGetCount(serviceIDs); serviceIndex = 0; while ( (err == noErr) && (serviceIndex < serviceCount) && !(*active) ) { CFStringRef thisService; Boolean isActive; thisService = (CFStringRef) CFArrayGetValueAtIndex(serviceIDs, serviceIndex); err = MoreSCIsServiceActive(setID, thisService, &isActive); if (err == noErr && isActive) { err = MoreSCIsEntityActive(setID, thisService, kSCEntNetAppleTalk, &isActive); if (err == noErr && isActive) { *active = true; } } serviceIndex += 1; } } MoreSCClose(&err, false); CFQRelease(serviceIDs); return err;}extern pascal OSStatus MoreSCSetAppleTalkActive(CFStringRef setID, Boolean active) // See comment in header.{ OSStatus err; CFArrayRef serviceIDs; Boolean madeChanges; serviceIDs = NULL; // Open a connection to SCF, get a list of all of the set's // services, iterate through those services to make their // AppleTalk entities active. madeChanges = false; err = MoreSCOpen(false, false); if (err == noErr) { err = MoreSCCopyServiceIDs(setID, &serviceIDs, NULL); } if (err == noErr) { CFIndex serviceCount; CFIndex serviceIndex; serviceCount = CFArrayGetCount(serviceIDs); for (serviceIndex = 0; serviceIndex < serviceCount; serviceIndex++) { CFStringRef thisService; Boolean entityIsActive; thisService = (CFStringRef) CFArrayGetValueAtIndex(serviceIDs, serviceIndex); // There may be no AppleTalk entity in this service (for example, // a PPP service), so we don't consider a failure to copy an error. if ( MoreSCIsEntityActive(setID, thisService, kSCEntNetAppleTalk, &entityIsActive) == noErr ) { if (entityIsActive != active) { err = MoreSCSetEntityActive(setID, thisService, kSCEntNetAppleTalk, active); if (err == noErr) { madeChanges = true; } } } if (err != noErr) { break; } } } MoreSCClose(&err, madeChanges); CFQRelease(serviceIDs); return err;}/////////////////////////////////////////////////////////////////#pragma mark ***** DHCP Releasestatic OSStatus IsSetupConfiguredToUseDHCP(SCDynamicStoreRef storeRef, CFStringRef configuredIPv4Key, Boolean *isDHCP) // Given a path to an IPv4 entity within the Setup: domain of the // dynamic store, sets *isDHCP to indicate whether the entity is // configured to use DHCP address acquisition. // // The input string is something like "Setup:/Network/Service/<serviceID>/IPv4".{ OSStatus err; CFDictionaryRef value; CFStringRef configMethod; assert(storeRef != NULL); assert(configuredIPv4Key != NULL); assert(isDHCP != NULL); value = NULL; // Get the value of the IPv4 entity, extract the "ConfigMethod" // property, and compare it to "DHCP". value = (CFDictionaryRef) SCDynamicStoreCopyValue(storeRef, configuredIPv4Key); err = MoreSCError( (void *) value ); if (err == noErr) { assert( CFGetTypeID(value) == CFDictionaryGetTypeID() ); if ( ! CFDictionaryGetValueIfPresent(value, kSCPropNetIPv4ConfigMethod, (const void **) &configMethod) ) { err = -2; } } if (err == noErr) { assert( CFGetTypeID(configMethod) == CFStringGetTypeID() ); *isDHCP = CFEqual(configMethod, kSCValNetIPv4ConfigMethodDHCP); } // Clean up. CFQRelease(value); return err;}static OSStatus AppendServiceIDForEachDHCPDynamicStoreKey(SCDynamicStoreRef storeRef, CFArrayRef configuredIPv4DynamicKeys, CFMutableArrayRef configuredDHCPServiceIDs) // Given an array of keys for configured IPv4 entities in the dynamic // store, and a created mutable array of strings, this routine appends a // service ID string to the output array for each element in // the input array whoses ConfigMethod property is DHCP. // // Input array elements look like "Setup:/Network/Service/<serviceID>/IPv4". // Output array elements look like: "<serviceID>".{ OSStatus err; CFIndex ipv4KeyCount; CFIndex keyIndex; assert(configuredIPv4DynamicKeys != NULL); assert(configuredDHCPServiceIDs != NULL); // Iterate over each element in the input array. ipv4KeyCount = CFArrayGetCount(configuredIPv4DynamicKeys); err = noErr; for (keyIndex = 0; keyIndex < ipv4KeyCount; keyIndex++) { CFStringRef thisKey; // got with "Get", so doesn't need to be released CFArrayRef thisKeyExploded; Boolean isDHCP; thisKeyExploded = NULL; // Get the keyIndex'th array element and assert that it looks like a // valid dynamic store key. thisKey = (CFStringRef) CFArrayGetValueAtIndex(configuredIPv4DynamicKeys, keyIndex); if (thisKey == NULL) { err = coreFoundationUnknownErr; } else { assert( CFGetTypeID(thisKey) == CFStringGetTypeID() ); } #if MORE_DEBUG if (err == noErr) { assert( CFStringHasPrefix(thisKey, CFSTR("Setup:/Network/Service/")) ); assert( CFStringHasSuffix(thisKey, CFSTR("/IPv4")) ); } #endif // Test to see whether we're interested in this element. if (err == noErr) { err = IsSetupConfiguredToUseDHCP(storeRef, thisKey, &isDHCP); } if (err == noErr && isDHCP) { // If we are, extract the service ID from the key and add it to // the output array. // Explode the key into it's component pieces (separated by "/"). This is, IMHO, // the easiest way to pull out the service ID part of the key (the "<serviceID>" in the // examples at the beginning of this routine). if (err == noErr) { thisKeyExploded = CFStringCreateArrayBySeparatingStrings(NULL, thisKey, CFSTR("/")); if (thisKeyExploded == NULL) { err = coreFoundationUnknownErr; } } // Add the service ID (the 3rd element of the exploded path) to the end of the results array. if (err == noErr) { assert( CFArrayGetCount(thisKeyExploded) == 5 ); assert( CFGetTypeID(CFArrayGetValueAtIndex(thisKeyExploded, 3)) == CFStringGetTypeID() ); CFArrayAppendValue(configuredDHCPServiceIDs, CFArrayGetValueAtIndex(thisKeyExploded, 3)); } } // Clean up once each time around the loop. CFQRelease(thisKeyExploded); if (err != noErr) { break; } } // for return err;}extern pascal OSStatus MoreSCCreateActiveDHCPServicesArray(CFArrayRef *activeDHCP) // See comment in header.{ OSStatus err; CFStringRef dhcpPattern; CFArrayRef configuredIPv4DynamicKeys; CFMutableArrayRef result; SCDynamicStoreRef storeRef; assert( activeDHCP != NULL); assert(*activeDHCP == NULL); dhcpPattern = NULL; configuredIPv4DynamicKeys = NULL; result = NULL; // Open a connection to the dynamic store. storeRef = SCDynamicStoreCreate(NULL, MoreSCGetClient(), NULL, NULL); err = MoreSCError( (void *) storeRef); if (err == noErr) { // Create dhcpPattern as "Setup:/Network/Service/[^/]+/IPv4". // SCDynamicStoreKeyCreateNetworkServiceEntity provides both // kSCCompNetwork ("Network") and kSCCompService ("Service"). // // We work in the Setup: domain not the state domain because // that's where we find the ConfigMethod = DHCP property. We // can't just search for DHCP entities (which is what I originally // implemented) because, if the interface is configured to use DHCP // but didn't find a server, it's assigned an autonet address // (169.x.x.x) but no DHCP entity is created. dhcpPattern = SCDynamicStoreKeyCreateNetworkServiceEntity( NULL, // allocator kSCDynamicStoreDomainSetup, // domain = "Setup:" kSCCompAnyRegex, // serviceID = "[^/]+" (1 or more non-slash chars) kSCEntNetIPv4); // entity = "IPv4" err = MoreSCError( (void *) dhcpPattern ); } // Find all the configured IPv4 entities in the dynamic store. if (err == noErr) { configuredIPv4DynamicKeys = SCDynamicStoreCopyKeyList(storeRef, dhcpPattern); err = MoreSCError( (void *) configuredIPv4DynamicKeys ); } // Create an array for the output results. if (err == noErr) { result = CFArrayCreateMutable(NULL, CFArrayGetCount(configuredIPv4DynamicKeys), &kCFTypeArrayCallBacks); if (result == NULL) { err = coreFoundationUnknownErr; } } // Walk through the list of IPv4 Setup entities looking for those with the // ConfigMethod = DHCP property. For each one you find, append the service ID // to the result list. if (err == noErr) { err = AppendServiceIDForEachDHCPDynamicStoreKey(storeRef, configuredIPv4DynamicKeys, result); } // Clean up. CFQRelease(dhcpPattern); CFQRelease(configuredIPv4DynamicKeys); if (err != noErr) { CFQRelease(result); result = NULL; } *activeDHCP = result; CFQRelease(storeRef); assert( (err == noErr) == (*activeDHCP != NULL) ); return err;}extern pascal OSStatus MoreSCDHCPRelease(CFStringRef serviceID) // See comment in header.{ OSStatus err; // Mark the entity inactive. err = MoreSCOpen(false, false); if (err == noErr) { err = MoreSCSetEntityActive(NULL, serviceID, kSCEntNetIPv4, false); } MoreSCClose(&err, true); // Mark the entity active. if (err == noErr) { err = MoreSCOpen(false, false); if (err == noErr) { err = MoreSCSetEntityActive(NULL, serviceID, kSCEntNetIPv4, true); } MoreSCClose(&err, true); } return err;}/////////////////////////////////////////////////////////////////#pragma mark ***** ISP APIsextern pascal OSStatus MoreSCFindSetByUserVisibleNameAndCopyID(CFStringRef userVisibleName, CFStringRef *setID) // See comment in header.{ OSStatus err; CFArrayRef setIDs; assert(userVisibleName != NULL); assert( setID != NULL); assert(*setID == NULL); setIDs = NULL; // Get an array of the set IDs, iterate over that array looking for // an element whose user-visible name matches. err = MoreSCCopySetIDs(&setIDs, NULL); if (err == noErr) { CFIndex setCount; CFIndex setIndex; setCount = CFArrayGetCount(setIDs); setIndex = 0; while ( (err == noErr) && (setIndex < setCount) && (*setID == NULL) ) { CFStringRef thisName; CFStringRef thisSet; thisSet = (CFStringRef) CFArrayGetValueAtIndex(setIDs, setIndex); thisName = NULL; err = MoreSCCopyUserVisibleNameOfSet(thisSet, &thisName); if (err == noErr) { if ( CFEqual(userVisibleName, thisName) ) { *setID = (CFStringRef) CFRetain(thisSet); } } if (err == noErr && *setID == NULL) { setIndex += 1; } CFQRelease(thisName); } } CFQRelease(setIDs); return err;}extern pascal OSStatus MoreSCFCopyDefaultPortBSDName(CFStringRef hardwareType, CFStringRef *bsdName) // See comment in header.{ OSStatus err; CFArrayRef portArray; assert( bsdName != NULL); assert(*bsdName == NULL); portArray = NULL; err = MoreSCCreatePortArray(&portArray); if (err == noErr) { CFIndex portCount; CFIndex portIndex; portCount = CFArrayGetCount(portArray); for (portIndex = 0; portIndex < portCount; portIndex++) { CFStringRef kind; kind = (CFStringRef) CFDictionaryGetValue( (CFDictionaryRef) CFArrayGetValueAtIndex(portArray, portIndex), kSCPropNetInterfaceHardware ); if ( CFEqual(kind, hardwareType) ) { *bsdName = (CFStringRef) CFRetain( CFDictionaryGetValue( (CFDictionaryRef) CFArrayGetValueAtIndex(portArray, portIndex), kSCPropNetInterfaceDeviceName) ); break; } } } CFQRelease(portArray); // The following isn't true. *bsdName can be NULL in the noErr // case if the port isn't found. // // assert( (err == noErr) == (*bsdName != NULL) ); return err;}extern pascal OSStatus MoreSCMakeNewSingleServiceSet( CFStringRef bsdName, CFStringRef userVisibleName, CFDictionaryRef serviceSettings, CFStringRef * newSetID) // See comment in header.{ OSStatus err; CFStringRef newSetIDLocal; CFArrayRef serviceIDs; CFStringRef * settingsKeys; CFDictionaryRef * settingsValues; CFIndex settingsIndex; CFIndex settingsCount; assert(bsdName != NULL); assert(userVisibleName != NULL); assert(serviceSettings != NULL); assert( (newSetID == NULL) || (*newSetID == NULL) ); newSetIDLocal = NULL; serviceIDs = NULL; settingsKeys = NULL; settingsValues = NULL; settingsCount = CFDictionaryGetCount(serviceSettings); // We open up a connection here to ensure that all of our // changes get committed at the end. err = MoreSCOpen(false, false); // Get the keys and values from the serviceSettings dictionary. if (err == noErr) { err = CFQAllocate(settingsCount * sizeof(*settingsKeys), (void **) &settingsKeys); if (err == noErr) { err = CFQAllocate(settingsCount * sizeof(*settingsValues), (void **) &settingsValues); } } if (err == noErr) { CFDictionaryGetKeysAndValues(serviceSettings, (const void **) settingsKeys, (const void **) settingsValues); } // Create a set and get the list of service IDs. if (err == noErr) { err = MoreSCNewSet(userVisibleName, &newSetIDLocal); } if (err == noErr) { err = MoreSCCopyServiceIDs(newSetIDLocal, &serviceIDs, NULL); } if (err == noErr) { CFIndex serviceCount; CFIndex serviceIndex; // Loop through every service in the new set. If the service's // BSD name matches the port we're configuring, overwrite the // service's entities with ones created from our settings. // For non-matching services, just disable the service. serviceCount = CFArrayGetCount(serviceIDs); for (serviceIndex = 0; serviceIndex < serviceCount; serviceIndex++) { CFStringRef thisService; CFStringRef thisServiceBSDName; thisServiceBSDName = NULL; thisService = (CFStringRef) CFArrayGetValueAtIndex(serviceIDs, serviceIndex); err = MoreSCCopyBSDNameOfService(newSetIDLocal, thisService, &thisServiceBSDName); if (err == noErr) { if ( CFEqual(bsdName, thisServiceBSDName) ) { for (settingsIndex = 0; settingsIndex < settingsCount; settingsIndex++) { // Now we encounter a slight hack. If the entity we're setting up // is kSCEntNetInterface, we merge the settings into the entity. // Otherwise we overwrite them entirely. This is required because // the PPPoE setup (MoreSCMakeNewPPPoESet) needs to be able to // modify some keys in the kSCEntNetInterface entity, but it // doesn't know all of the existing values so it can't do the // merge itself. if ( CFEqual(settingsKeys[settingsIndex], kSCEntNetInterface) ) { CFMutableDictionaryRef entityDict; entityDict = NULL; err = MoreSCCopyEntityMutable(newSetIDLocal, thisService, settingsKeys[settingsIndex], &entityDict); if (err == noErr) { err = CFQDictionaryMerge(entityDict, settingsValues[settingsIndex]); } if (err == noErr) { err = MoreSCSetEntity(newSetIDLocal, thisService, settingsKeys[settingsIndex], entityDict); } CFQRelease(entityDict); } else { err = MoreSCSetEntity(newSetIDLocal, thisService, settingsKeys[settingsIndex], settingsValues[settingsIndex]); } if (err != noErr) { break; } } } else { err = MoreSCSetServiceActive(newSetIDLocal, thisService, false); } } CFQRelease(thisServiceBSDName); if (err != noErr) { break; } } } if (err != noErr) { // On error, delete any partially created set. if (newSetIDLocal != NULL) { (void) MoreSCDeleteSet(newSetIDLocal); CFRelease(newSetIDLocal); newSetIDLocal = NULL; } } MoreSCClose(&err, true); // Clean up. // If we got an error during the MoreSCClose (which might happen // if we have bad privs), make sure we return a NULL set ID. Note that // this somewhat duplicates the results of the code around MoreSCDeleteSet // above, but it actually handles a distinct case where we have no error // up to the MoreSCClose but then MoreSCClose fails. if (err != noErr) { CFQRelease(newSetIDLocal); newSetIDLocal = NULL; } CFQRelease(serviceIDs); if (newSetID != NULL) { *newSetID = newSetIDLocal; } else { CFQRelease(newSetIDLocal); } CFQDeallocate(settingsKeys); CFQDeallocate(settingsValues); assert( (err == noErr) == ( (newSetID == NULL) || (*newSetID != NULL) ) ); return err;}static OSStatus SetupEntity(CFMutableDictionaryRef settings, CFStringRef protocol, const MoreSCDigest *digest) // Given all of the information required to set up an entity // (its set, its service within that set, and its protocol // (ie entity type), and a digest of the value we want), // this routine sets up the entity. // // digest can be NULL, in which case this routine sets // the entity to have a default value.{ OSStatus err; MoreSCDigest digestLocal; CFDictionaryRef entityDict; assert(settings != NULL); assert(protocol != NULL); entityDict = NULL; // If we didn't get a digest, create a default one // (all zeroes). if (digest == NULL) { BlockZero(&digestLocal, sizeof(digestLocal)); digest = &digestLocal; } // Create an entity dictionary from the digest and put // it into the settings dictionary. err = MoreSCCreateEntity(protocol, digest, &entityDict); if (err == noErr) { CFDictionaryAddValue(settings, protocol, entityDict); } CFQRelease(entityDict); return err;}extern pascal OSStatus MoreSCMakeNewDialupSet( CFStringRef bsdName, CFStringRef userVisibleName, const MoreSCModemDigest * modemSettings, const MoreSCPPPDigest * pppSettings, const MoreSCIPv4Digest * ipv4Settings, const MoreSCDNSDigest * dnsSettings, CFStringRef * newSetID) // See comment in header.{ OSStatus err; CFStringRef portName; CFMutableDictionaryRef settings; assert(userVisibleName != NULL); assert(pppSettings != NULL); assert(pppSettings->active); assert( (newSetID == NULL) || (*newSetID == NULL) ); portName = NULL; settings = NULL; // Find the appropriate BSD port name. if (bsdName == NULL) { err = MoreSCFCopyDefaultPortBSDName(kSCEntNetModem, &portName); } else { portName = (CFStringRef) CFRetain(bsdName); err = noErr; } if (err == noErr && portName == NULL) {// assert(false); // You supplied a BSD name that doesn't exist. err = paramErr; // Or you supplied NULL and there is no default port. } // Create the settings dictionary for dialup. This is easy because the // defaults work out well. if (err == noErr) { err = CFQDictionaryCreateMutable(&settings); } if (err == noErr) { err = SetupEntity(settings, kSCEntNetPPP, (MoreSCDigest *) pppSettings); } if (err == noErr && modemSettings != NULL) { err = SetupEntity(settings, kSCEntNetModem, (MoreSCDigest *) modemSettings); } if (err == noErr && ipv4Settings != NULL) { err = SetupEntity(settings, kSCEntNetIPv4, (MoreSCDigest *) ipv4Settings); } if (err == noErr && dnsSettings != NULL) { err = SetupEntity(settings, kSCEntNetDNS, (MoreSCDigest *) dnsSettings); } // Create the set using our helper routine. if (err == noErr) { err = MoreSCMakeNewSingleServiceSet(portName, userVisibleName, settings, newSetID); } CFQRelease(portName); CFQRelease(settings); assert( (err == noErr) == ( (newSetID == NULL) || (*newSetID != NULL) ) ); return err;}extern pascal OSStatus MoreSCMakeNewPPPoESet( CFStringRef bsdName, CFStringRef userVisibleName, const MoreSCPPPDigest * pppSettings, const MoreSCIPv4Digest * ipv4Settings, const MoreSCDNSDigest * dnsSettings, CFStringRef * newSetID){ OSStatus err; CFStringRef portName; CFMutableDictionaryRef settings; assert(userVisibleName != NULL); assert(pppSettings != NULL); assert(pppSettings->active); assert( (newSetID == NULL) || (*newSetID == NULL) ); portName = NULL; settings = NULL; // Find the appropriate BSD port name. if (bsdName == NULL) { err = MoreSCFCopyDefaultPortBSDName(kSCEntNetEthernet, &portName); } else { portName = (CFStringRef) CFRetain(bsdName); err = noErr; } if (err == noErr && portName == NULL) {// assert(false); // You supplied a BSD name that doesn't exist. err = paramErr; // Or you supplied NULL and there is no default port. } // Create the settings dictionary for PPPoE. This is somewhat trickier than // dialup because the defaults aren't in our favour. if (err == noErr) { err = CFQDictionaryCreateMutable(&settings); } if (err == noErr) { err = SetupEntity(settings, kSCEntNetPPP, (MoreSCDigest *) pppSettings); } if (err == noErr) { MoreSCIPv4Digest ipv4SettingsLocal; // The default settings for IPv4 on Ethernet are to use DHCP. In // the PPPoE case we must use PPP as the default. if (ipv4Settings == NULL) { ipv4Settings = &ipv4SettingsLocal; BlockZero(&ipv4SettingsLocal, sizeof(ipv4SettingsLocal)); ipv4SettingsLocal.configMethod = kSCValNetIPv4ConfigMethodPPP; } err = SetupEntity(settings, kSCEntNetIPv4, (MoreSCDigest *) ipv4Settings); } if (err == noErr && dnsSettings != NULL) { err = SetupEntity(settings, kSCEntNetDNS, (MoreSCDigest *) dnsSettings); } if (err == noErr) { CFDictionaryRef entityDict; CFStringRef keys[2]; CFStringRef values[2]; keys[0] = kSCPropNetInterfaceType; values[0] = kSCValNetInterfaceTypePPP; keys[1] = kSCPropNetInterfaceSubType; values[1] = kSCValNetInterfaceSubTypePPPoE; entityDict = CFDictionaryCreate(NULL, (const void **) keys, (const void **) values, 2, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); if (entityDict == NULL) { err = coreFoundationUnknownErr; } if (err == noErr) { CFDictionaryAddValue(settings, kSCEntNetInterface, entityDict); } CFQRelease(entityDict); } // Create the set using our helper routine. if (err == noErr) { err = MoreSCMakeNewSingleServiceSet(portName, userVisibleName, settings, newSetID); } CFQRelease(portName); CFQRelease(settings); assert( (err == noErr) == ( (newSetID == NULL) || (*newSetID != NULL) ) ); return err;}</pre>
<!--googleoff: index -->
</td>
</tr>
</table>
<!-- END WIDE COLUMN -->
<!-- END MAIN CONTENT -->
<table width="680" border="0" cellpadding="0" cellspacing="0">
<tr>
<td><div style="width: 100%; height: 1px; background-color: #919699; margin-top: 5px; margin-bottom: 15px"></div></td>
</tr>
<tr>
<td align="center"><br/>
<table border="0" cellpadding="0" cellspacing="0" class="graybox">
<tr>
<th>Did this document help you?</th>
</tr>
<tr>
<td>
<div style="margin-bottom: 8px"><a href="http://developer.apple.com/feedback/?v=1&url=/samplecode/QISA/listing34.html%3Fid%3DDTS10000714-1.0&media=dvd" target=_new>Yes</a>: Tell us what works for you.</div>
<div style="margin-bottom: 8px"><a href="http://developer.apple.com/feedback/?v=2&url=/samplecode/QISA/listing34.html%3Fid%3DDTS10000714-1.0&media=dvd" target=_new>It’s good, but:</a> Report typos, inaccuracies, and so forth.</div>
<div><a href="http://developer.apple.com/feedback/?v=3&url=/samplecode/QISA/listing34.html%3Fid%3DDTS10000714-1.0&media=dvd" target=_new>It wasn’t helpful</a>: Tell us what would have helped.</div>
</td>
</tr>
</table>
</td>
</tr>
</table>
<!-- START BOTTOM APPLE NAVIGATION -->
<!--#include virtual="/includes/footer"-->
<!-- END BOTTOM APPLE NAVIGATION -->
<!-- START CENTER CLOSE -->
</center>
<!-- END CENTER CLOSE -->
</body>
</html>