2 * Copyright (c) 2004-2010, 2013, 2014, 2016 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
)
493 SCNetworkInterfaceRef interface
;
494 SCNetworkServiceRef service
;
495 CFStringRef serviceName
;
497 service
= _find_service(argv
[0]);
499 if (service
== NULL
) {
503 if (net_service
!= NULL
) CFRelease(net_service
);
504 net_service
= CFRetain(service
);
506 serviceName
= SCNetworkServiceGetName(service
);
507 if (serviceName
!= NULL
) {
508 SCPrint(TRUE
, stdout
, CFSTR("service \"%@\" selected\n"), serviceName
);
510 SCPrint(TRUE
, stdout
,
511 CFSTR("service ID \"%@\" selected\n"),
512 SCNetworkServiceGetServiceID(service
));
515 interface
= SCNetworkServiceGetInterface(service
);
516 if (interface
!= NULL
) {
517 CFStringRef interfaceName
;
519 if (net_interface
!= NULL
) CFRelease(net_interface
);
520 net_interface
= CFRetain(interface
);
522 interfaceName
= SCNetworkInterfaceGetLocalizedDisplayName(interface
);
523 if (interfaceName
== NULL
) {
524 interfaceName
= SCNetworkInterfaceGetBSDName(interface
);
526 if (interfaceName
== NULL
) {
527 interfaceName
= SCNetworkInterfaceGetInterfaceType(interface
);
530 SCPrint(TRUE
, stdout
,
531 CFSTR("& interface \"%@\" selected\n"),
534 if (net_interface
!= NULL
) {
535 CFRelease(net_interface
);
536 net_interface
= NULL
;
537 SCPrint(TRUE
, stdout
, CFSTR("& no interface selected\n"));
541 if (protocols
!= NULL
) {
542 CFRelease(protocols
);
546 if (net_protocol
!= NULL
) {
547 CFRelease(net_protocol
);
549 SCPrint(TRUE
, stdout
, CFSTR("& no protocol selected\n"));
558 set_service(int argc
, char **argv
)
562 if (net_service
== NULL
) {
563 SCPrint(TRUE
, stdout
, CFSTR("service not selected\n"));
568 SCPrint(TRUE
, stdout
, CFSTR("set what?\n"));
579 if (strcmp(command
, "name") == 0) {
580 CFStringRef serviceName
;
583 SCPrint(TRUE
, stdout
, CFSTR("name not specified\n"));
587 serviceName
= (strlen(argv
[0]) > 0)
588 ? CFStringCreateWithCString(NULL
, argv
[0], kCFStringEncodingUTF8
)
593 ok
= SCNetworkServiceSetName(net_service
, serviceName
);
594 if (serviceName
!= NULL
) CFRelease(serviceName
);
596 SCPrint(TRUE
, stdout
, CFSTR("%s\n"), SCErrorString(SCError()));
600 _prefs_changed
= TRUE
;
601 } else if (strcmp(command
, "order") == 0) {
609 services
= SCNetworkSetCopyServices(net_set
);
610 nServices
= CFArrayGetCount(services
);
614 SCPrint(TRUE
, stdout
, CFSTR("order not specified\n"));
618 if (net_set
== NULL
) {
619 SCPrint(TRUE
, stdout
, CFSTR("set not selected\n"));
628 newIndex
= strtol(str
, &end
, 10);
629 if ((*str
!= '\0') && (*end
== '\0') && (errno
== 0)) {
630 if ((newIndex
> 0) && (newIndex
<= nServices
)) {
632 CFMutableArrayRef newOrder
;
634 CFStringRef serviceID
= SCNetworkServiceGetServiceID(net_service
);
636 order
= SCNetworkSetGetServiceOrder(net_set
);
638 newOrder
= CFArrayCreateMutable(NULL
, 0, &kCFTypeArrayCallBacks
);
640 newOrder
= CFArrayCreateMutableCopy(NULL
, 0, order
);
643 curIndex
= CFArrayGetFirstIndexOfValue(newOrder
,
644 CFRangeMake(0, CFArrayGetCount(newOrder
)),
646 if (curIndex
!= kCFNotFound
) {
647 CFArrayRemoveValueAtIndex(newOrder
, curIndex
);
650 if (newIndex
<= CFArrayGetCount(newOrder
)) {
651 CFArrayInsertValueAtIndex(newOrder
, newIndex
- 1, serviceID
);
653 CFArrayAppendValue(newOrder
, serviceID
);
656 ok
= SCNetworkSetSetServiceOrder(net_set
, newOrder
);
659 SCPrint(TRUE
, stdout
, CFSTR("%s\n"), SCErrorString(SCError()));
663 _prefs_changed
= TRUE
;
665 SCPrint(TRUE
, stdout
, CFSTR("set order to what?\n"));
669 SCPrint(TRUE
, stdout
, CFSTR("set what?\n"));
672 } else if (strcmp(command
, "rank") == 0) {
673 SCNetworkServicePrimaryRank rank
= kSCNetworkServicePrimaryRankDefault
;
674 SCNetworkServiceRef service
= (argc
< 2) ? net_service
: NULL
;
675 Boolean useActive
= FALSE
;
678 SCPrint(TRUE
, stdout
, CFSTR("rank not specified\n"));
682 if (strlen(argv
[0]) > 0) {
683 if (strcasecmp(argv
[0], "Never") == 0) {
684 rank
= kSCNetworkServicePrimaryRankNever
;
685 } else if ((service
!= net_service
) && (strcasecmp(argv
[0], "First") == 0)) {
686 rank
= kSCNetworkServicePrimaryRankFirst
;
687 } else if ((service
!= net_service
) && (strcasecmp(argv
[0], "Last") == 0)) {
688 rank
= kSCNetworkServicePrimaryRankLast
;
689 } else if ((service
!= net_service
) && (strcasecmp(argv
[0], "Scoped") == 0)) {
690 rank
= kSCNetworkServicePrimaryRankScoped
;
692 SCPrint(TRUE
, stdout
, CFSTR("rank not valid\n"));
699 if (service
== NULL
) {
700 CFStringRef serviceID
;
701 SCDynamicStoreRef store
;
703 store
= SCDynamicStoreCreate(NULL
,
704 CFSTR("scutil (set primary rank)"),
707 serviceID
= SCNetworkServiceGetServiceID(net_service
);
708 service
= _SCNetworkServiceCopyActive(store
, serviceID
);
716 ok
= SCNetworkServiceSetPrimaryRank(service
, rank
);
720 _prefs_changed
= TRUE
;
723 SCPrint(TRUE
, stdout
, CFSTR("%s\n"), SCErrorString(SCError()));
726 } else if (strcmp(command
, "id") == 0) {
727 CFStringRef serviceID
;
729 if ((argc
< 1) || (strlen(argv
[0]) == 0)) {
730 SCPrint(TRUE
, stdout
, CFSTR("set id not specified\n"));
734 serviceID
= CFStringCreateWithCString(NULL
, argv
[0], kCFStringEncodingUTF8
);
738 ok
= _SCNetworkServiceSetServiceID(net_service
, serviceID
);
739 CFRelease(serviceID
);
741 SCPrint(TRUE
, stdout
, CFSTR("%s\n"), SCErrorString(SCError()));
745 _prefs_changed
= TRUE
;
747 SCPrint(TRUE
, stdout
, CFSTR("set what?\n"));
756 __show_service_interface(SCNetworkServiceRef service
, const char *prefix
)
758 CFStringRef description
;
759 SCNetworkInterfaceRef interface
;
761 interface
= SCNetworkServiceGetInterface(service
);
762 if (interface
== NULL
) {
766 description
= _interface_description(interface
);
767 SCPrint(TRUE
, stdout
, CFSTR("%s%@\n"), prefix
, description
);
768 CFRelease(description
);
774 __show_service_protocols(SCNetworkServiceRef service
, const char *prefix
, Boolean skipEmpty
)
778 CFArrayRef protocols
;
780 protocols
= SCNetworkServiceCopyProtocols(service
);
781 if (protocols
== NULL
) {
785 n
= CFArrayGetCount(protocols
);
787 CFMutableArrayRef sorted
;
789 sorted
= CFArrayCreateMutableCopy(NULL
, 0, protocols
);
790 CFArraySortValues(sorted
,
794 CFRelease(protocols
);
798 for (i
= 0; i
< n
; i
++) {
799 CFStringRef description
;
800 SCNetworkProtocolRef protocol
;
802 protocol
= CFArrayGetValueAtIndex(protocols
, i
);
803 description
= _protocol_description(protocol
, skipEmpty
);
804 if (description
!= NULL
) {
805 CFStringRef protocolType
;
807 protocolType
= SCNetworkProtocolGetProtocolType(protocol
);
808 SCPrint(TRUE
, stdout
,
809 CFSTR("%s%@%*s : %@\n"),
812 (int)(sizeof("Interface") - CFStringGetLength(protocolType
) - 1),
815 CFRelease(description
);
819 CFRelease(protocols
);
826 show_service(int argc
, char **argv
)
828 SCNetworkInterfaceRef interface
;
829 CFArrayRef protocols
;
830 SCNetworkServiceRef service
;
831 CFStringRef serviceName
;
832 SCNetworkServicePrimaryRank serviceRank
;
835 service
= _find_service(argv
[0]);
837 if (net_service
!= NULL
) {
838 service
= net_service
;
840 SCPrint(TRUE
, stdout
, CFSTR("service not selected\n"));
845 if (service
== NULL
) {
849 SCPrint(TRUE
, stdout
, CFSTR("service id = %@\n"), SCNetworkServiceGetServiceID(service
));
851 serviceName
= SCNetworkServiceGetName(service
);
852 SCPrint(TRUE
, stdout
, CFSTR("name = %@\n"),
853 (serviceName
!= NULL
) ? serviceName
: CFSTR(""));
855 serviceRank
= SCNetworkServiceGetPrimaryRank(service
);
856 switch (serviceRank
) {
857 case kSCNetworkServicePrimaryRankDefault
:
860 case kSCNetworkServicePrimaryRankFirst
:
861 SCPrint(TRUE
, stdout
, CFSTR("primary rank = FIRST\n"));
863 case kSCNetworkServicePrimaryRankLast
:
864 SCPrint(TRUE
, stdout
, CFSTR("primary rank = LAST\n"));
866 case kSCNetworkServicePrimaryRankNever
:
867 SCPrint(TRUE
, stdout
, CFSTR("primary rank = NEVER\n"));
869 case kSCNetworkServicePrimaryRankScoped
:
870 SCPrint(TRUE
, stdout
, CFSTR("primary rank = SCOPED\n"));
873 SCPrint(TRUE
, stdout
, CFSTR("primary rank = %d\n"), serviceRank
);
877 interface
= SCNetworkServiceGetInterface(service
);
878 if (interface
!= NULL
) {
879 CFStringRef interfaceName
;
881 interfaceName
= SCNetworkInterfaceGetLocalizedDisplayName(interface
);
882 if (interfaceName
!= NULL
) {
883 CFRetain(interfaceName
);
885 interfaceName
= _interface_description(interface
);
887 if (interfaceName
!= NULL
) {
888 SCPrint(TRUE
, stdout
, CFSTR("interface = %@\n"), interfaceName
);
889 CFRelease(interfaceName
);
892 SCPrint(TRUE
, stdout
, CFSTR("\n No interface!\n\n"));
895 protocols
= SCNetworkServiceCopyProtocols(service
);
896 if (protocols
!= NULL
) {
899 n
= CFArrayGetCount(protocols
);
901 CFMutableArrayRef sorted
;
903 sorted
= CFArrayCreateMutableCopy(NULL
, 0, protocols
);
904 CFArraySortValues(sorted
,
908 CFRelease(protocols
);
915 SCPrint(TRUE
, stdout
, CFSTR("configured protocols = "));
916 for (i
= 0; i
< n
; i
++) {
917 SCNetworkProtocolRef protocol
;
919 protocol
= CFArrayGetValueAtIndex(protocols
, i
);
920 SCPrint(TRUE
, stdout
, CFSTR("%s%@"),
921 (i
== 0) ? "" : ", ",
922 SCNetworkProtocolGetProtocolType(protocol
));
924 SCPrint(TRUE
, stdout
, CFSTR("\n"));
926 __show_service_protocols(service
, " ", FALSE
);
928 SCPrint(TRUE
, stdout
, CFSTR("no configured protocols\n"));
931 CFRelease(protocols
);
935 SCPrint(TRUE
, stdout
, CFSTR("\n%@\n"), service
);
944 show_services(int argc
, char **argv
)
950 SCPrint(TRUE
, stdout
, CFSTR("network configuration not open\n"));
955 if (services
!= NULL
) CFRelease(services
);
956 services
= SCNetworkServiceCopyAll(prefs
);
958 if (net_set
== NULL
) {
959 SCPrint(TRUE
, stdout
, CFSTR("set not selected\n"));
963 if (services
!= NULL
) CFRelease(services
);
964 services
= SCNetworkSetCopyServices(net_set
);
965 n
= (services
!= NULL
) ? CFArrayGetCount(services
) : 0;
968 CFMutableArrayRef sorted
;
970 order
= SCNetworkSetGetServiceOrder(net_set
);
971 sorted
= CFArrayCreateMutableCopy(NULL
, 0, services
);
972 CFArraySortValues(sorted
,
973 CFRangeMake(0, CFArrayGetCount(sorted
)),
974 _SCNetworkServiceCompare
,
981 if (services
== NULL
) {
982 SCPrint(TRUE
, stdout
, CFSTR("%s\n"), SCErrorString(SCError()));
986 n
= CFArrayGetCount(services
);
987 for (i
= 0; i
< n
; i
++) {
988 SCNetworkServiceRef service
;
989 CFStringRef serviceName
;
990 CFStringRef serviceID
;
992 service
= CFArrayGetValueAtIndex(services
, i
);
993 serviceID
= SCNetworkServiceGetServiceID(service
);
994 serviceName
= SCNetworkServiceGetName(service
);
995 if (serviceName
== NULL
) serviceName
= CFSTR("");
997 SCPrint(TRUE
, stdout
, CFSTR("%c%2ld: %@%-*s (%@)%s\n"),
998 ((net_service
!= NULL
) && CFEqual(service
, net_service
)) ? '>' : ' ',
1001 (int)(30 - CFStringGetLength(serviceName
)),
1004 SCNetworkServiceGetEnabled(service
) ? "" : " *DISABLED*");
1006 __show_service_interface(service
, " Interface : ");
1007 __show_service_protocols(service
, " ", TRUE
);