2 * Copyright (c) 2013, 2015 Apple Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
26 * - test harness to test IPMonitorControl client and server
30 * Modification History
32 * December 16, 2013 Dieter Siegmund (dieter@apple.com)
37 #include <CoreFoundation/CoreFoundation.h>
38 #include <SystemConfiguration/SCPrivate.h>
40 #include "IPMonitorControl.h"
41 #include "IPMonitorControlServer.h"
42 #include "symbol_scope.h"
45 AssertionsChanged(void * info
)
47 CFDictionaryRef assertions
= NULL
;
50 changes
= IPMonitorControlServerCopyInterfaceRankInformation(&assertions
);
51 SCPrint(TRUE
, stdout
, CFSTR("Changed interfaces %@\n"), changes
);
52 if (assertions
== NULL
) {
53 SCPrint(TRUE
, stdout
, CFSTR("No assertions\n"));
56 SCPrint(TRUE
, stdout
, CFSTR("Assertions = %@\n"), assertions
);
57 CFRelease(assertions
);
59 if (changes
!= NULL
) {
66 main(int argc
, char * argv
[])
70 IPMonitorControlRef control
;
71 SCNetworkServicePrimaryRank rank
;
72 Boolean rank_set
= FALSE
;
75 rank
= kSCNetworkServicePrimaryRankDefault
;
76 control
= IPMonitorControlCreate();
77 if (control
== NULL
) {
78 fprintf(stderr
, "failed to allocate IPMonitorControl\n");
82 while ((ch
= getopt(argc
, argv
, "i:r:w")) != EOF
) {
84 SCNetworkServicePrimaryRank existing_rank
;
88 ifname
= CFStringCreateWithCString(NULL
, optarg
,
89 kCFStringEncodingUTF8
);
90 existing_rank
= IPMonitorControlGetInterfacePrimaryRank(control
,
92 printf("%s rank was %u\n", optarg
, existing_rank
);
93 if (IPMonitorControlSetInterfacePrimaryRank(control
,
96 printf("%s rank set to %u\n", optarg
, rank
);
100 fprintf(stderr
, "failed to set rank\n");
105 rank
= strtoul(optarg
, NULL
, 0);
111 fprintf(stderr
, "unexpected option '%c'\n", (char)ch
);
119 fprintf(stderr
, "ignoring additional parameters\n");
129 CFRunLoopSourceContext context
;
130 CFRunLoopSourceRef rls
;
131 STATIC Boolean verbose
= TRUE
;
133 bzero(&context
, sizeof(context
));
134 context
.info
= (void *)NULL
;
135 context
.perform
= AssertionsChanged
;
136 rls
= CFRunLoopSourceCreate(NULL
, 0, &context
);
137 CFRunLoopAddSource(CFRunLoopGetCurrent(), rls
,
138 kCFRunLoopDefaultMode
);
139 if (!IPMonitorControlServerStart(CFRunLoopGetCurrent(), rls
, &verbose
)) {
140 fprintf(stderr
, "failed to create connection\n");