2 * Copyright (c) 2013 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
;
74 rank
= kSCNetworkServicePrimaryRankDefault
;
75 control
= IPMonitorControlCreate();
76 if (control
== NULL
) {
77 fprintf(stderr
, "failed to allocate IPMonitorControl\n");
81 while ((ch
= getopt(argc
, argv
, "i:r:")) != EOF
) {
83 SCNetworkServicePrimaryRank existing_rank
;
87 ifname
= CFStringCreateWithCString(NULL
, optarg
,
88 kCFStringEncodingUTF8
);
89 existing_rank
= IPMonitorControlGetInterfacePrimaryRank(control
,
91 printf("%s rank was %u\n", optarg
, existing_rank
);
92 if (IPMonitorControlSetInterfacePrimaryRank(control
,
95 printf("%s rank set to %u\n", optarg
, rank
);
99 fprintf(stderr
, "failed to set rank\n");
104 rank
= strtoul(optarg
, NULL
, 0);
107 fprintf(stderr
, "unexpected option '%c'\n", (char)ch
);
115 fprintf(stderr
, "ignoring additional parameters\n");
117 if (rank_set
== FALSE
) {
122 CFRunLoopSourceContext context
;
123 CFRunLoopSourceRef rls
;
124 STATIC Boolean verbose
= TRUE
;
126 bzero(&context
, sizeof(context
));
127 context
.info
= (void *)NULL
;
128 context
.perform
= AssertionsChanged
;
129 rls
= CFRunLoopSourceCreate(NULL
, 0, &context
);
130 CFRunLoopAddSource(CFRunLoopGetCurrent(), rls
,
131 kCFRunLoopDefaultMode
);
132 if (IPMonitorControlServerStart(CFRunLoopGetCurrent(), rls
,
133 &verbose
) == FALSE
) {
134 fprintf(stderr
, "failed to create connection\n");