2 * Copyright (c) 2004-2010, 2013, 2014, 2016, 2017 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@
25 * Modification History
27 * August 5, 2004 Allan Nathanson <ajn@apple.com>
34 #include "net_service.h"
35 #include "net_interface.h"
36 #include "net_protocol.h"
40 /* -------------------- */
43 static SCNetworkServiceRef
44 _find_service(char *match
)
46 Boolean allowIndex
= TRUE
;
49 CFStringRef select_name
= NULL
;
50 SCNetworkServiceRef selected
= NULL
;
52 if (services
== NULL
) {
53 if (net_set
== NULL
) {
54 SCPrint(TRUE
, stdout
, CFSTR("set not selected\n"));
58 services
= SCNetworkSetCopyServices(net_set
);
59 if (services
== NULL
) {
60 SCPrint(TRUE
, stdout
, CFSTR("%s\n"), SCErrorString(SCError()));
67 // try to select the service by its serviceID
69 select_name
= CFStringCreateWithCString(NULL
, match
, kCFStringEncodingUTF8
);
71 n
= CFArrayGetCount(services
);
72 for (i
= 0; i
< n
; i
++) {
73 SCNetworkServiceRef service
;
74 CFStringRef serviceID
;
76 service
= CFArrayGetValueAtIndex(services
, i
);
77 serviceID
= SCNetworkServiceGetServiceID(service
);
78 if (CFEqual(select_name
, serviceID
)) {
84 // try to select the service by its name
86 for (i
= 0; i
< n
; i
++) {
87 SCNetworkServiceRef service
;
88 CFStringRef serviceName
;
90 service
= CFArrayGetValueAtIndex(services
, i
);
91 serviceName
= SCNetworkServiceGetName(service
);
92 if ((serviceName
!= NULL
) && CFEqual(select_name
, serviceName
)) {
93 if (selected
== NULL
) {
96 // if multiple services match
98 SCPrint(TRUE
, stdout
, CFSTR("multiple services match\n"));
104 if (selected
!= NULL
) {
108 // try to select the service by its name (case insensitive)
110 for (i
= 0; i
< n
; i
++) {
111 SCNetworkServiceRef service
;
112 CFStringRef serviceName
;
114 service
= CFArrayGetValueAtIndex(services
, i
);
115 serviceName
= SCNetworkServiceGetName(service
);
116 if ((serviceName
!= NULL
) &&
117 CFStringCompare(select_name
,
119 kCFCompareCaseInsensitive
) == kCFCompareEqualTo
) {
120 if (selected
== NULL
) {
123 // if multiple services match
125 SCPrint(TRUE
, stdout
, CFSTR("multiple services match\n"));
131 if (selected
!= NULL
) {
135 // try to select the service by its [BSD] interface name
137 for (i
= 0; i
< n
; i
++) {
138 SCNetworkInterfaceRef interface
;
139 CFStringRef interfaceName
= NULL
;
140 SCNetworkServiceRef service
;
142 service
= CFArrayGetValueAtIndex(services
, i
);
144 interface
= SCNetworkServiceGetInterface(service
);
145 while ((interface
!= NULL
) && (interfaceName
== NULL
)) {
146 interfaceName
= SCNetworkInterfaceGetBSDName(interface
);
147 if (interfaceName
== NULL
) {
148 interface
= SCNetworkInterfaceGetInterface(interface
);
152 if (interfaceName
== NULL
) {
156 if (CFStringCompare(select_name
,
158 kCFCompareCaseInsensitive
) == kCFCompareEqualTo
) {
159 if (selected
== NULL
) {
162 // if multiple services match
164 SCPrint(TRUE
, stdout
, CFSTR("multiple services match\n"));
170 if (selected
!= NULL
) {
174 // try to select the service by its index
182 val
= strtol(str
, &end
, 10);
183 if ((*str
!= '\0') && (*end
== '\0') && (errno
== 0)) {
184 if ((val
> 0) && (val
<= n
)) {
185 selected
= CFArrayGetValueAtIndex(services
, val
- 1);
190 if (selected
!= NULL
) {
194 SCPrint(TRUE
, stdout
, CFSTR("no match, which service?\n"));
198 if (select_name
!= NULL
) CFRelease(select_name
);
203 /* -------------------- */
208 create_service(int argc
, char **argv
)
210 SCNetworkInterfaceRef interface
;
211 CFStringRef interfaceName
;
213 SCNetworkServiceRef service
= NULL
;
214 CFStringRef serviceName
;
216 CFArrayRef supported
;
219 SCPrint(TRUE
, stdout
, CFSTR("network configuration not open\n"));
223 if (net_set
== NULL
) {
224 SCPrint(TRUE
, stdout
, CFSTR("set not selected\n"));
229 if (net_interface
== NULL
) {
230 SCPrint(TRUE
, stdout
, CFSTR("no network interface selected\n"));
234 interface
= net_interface
;
238 interface
= _find_interface(argc
, argv
, &nArgs
);
243 if (interface
== NULL
) {
247 supported
= SCNetworkInterfaceGetSupportedProtocolTypes(interface
);
248 if (supported
== NULL
) {
249 SCPrint(TRUE
, stdout
, CFSTR("no network protocols are supported over this interface\n"));
253 service
= SCNetworkServiceCreate(prefs
, interface
);
254 if (service
== NULL
) {
255 SCPrint(TRUE
, stdout
, CFSTR("%s\n"), SCErrorString(SCError()));
259 if ((argc
> 0) && (strlen(argv
[0]) > 0)) {
262 serviceName
= CFStringCreateWithCString(NULL
, argv
[0], kCFStringEncodingUTF8
);
266 ok
= SCNetworkServiceSetName(service
, serviceName
);
267 CFRelease(serviceName
);
269 SCPrint(TRUE
, stdout
, CFSTR("%s\n"), SCErrorString(SCError()));
270 (void)SCNetworkServiceRemove(service
);
275 ok
= SCNetworkServiceEstablishDefaultConfiguration(service
);
277 SCPrint(TRUE
, stdout
, CFSTR("%s\n"), SCErrorString(SCError()));
278 (void)SCNetworkServiceRemove(service
);
282 ok
= SCNetworkSetAddService(net_set
, service
);
284 SCPrint(TRUE
, stdout
, CFSTR("service not created: %s\n"), SCErrorString(SCError()));
285 (void)SCNetworkServiceRemove(service
);
289 _prefs_changed
= TRUE
;
291 if (net_service
!= NULL
) CFRelease(net_service
);
292 net_service
= CFRetain(service
);
294 serviceName
= SCNetworkServiceGetName(service
);
295 if (serviceName
!= NULL
) {
296 SCPrint(TRUE
, stdout
,
297 CFSTR("service \"%@\" (%@) created and selected\n"),
299 SCNetworkServiceGetServiceID(service
));
301 SCPrint(TRUE
, stdout
,
302 CFSTR("service ID \"%@\" created and selected\n"),
303 SCNetworkServiceGetServiceID(service
));
306 setName
= SCNetworkSetGetName(net_set
);
307 if (setName
!= NULL
) {
308 SCPrint(TRUE
, stdout
, CFSTR("& added to set \"%@\"\n"), setName
);
310 SCPrint(TRUE
, stdout
, CFSTR("& added to set ID \"%@\"\n"),
311 SCNetworkSetGetSetID(net_set
));
314 if (net_interface
!= NULL
) CFRelease(net_interface
);
315 net_interface
= SCNetworkServiceGetInterface(net_service
);
316 if (net_interface
!= NULL
) {
317 CFRetain(net_interface
);
320 interfaceName
= SCNetworkInterfaceGetLocalizedDisplayName(interface
);
321 if (interfaceName
== NULL
) {
322 interfaceName
= SCNetworkInterfaceGetBSDName(interface
);
324 if (interfaceName
== NULL
) {
325 interfaceName
= SCNetworkInterfaceGetInterfaceType(interface
);
328 SCPrint(TRUE
, stdout
,
329 CFSTR("& interface \"%@\" selected\n"),
332 if (protocols
!= NULL
) {
333 CFRelease(protocols
);
337 if (net_protocol
!= NULL
) {
338 CFRelease(net_protocol
);
340 SCPrint(TRUE
, stdout
, CFSTR("& no protocol selected\n"));
343 if (services
!= NULL
) {
350 if (service
!= NULL
) CFRelease(service
);
357 disable_service(int argc
, char **argv
)
359 SCNetworkServiceRef service
;
362 service
= _find_service(argv
[0]);
364 if (net_service
!= NULL
) {
365 service
= net_service
;
367 SCPrint(TRUE
, stdout
, CFSTR("service not selected\n"));
372 if (service
== NULL
) {
376 if (!SCNetworkServiceSetEnabled(service
, FALSE
)) {
377 SCPrint(TRUE
, stdout
, CFSTR("%s\n"), SCErrorString(SCError()));
381 _prefs_changed
= TRUE
;
388 enable_service(int argc
, char **argv
)
390 SCNetworkServiceRef service
;
393 service
= _find_service(argv
[0]);
395 if (net_service
!= NULL
) {
396 service
= net_service
;
398 SCPrint(TRUE
, stdout
, CFSTR("service not selected\n"));
403 if (service
== NULL
) {
407 if (!SCNetworkServiceSetEnabled(service
, TRUE
)) {
408 SCPrint(TRUE
, stdout
, CFSTR("%s\n"), SCErrorString(SCError()));
412 _prefs_changed
= TRUE
;
419 remove_service(int argc
, char **argv
)
421 SCNetworkServiceRef service
= NULL
;
422 CFStringRef serviceName
;
425 service
= _find_service(argv
[0]);
427 if (net_service
!= NULL
) {
428 service
= net_service
;
432 if (service
== NULL
) {
438 if (!SCNetworkServiceRemove(service
)) {
439 SCPrint(TRUE
, stdout
, CFSTR("%s\n"), SCErrorString(SCError()));
443 _prefs_changed
= TRUE
;
445 serviceName
= SCNetworkServiceGetName(service
);
446 if (serviceName
!= NULL
) {
447 SCPrint(TRUE
, stdout
, CFSTR("service \"%@\" removed\n"), serviceName
);
449 SCPrint(TRUE
, stdout
,
450 CFSTR("service ID \"%@\" removed\n"),
451 SCNetworkServiceGetServiceID(service
));
454 if ((net_service
!= NULL
) && CFEqual(service
, net_service
)) {
455 CFRelease(net_service
);
457 SCPrint(TRUE
, stdout
, CFSTR("& no service selected\n"));
459 if (protocols
!= NULL
) {
460 CFRelease(protocols
);
464 if (net_protocol
!= NULL
) {
465 CFRelease(net_protocol
);
467 SCPrint(TRUE
, stdout
, CFSTR("& no protocol selected\n"));
470 if (net_interface
!= NULL
) {
471 CFRelease(net_interface
);
472 net_interface
= NULL
;
473 SCPrint(TRUE
, stdout
, CFSTR("& no interface selected\n"));
477 if (services
!= NULL
) {
491 select_service(int argc
, char **argv
)
494 SCNetworkInterfaceRef interface
;
495 SCNetworkServiceRef service
;
496 CFStringRef serviceName
;
498 service
= _find_service(argv
[0]);
500 if (service
== NULL
) {
504 if (net_service
!= NULL
) CFRelease(net_service
);
505 net_service
= CFRetain(service
);
507 serviceName
= SCNetworkServiceGetName(service
);
508 if (serviceName
!= NULL
) {
509 SCPrint(TRUE
, stdout
, CFSTR("service \"%@\" selected\n"), serviceName
);
511 SCPrint(TRUE
, stdout
,
512 CFSTR("service ID \"%@\" selected\n"),
513 SCNetworkServiceGetServiceID(service
));
516 interface
= SCNetworkServiceGetInterface(service
);
517 if (interface
!= NULL
) {
518 CFStringRef interfaceName
;
520 if (net_interface
!= NULL
) CFRelease(net_interface
);
521 net_interface
= CFRetain(interface
);
523 interfaceName
= SCNetworkInterfaceGetLocalizedDisplayName(interface
);
524 if (interfaceName
== NULL
) {
525 interfaceName
= SCNetworkInterfaceGetBSDName(interface
);
527 if (interfaceName
== NULL
) {
528 interfaceName
= SCNetworkInterfaceGetInterfaceType(interface
);
531 SCPrint(TRUE
, stdout
,
532 CFSTR("& interface \"%@\" selected\n"),
535 if (net_interface
!= NULL
) {
536 CFRelease(net_interface
);
537 net_interface
= NULL
;
538 SCPrint(TRUE
, stdout
, CFSTR("& no interface selected\n"));
542 if (protocols
!= NULL
) {
543 CFRelease(protocols
);
547 if (net_protocol
!= NULL
) {
548 CFRelease(net_protocol
);
550 SCPrint(TRUE
, stdout
, CFSTR("& no protocol selected\n"));
559 set_service(int argc
, char **argv
)
563 if (net_service
== NULL
) {
564 SCPrint(TRUE
, stdout
, CFSTR("service not selected\n"));
569 SCPrint(TRUE
, stdout
, CFSTR("set what?\n"));
580 if (strcmp(command
, "name") == 0) {
581 CFStringRef serviceName
;
584 SCPrint(TRUE
, stdout
, CFSTR("name not specified\n"));
588 serviceName
= (strlen(argv
[0]) > 0)
589 ? CFStringCreateWithCString(NULL
, argv
[0], kCFStringEncodingUTF8
)
594 ok
= SCNetworkServiceSetName(net_service
, serviceName
);
595 if (serviceName
!= NULL
) CFRelease(serviceName
);
597 SCPrint(TRUE
, stdout
, CFSTR("%s\n"), SCErrorString(SCError()));
601 _prefs_changed
= TRUE
;
602 } else if (strcmp(command
, "order") == 0) {
610 services
= SCNetworkSetCopyServices(net_set
);
611 nServices
= CFArrayGetCount(services
);
615 SCPrint(TRUE
, stdout
, CFSTR("order not specified\n"));
619 if (net_set
== NULL
) {
620 SCPrint(TRUE
, stdout
, CFSTR("set not selected\n"));
629 newIndex
= strtol(str
, &end
, 10);
630 if ((*str
!= '\0') && (*end
== '\0') && (errno
== 0)) {
631 if ((newIndex
> 0) && (newIndex
<= nServices
)) {
633 CFMutableArrayRef newOrder
;
635 CFStringRef serviceID
= SCNetworkServiceGetServiceID(net_service
);
637 order
= SCNetworkSetGetServiceOrder(net_set
);
639 newOrder
= CFArrayCreateMutable(NULL
, 0, &kCFTypeArrayCallBacks
);
641 newOrder
= CFArrayCreateMutableCopy(NULL
, 0, order
);
644 curIndex
= CFArrayGetFirstIndexOfValue(newOrder
,
645 CFRangeMake(0, CFArrayGetCount(newOrder
)),
647 if (curIndex
!= kCFNotFound
) {
648 CFArrayRemoveValueAtIndex(newOrder
, curIndex
);
651 if (newIndex
<= CFArrayGetCount(newOrder
)) {
652 CFArrayInsertValueAtIndex(newOrder
, newIndex
- 1, serviceID
);
654 CFArrayAppendValue(newOrder
, serviceID
);
657 ok
= SCNetworkSetSetServiceOrder(net_set
, newOrder
);
660 SCPrint(TRUE
, stdout
, CFSTR("%s\n"), SCErrorString(SCError()));
664 _prefs_changed
= TRUE
;
666 SCPrint(TRUE
, stdout
, CFSTR("set order to what?\n"));
670 SCPrint(TRUE
, stdout
, CFSTR("set what?\n"));
673 } else if (strcmp(command
, "rank") == 0) {
674 SCNetworkServicePrimaryRank rank
= kSCNetworkServicePrimaryRankDefault
;
675 SCNetworkServiceRef service
= (argc
< 2) ? net_service
: NULL
;
676 Boolean useActive
= FALSE
;
679 SCPrint(TRUE
, stdout
, CFSTR("rank not specified\n"));
683 if (strlen(argv
[0]) > 0) {
684 if (strcasecmp(argv
[0], "Never") == 0) {
685 rank
= kSCNetworkServicePrimaryRankNever
;
686 } else if ((service
!= net_service
) && (strcasecmp(argv
[0], "First") == 0)) {
687 rank
= kSCNetworkServicePrimaryRankFirst
;
688 } else if ((service
!= net_service
) && (strcasecmp(argv
[0], "Last") == 0)) {
689 rank
= kSCNetworkServicePrimaryRankLast
;
690 } else if ((service
!= net_service
) && (strcasecmp(argv
[0], "Scoped") == 0)) {
691 rank
= kSCNetworkServicePrimaryRankScoped
;
693 SCPrint(TRUE
, stdout
, CFSTR("rank not valid\n"));
700 if (service
== NULL
) {
701 CFStringRef serviceID
;
702 SCDynamicStoreRef store
;
704 store
= SCDynamicStoreCreate(NULL
,
705 CFSTR("scutil (set primary rank)"),
708 serviceID
= SCNetworkServiceGetServiceID(net_service
);
709 service
= _SCNetworkServiceCopyActive(store
, serviceID
);
717 ok
= SCNetworkServiceSetPrimaryRank(service
, rank
);
721 _prefs_changed
= TRUE
;
724 SCPrint(TRUE
, stdout
, CFSTR("%s\n"), SCErrorString(SCError()));
727 } else if (strcmp(command
, "id") == 0) {
728 CFStringRef serviceID
;
730 if ((argc
< 1) || (strlen(argv
[0]) == 0)) {
731 SCPrint(TRUE
, stdout
, CFSTR("set id not specified\n"));
735 serviceID
= CFStringCreateWithCString(NULL
, argv
[0], kCFStringEncodingUTF8
);
739 ok
= _SCNetworkServiceSetServiceID(net_service
, serviceID
);
740 CFRelease(serviceID
);
742 SCPrint(TRUE
, stdout
, CFSTR("%s\n"), SCErrorString(SCError()));
746 _prefs_changed
= TRUE
;
748 SCPrint(TRUE
, stdout
, CFSTR("set what?\n"));
757 __show_service_interface(SCNetworkServiceRef service
, const char *prefix
)
759 CFStringRef description
;
760 SCNetworkInterfaceRef interface
;
762 interface
= SCNetworkServiceGetInterface(service
);
763 if (interface
== NULL
) {
767 description
= _interface_description(interface
);
768 SCPrint(TRUE
, stdout
, CFSTR("%s%@\n"), prefix
, description
);
769 CFRelease(description
);
775 __show_service_protocols(SCNetworkServiceRef service
, const char *prefix
, Boolean skipEmpty
)
779 CFArrayRef protocols
;
781 protocols
= SCNetworkServiceCopyProtocols(service
);
782 if (protocols
== NULL
) {
786 n
= CFArrayGetCount(protocols
);
788 CFMutableArrayRef sorted
;
790 sorted
= CFArrayCreateMutableCopy(NULL
, 0, protocols
);
791 CFArraySortValues(sorted
,
793 _SCNetworkProtocolCompare
,
795 CFRelease(protocols
);
799 for (i
= 0; i
< n
; i
++) {
800 CFStringRef description
;
801 SCNetworkProtocolRef protocol
;
803 protocol
= CFArrayGetValueAtIndex(protocols
, i
);
804 description
= _protocol_description(protocol
, skipEmpty
);
805 if (description
!= NULL
) {
806 CFStringRef protocolType
;
808 protocolType
= SCNetworkProtocolGetProtocolType(protocol
);
809 SCPrint(TRUE
, stdout
,
810 CFSTR("%s%@%*s : %@\n"),
813 (int)(sizeof("Interface") - CFStringGetLength(protocolType
) - 1),
816 CFRelease(description
);
820 CFRelease(protocols
);
827 show_service(int argc
, char **argv
)
829 SCNetworkInterfaceRef interface
;
830 CFArrayRef protocols
;
831 SCNetworkServiceRef service
;
832 CFStringRef serviceName
;
833 SCNetworkServicePrimaryRank serviceRank
;
836 service
= _find_service(argv
[0]);
838 if (net_service
!= NULL
) {
839 service
= net_service
;
841 SCPrint(TRUE
, stdout
, CFSTR("service not selected\n"));
846 if (service
== NULL
) {
850 SCPrint(TRUE
, stdout
, CFSTR("service id = %@\n"), SCNetworkServiceGetServiceID(service
));
852 serviceName
= SCNetworkServiceGetName(service
);
853 SCPrint(TRUE
, stdout
, CFSTR("name = %@\n"),
854 (serviceName
!= NULL
) ? serviceName
: CFSTR(""));
856 serviceRank
= SCNetworkServiceGetPrimaryRank(service
);
857 switch (serviceRank
) {
858 case kSCNetworkServicePrimaryRankDefault
:
861 case kSCNetworkServicePrimaryRankFirst
:
862 SCPrint(TRUE
, stdout
, CFSTR("primary rank = %@\n"), kSCValNetServicePrimaryRankFirst
);
864 case kSCNetworkServicePrimaryRankLast
:
865 SCPrint(TRUE
, stdout
, CFSTR("primary rank = %@\n"), kSCValNetServicePrimaryRankLast
);
867 case kSCNetworkServicePrimaryRankNever
:
868 SCPrint(TRUE
, stdout
, CFSTR("primary rank = %@\n"), kSCValNetServicePrimaryRankNever
);
870 case kSCNetworkServicePrimaryRankScoped
:
871 SCPrint(TRUE
, stdout
, CFSTR("primary rank = %@\n"), kSCValNetServicePrimaryRankScoped
);
874 SCPrint(TRUE
, stdout
, CFSTR("primary rank = %d\n"), serviceRank
);
878 interface
= SCNetworkServiceGetInterface(service
);
879 if (interface
!= NULL
) {
880 CFStringRef interfaceName
;
882 interfaceName
= SCNetworkInterfaceGetLocalizedDisplayName(interface
);
883 if (interfaceName
!= NULL
) {
884 CFRetain(interfaceName
);
886 interfaceName
= _interface_description(interface
);
888 if (interfaceName
!= NULL
) {
889 SCPrint(TRUE
, stdout
, CFSTR("interface = %@\n"), interfaceName
);
890 CFRelease(interfaceName
);
893 SCPrint(TRUE
, stdout
, CFSTR("\n No interface!\n\n"));
896 protocols
= SCNetworkServiceCopyProtocols(service
);
897 if (protocols
!= NULL
) {
900 n
= CFArrayGetCount(protocols
);
902 CFMutableArrayRef sorted
;
904 sorted
= CFArrayCreateMutableCopy(NULL
, 0, protocols
);
905 CFArraySortValues(sorted
,
907 _SCNetworkProtocolCompare
,
909 CFRelease(protocols
);
916 SCPrint(TRUE
, stdout
, CFSTR("configured protocols = "));
917 for (i
= 0; i
< n
; i
++) {
918 SCNetworkProtocolRef protocol
;
920 protocol
= CFArrayGetValueAtIndex(protocols
, i
);
921 SCPrint(TRUE
, stdout
, CFSTR("%s%@"),
922 (i
== 0) ? "" : ", ",
923 SCNetworkProtocolGetProtocolType(protocol
));
925 SCPrint(TRUE
, stdout
, CFSTR("\n"));
927 __show_service_protocols(service
, " ", FALSE
);
929 SCPrint(TRUE
, stdout
, CFSTR("no configured protocols\n"));
932 CFRelease(protocols
);
936 SCPrint(TRUE
, stdout
, CFSTR("\n%@\n"), service
);
945 show_services(int argc
, char **argv
)
952 SCPrint(TRUE
, stdout
, CFSTR("network configuration not open\n"));
957 if (services
!= NULL
) CFRelease(services
);
958 services
= SCNetworkServiceCopyAll(prefs
);
960 if (net_set
== NULL
) {
961 SCPrint(TRUE
, stdout
, CFSTR("set not selected\n"));
965 if (services
!= NULL
) CFRelease(services
);
966 services
= SCNetworkSetCopyServices(net_set
);
967 n
= (services
!= NULL
) ? CFArrayGetCount(services
) : 0;
970 CFMutableArrayRef sorted
;
972 order
= SCNetworkSetGetServiceOrder(net_set
);
973 sorted
= CFArrayCreateMutableCopy(NULL
, 0, services
);
974 CFArraySortValues(sorted
,
975 CFRangeMake(0, CFArrayGetCount(sorted
)),
976 _SCNetworkServiceCompare
,
983 if (services
== NULL
) {
984 SCPrint(TRUE
, stdout
, CFSTR("%s\n"), SCErrorString(SCError()));
988 n
= CFArrayGetCount(services
);
989 for (i
= 0; i
< n
; i
++) {
990 SCNetworkServiceRef service
;
991 CFStringRef serviceName
;
992 CFStringRef serviceID
;
994 service
= CFArrayGetValueAtIndex(services
, i
);
995 serviceID
= SCNetworkServiceGetServiceID(service
);
996 serviceName
= SCNetworkServiceGetName(service
);
997 if (serviceName
== NULL
) serviceName
= CFSTR("");
999 SCPrint(TRUE
, stdout
, CFSTR("%c%2ld: %@%-*s (%@)%s\n"),
1000 ((net_service
!= NULL
) && CFEqual(service
, net_service
)) ? '>' : ' ',
1003 (int)(30 - CFStringGetLength(serviceName
)),
1006 SCNetworkServiceGetEnabled(service
) ? "" : " *DISABLED*");
1008 __show_service_interface(service
, " Interface : ");
1009 __show_service_protocols(service
, " ", TRUE
);