2 * Copyright (c) 2004-2009 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 /* -------------------- */
45 _compare_services(const void *val1
, const void *val2
, void *context
)
49 CFArrayRef order
= (CFArrayRef
)context
;
50 SCNetworkServiceRef s1
= (SCNetworkServiceRef
)val1
;
51 SCNetworkServiceRef s2
= (SCNetworkServiceRef
)val2
;
53 id1
= SCNetworkServiceGetServiceID(s1
);
54 id2
= SCNetworkServiceGetServiceID(s2
);
61 range
= CFRangeMake(0, CFArrayGetCount(order
));
62 o1
= CFArrayGetFirstIndexOfValue(order
, range
, id1
);
63 o2
= CFArrayGetFirstIndexOfValue(order
, range
, id2
);
66 return (o2
!= kCFNotFound
) ? kCFCompareGreaterThan
: kCFCompareLessThan
;
68 return (o1
!= kCFNotFound
) ? kCFCompareLessThan
: kCFCompareGreaterThan
;
72 return CFStringCompare(id1
, id2
, 0);
76 static SCNetworkServiceRef
77 _find_service(char *match
)
79 Boolean allowIndex
= TRUE
;
82 CFStringRef select_name
= NULL
;
83 SCNetworkServiceRef selected
= NULL
;
85 if (services
== NULL
) {
86 if (net_set
== NULL
) {
87 SCPrint(TRUE
, stdout
, CFSTR("set not selected\n"));
91 services
= SCNetworkSetCopyServices(net_set
);
92 if (services
== NULL
) {
93 SCPrint(TRUE
, stdout
, CFSTR("%s\n"), SCErrorString(SCError()));
100 // try to select the service by its serviceID
102 select_name
= CFStringCreateWithCString(NULL
, match
, kCFStringEncodingUTF8
);
104 n
= CFArrayGetCount(services
);
105 for (i
= 0; i
< n
; i
++) {
106 SCNetworkServiceRef service
;
107 CFStringRef serviceID
;
109 service
= CFArrayGetValueAtIndex(services
, i
);
110 serviceID
= SCNetworkServiceGetServiceID(service
);
111 if (CFEqual(select_name
, serviceID
)) {
117 // try to select the service by its name
119 for (i
= 0; i
< n
; i
++) {
120 SCNetworkServiceRef service
;
121 CFStringRef serviceName
;
123 service
= CFArrayGetValueAtIndex(services
, i
);
124 serviceName
= SCNetworkServiceGetName(service
);
125 if ((serviceName
!= NULL
) && CFEqual(select_name
, serviceName
)) {
126 if (selected
== NULL
) {
129 // if multiple services match
131 SCPrint(TRUE
, stdout
, CFSTR("multiple services match\n"));
137 if (selected
!= NULL
) {
141 // try to select the service by its name (case insensitive)
143 for (i
= 0; i
< n
; i
++) {
144 SCNetworkServiceRef service
;
145 CFStringRef serviceName
;
147 service
= CFArrayGetValueAtIndex(services
, i
);
148 serviceName
= SCNetworkServiceGetName(service
);
149 if ((serviceName
!= NULL
) &&
150 CFStringCompare(select_name
,
152 kCFCompareCaseInsensitive
) == kCFCompareEqualTo
) {
153 if (selected
== NULL
) {
156 // if multiple services match
158 SCPrint(TRUE
, stdout
, CFSTR("multiple services match\n"));
164 if (selected
!= NULL
) {
168 // try to select the service by its [BSD] interface name
170 for (i
= 0; i
< n
; i
++) {
171 SCNetworkInterfaceRef interface
;
172 CFStringRef interfaceName
= NULL
;
173 SCNetworkServiceRef service
;
175 service
= CFArrayGetValueAtIndex(services
, i
);
177 interface
= SCNetworkServiceGetInterface(service
);
178 while ((interface
!= NULL
) && (interfaceName
== NULL
)) {
179 interfaceName
= SCNetworkInterfaceGetBSDName(interface
);
180 if (interfaceName
== NULL
) {
181 interface
= SCNetworkInterfaceGetInterface(interface
);
185 if (interfaceName
== NULL
) {
189 if (CFStringCompare(select_name
,
191 kCFCompareCaseInsensitive
) == kCFCompareEqualTo
) {
192 if (selected
== NULL
) {
195 // if multiple services match
197 SCPrint(TRUE
, stdout
, CFSTR("multiple services match\n"));
203 if (selected
!= NULL
) {
207 // try to select the service by its index
215 val
= strtol(str
, &end
, 10);
216 if ((*str
!= '\0') && (*end
== '\0') && (errno
== 0)) {
217 if ((val
> 0) && (val
<= n
)) {
218 selected
= CFArrayGetValueAtIndex(services
, val
- 1);
223 if (selected
!= NULL
) {
227 SCPrint(TRUE
, stdout
, CFSTR("no match, which service?\n"));
231 if (select_name
!= NULL
) CFRelease(select_name
);
236 /* -------------------- */
241 create_service(int argc
, char **argv
)
243 SCNetworkInterfaceRef interface
;
244 CFStringRef interfaceName
;
246 SCNetworkServiceRef service
= NULL
;
247 CFStringRef serviceName
;
249 CFArrayRef supported
;
252 SCPrint(TRUE
, stdout
, CFSTR("network configuration not open\n"));
256 if (net_set
== NULL
) {
257 SCPrint(TRUE
, stdout
, CFSTR("set not selected\n"));
262 if (net_interface
== NULL
) {
263 SCPrint(TRUE
, stdout
, CFSTR("no network interface selected\n"));
267 interface
= net_interface
;
271 interface
= _find_interface(argc
, argv
, &nArgs
);
276 if (interface
== NULL
) {
280 supported
= SCNetworkInterfaceGetSupportedProtocolTypes(interface
);
281 if (supported
== NULL
) {
282 SCPrint(TRUE
, stdout
, CFSTR("no network protocols are supported over this interface\n"));
286 service
= SCNetworkServiceCreate(prefs
, interface
);
287 if (service
== NULL
) {
288 SCPrint(TRUE
, stdout
, CFSTR("%s\n"), SCErrorString(SCError()));
292 if ((argc
> 0) && (strlen(argv
[0]) > 0)) {
295 serviceName
= CFStringCreateWithCString(NULL
, argv
[0], kCFStringEncodingUTF8
);
299 ok
= SCNetworkServiceSetName(service
, serviceName
);
300 CFRelease(serviceName
);
302 SCPrint(TRUE
, stdout
, CFSTR("%s\n"), SCErrorString(SCError()));
303 (void)SCNetworkServiceRemove(service
);
308 ok
= SCNetworkServiceEstablishDefaultConfiguration(service
);
310 SCPrint(TRUE
, stdout
, CFSTR("%s\n"), SCErrorString(SCError()));
311 (void)SCNetworkServiceRemove(service
);
315 ok
= SCNetworkSetAddService(net_set
, service
);
317 SCPrint(TRUE
, stdout
, CFSTR("service not created: %s\n"), SCErrorString(SCError()));
318 (void)SCNetworkServiceRemove(service
);
322 _prefs_changed
= TRUE
;
324 if (net_service
!= NULL
) CFRelease(net_service
);
325 net_service
= CFRetain(service
);
327 serviceName
= SCNetworkServiceGetName(service
);
328 if (serviceName
!= NULL
) {
329 SCPrint(TRUE
, stdout
,
330 CFSTR("service \"%@\" (%@) created and selected\n"),
332 SCNetworkServiceGetServiceID(service
));
334 SCPrint(TRUE
, stdout
,
335 CFSTR("service ID \"%@\" created and selected\n"),
336 SCNetworkServiceGetServiceID(service
));
339 setName
= SCNetworkSetGetName(net_set
);
340 if (setName
!= NULL
) {
341 SCPrint(TRUE
, stdout
, CFSTR("& added to set \"%@\"\n"), setName
);
343 SCPrint(TRUE
, stdout
, CFSTR("& added to set ID \"%@\"\n"),
344 SCNetworkSetGetSetID(net_set
));
347 if (net_interface
!= NULL
) CFRelease(net_interface
);
348 net_interface
= SCNetworkServiceGetInterface(net_service
);
349 if (net_interface
!= NULL
) {
350 CFRetain(net_interface
);
353 interfaceName
= SCNetworkInterfaceGetLocalizedDisplayName(interface
);
354 if (interfaceName
== NULL
) {
355 interfaceName
= SCNetworkInterfaceGetBSDName(interface
);
357 if (interfaceName
== NULL
) {
358 interfaceName
= SCNetworkInterfaceGetInterfaceType(interface
);
361 SCPrint(TRUE
, stdout
,
362 CFSTR("& interface \"%@\" selected\n"),
365 if (protocols
!= NULL
) {
366 CFRelease(protocols
);
370 if (net_protocol
!= NULL
) {
371 CFRelease(net_protocol
);
373 SCPrint(TRUE
, stdout
, CFSTR("& no protocol selected\n"));
376 if (services
!= NULL
) {
383 if (service
!= NULL
) CFRelease(service
);
390 disable_service(int argc
, char **argv
)
392 SCNetworkServiceRef service
;
395 service
= _find_service(argv
[0]);
397 if (net_service
!= NULL
) {
398 service
= net_service
;
400 SCPrint(TRUE
, stdout
, CFSTR("service not selected\n"));
405 if (service
== NULL
) {
409 if (!SCNetworkServiceSetEnabled(service
, FALSE
)) {
410 SCPrint(TRUE
, stdout
, CFSTR("%s\n"), SCErrorString(SCError()));
414 _prefs_changed
= TRUE
;
421 enable_service(int argc
, char **argv
)
423 SCNetworkServiceRef service
;
426 service
= _find_service(argv
[0]);
428 if (net_service
!= NULL
) {
429 service
= net_service
;
431 SCPrint(TRUE
, stdout
, CFSTR("service not selected\n"));
436 if (service
== NULL
) {
440 if (!SCNetworkServiceSetEnabled(service
, TRUE
)) {
441 SCPrint(TRUE
, stdout
, CFSTR("%s\n"), SCErrorString(SCError()));
445 _prefs_changed
= TRUE
;
452 remove_service(int argc
, char **argv
)
454 SCNetworkServiceRef service
= NULL
;
455 CFStringRef serviceName
;
458 service
= _find_service(argv
[0]);
460 if (net_service
!= NULL
) {
461 service
= net_service
;
465 if (service
== NULL
) {
471 if (!SCNetworkServiceRemove(service
)) {
472 SCPrint(TRUE
, stdout
, CFSTR("%s\n"), SCErrorString(SCError()));
476 _prefs_changed
= TRUE
;
478 serviceName
= SCNetworkServiceGetName(service
);
479 if (serviceName
!= NULL
) {
480 SCPrint(TRUE
, stdout
, CFSTR("service \"%@\" removed\n"), serviceName
);
482 SCPrint(TRUE
, stdout
,
483 CFSTR("service ID \"%@\" removed\n"),
484 SCNetworkServiceGetServiceID(service
));
487 if ((net_service
!= NULL
) && CFEqual(service
, net_service
)) {
488 CFRelease(net_service
);
490 SCPrint(TRUE
, stdout
, CFSTR("& no service selected\n"));
492 if (protocols
!= NULL
) {
493 CFRelease(protocols
);
497 if (net_protocol
!= NULL
) {
498 CFRelease(net_protocol
);
500 SCPrint(TRUE
, stdout
, CFSTR("& no protocol selected\n"));
503 if (net_interface
!= NULL
) {
504 CFRelease(net_interface
);
505 net_interface
= NULL
;
506 SCPrint(TRUE
, stdout
, CFSTR("& no interface selected\n"));
510 if (services
!= NULL
) {
524 select_service(int argc
, char **argv
)
526 SCNetworkInterfaceRef interface
;
527 SCNetworkServiceRef service
;
528 CFStringRef serviceName
;
530 service
= _find_service(argv
[0]);
532 if (service
== NULL
) {
536 if (net_service
!= NULL
) CFRelease(net_service
);
537 net_service
= CFRetain(service
);
539 serviceName
= SCNetworkServiceGetName(service
);
540 if (serviceName
!= NULL
) {
541 SCPrint(TRUE
, stdout
, CFSTR("service \"%@\" selected\n"), serviceName
);
543 SCPrint(TRUE
, stdout
,
544 CFSTR("service ID \"%@\" selected\n"),
545 SCNetworkServiceGetServiceID(service
));
548 interface
= SCNetworkServiceGetInterface(service
);
549 if (interface
!= NULL
) {
550 CFStringRef interfaceName
;
552 if (net_interface
!= NULL
) CFRelease(net_interface
);
553 net_interface
= CFRetain(interface
);
555 interfaceName
= SCNetworkInterfaceGetLocalizedDisplayName(interface
);
556 if (interfaceName
== NULL
) {
557 interfaceName
= SCNetworkInterfaceGetBSDName(interface
);
559 if (interfaceName
== NULL
) {
560 interfaceName
= SCNetworkInterfaceGetInterfaceType(interface
);
563 SCPrint(TRUE
, stdout
,
564 CFSTR("& interface \"%@\" selected\n"),
567 if (net_interface
!= NULL
) {
568 CFRelease(net_interface
);
569 net_interface
= NULL
;
570 SCPrint(TRUE
, stdout
, CFSTR("& no interface selected\n"));
574 if (protocols
!= NULL
) {
575 CFRelease(protocols
);
579 if (net_protocol
!= NULL
) {
580 CFRelease(net_protocol
);
582 SCPrint(TRUE
, stdout
, CFSTR("& no protocol selected\n"));
591 set_service(int argc
, char **argv
)
595 if (net_service
== NULL
) {
596 SCPrint(TRUE
, stdout
, CFSTR("service not selected\n"));
601 SCPrint(TRUE
, stdout
, CFSTR("set what?\n"));
612 if (strcmp(command
, "name") == 0) {
613 CFStringRef serviceName
;
616 SCPrint(TRUE
, stdout
, CFSTR("name not specified\n"));
620 serviceName
= (strlen(argv
[0]) > 0)
621 ? CFStringCreateWithCString(NULL
, argv
[0], kCFStringEncodingUTF8
)
626 ok
= SCNetworkServiceSetName(net_service
, serviceName
);
627 if (serviceName
!= NULL
) CFRelease(serviceName
);
629 SCPrint(TRUE
, stdout
, CFSTR("%s\n"), SCErrorString(SCError()));
633 _prefs_changed
= TRUE
;
634 } else if (strcmp(command
, "order") == 0) {
642 services
= SCNetworkSetCopyServices(net_set
);
643 nServices
= CFArrayGetCount(services
);
647 SCPrint(TRUE
, stdout
, CFSTR("order not specified\n"));
651 if (net_set
== NULL
) {
652 SCPrint(TRUE
, stdout
, CFSTR("set not selected\n"));
661 newIndex
= strtol(str
, &end
, 10);
662 if ((*str
!= '\0') && (*end
== '\0') && (errno
== 0)) {
663 if ((newIndex
> 0) && (newIndex
<= nServices
)) {
665 CFMutableArrayRef newOrder
;
667 CFStringRef serviceID
= SCNetworkServiceGetServiceID(net_service
);
669 order
= SCNetworkSetGetServiceOrder(net_set
);
671 newOrder
= CFArrayCreateMutable(NULL
, 0, &kCFTypeArrayCallBacks
);
673 newOrder
= CFArrayCreateMutableCopy(NULL
, 0, order
);
676 curIndex
= CFArrayGetFirstIndexOfValue(newOrder
,
677 CFRangeMake(0, CFArrayGetCount(newOrder
)),
679 if (curIndex
!= kCFNotFound
) {
680 CFArrayRemoveValueAtIndex(newOrder
, curIndex
);
683 if (newIndex
<= CFArrayGetCount(newOrder
)) {
684 CFArrayInsertValueAtIndex(newOrder
, newIndex
- 1, serviceID
);
686 CFArrayAppendValue(newOrder
, serviceID
);
689 ok
= SCNetworkSetSetServiceOrder(net_set
, newOrder
);
692 SCPrint(TRUE
, stdout
, CFSTR("%s\n"), SCErrorString(SCError()));
696 _prefs_changed
= TRUE
;
698 SCPrint(TRUE
, stdout
, CFSTR("set order to what?\n"));
702 SCPrint(TRUE
, stdout
, CFSTR("set what?\n"));
705 } else if (strcmp(command
, "rank") == 0) {
706 SCNetworkServicePrimaryRank rank
= kSCNetworkServicePrimaryRankDefault
;
707 SCNetworkServiceRef service
= (argc
< 2) ? net_service
: NULL
;
710 SCPrint(TRUE
, stdout
, CFSTR("rank not specified\n"));
714 if (strlen(argv
[0]) > 0) {
715 if (strcasecmp(argv
[0], "Never") == 0) {
716 rank
= kSCNetworkServicePrimaryRankNever
;
717 } else if ((service
!= net_service
) && (strcasecmp(argv
[0], "First") == 0)) {
718 rank
= kSCNetworkServicePrimaryRankFirst
;
719 } else if ((service
!= net_service
) && (strcasecmp(argv
[0], "Last") == 0)) {
720 rank
= kSCNetworkServicePrimaryRankLast
;
722 SCPrint(TRUE
, stdout
, CFSTR("rank not valid\n"));
729 if (service
== NULL
) {
730 CFStringRef serviceID
;
731 SCDynamicStoreRef store
;
733 store
= SCDynamicStoreCreate(NULL
,
734 CFSTR("scutil (set primary rank)"),
737 serviceID
= SCNetworkServiceGetServiceID(net_service
);
738 service
= _SCNetworkServiceCopyActive(store
, serviceID
);
745 ok
= SCNetworkServiceSetPrimaryRank(service
, rank
);
746 if (service
!= net_service
) CFRelease(service
);
748 if (service
== net_service
) _prefs_changed
= TRUE
;
750 SCPrint(TRUE
, stdout
, CFSTR("%s\n"), SCErrorString(SCError()));
754 SCPrint(TRUE
, stdout
, CFSTR("set what?\n"));
763 __show_service_interface(SCNetworkServiceRef service
, const char *prefix
)
765 CFStringRef description
;
766 SCNetworkInterfaceRef interface
;
768 interface
= SCNetworkServiceGetInterface(service
);
769 if (interface
== NULL
) {
773 description
= _interface_description(interface
);
774 SCPrint(TRUE
, stdout
, CFSTR("%s%@\n"), prefix
, description
);
775 CFRelease(description
);
781 __show_service_protocols(SCNetworkServiceRef service
, const char *prefix
, Boolean skipEmpty
)
785 CFArrayRef protocols
;
787 protocols
= SCNetworkServiceCopyProtocols(service
);
788 if (protocols
== NULL
) {
792 n
= CFArrayGetCount(protocols
);
794 CFMutableArrayRef sorted
;
796 sorted
= CFArrayCreateMutableCopy(NULL
, 0, protocols
);
797 CFArraySortValues(sorted
,
801 CFRelease(protocols
);
805 for (i
= 0; i
< n
; i
++) {
806 CFStringRef description
;
807 SCNetworkProtocolRef protocol
;
809 protocol
= CFArrayGetValueAtIndex(protocols
, i
);
810 description
= _protocol_description(protocol
, skipEmpty
);
811 if (description
!= NULL
) {
812 CFStringRef protocolType
;
814 protocolType
= SCNetworkProtocolGetProtocolType(protocol
);
815 SCPrint(TRUE
, stdout
,
816 CFSTR("%s%@%*s : %@\n"),
819 sizeof("Interface") - CFStringGetLength(protocolType
) - 1,
822 CFRelease(description
);
826 CFRelease(protocols
);
833 show_service(int argc
, char **argv
)
835 SCNetworkInterfaceRef interface
;
836 CFArrayRef protocols
;
837 SCNetworkServiceRef service
;
838 CFStringRef serviceName
;
839 SCNetworkServicePrimaryRank serviceRank
;
842 service
= _find_service(argv
[0]);
844 if (net_service
!= NULL
) {
845 service
= net_service
;
847 SCPrint(TRUE
, stdout
, CFSTR("service not selected\n"));
852 if (service
== NULL
) {
856 SCPrint(TRUE
, stdout
, CFSTR("service id = %@\n"), SCNetworkServiceGetServiceID(service
));
858 serviceName
= SCNetworkServiceGetName(service
);
859 SCPrint(TRUE
, stdout
, CFSTR("name = %@\n"),
860 (serviceName
!= NULL
) ? serviceName
: CFSTR(""));
862 serviceRank
= SCNetworkServiceGetPrimaryRank(service
);
863 switch (serviceRank
) {
864 case kSCNetworkServicePrimaryRankDefault
:
867 case kSCNetworkServicePrimaryRankFirst
:
868 SCPrint(TRUE
, stdout
, CFSTR("primary rank = FIRST\n"));
870 case kSCNetworkServicePrimaryRankLast
:
871 SCPrint(TRUE
, stdout
, CFSTR("primary rank = LAST\n"));
873 case kSCNetworkServicePrimaryRankNever
:
874 SCPrint(TRUE
, stdout
, CFSTR("primary rank = NEVER\n"));
877 SCPrint(TRUE
, stdout
, CFSTR("primary rank = %d\n"), serviceRank
);
881 interface
= SCNetworkServiceGetInterface(service
);
882 if (interface
!= NULL
) {
883 CFStringRef interfaceName
;
885 interfaceName
= SCNetworkInterfaceGetLocalizedDisplayName(interface
);
886 if (interfaceName
!= NULL
) {
887 CFRetain(interfaceName
);
889 interfaceName
= _interface_description(interface
);
891 if (interfaceName
!= NULL
) {
892 SCPrint(TRUE
, stdout
, CFSTR("interface = %@\n"), interfaceName
);
893 CFRelease(interfaceName
);
896 SCPrint(TRUE
, stdout
, CFSTR("\n No interface!\n\n"));
899 protocols
= SCNetworkServiceCopyProtocols(service
);
900 if (protocols
!= NULL
) {
903 n
= CFArrayGetCount(protocols
);
905 CFMutableArrayRef sorted
;
907 sorted
= CFArrayCreateMutableCopy(NULL
, 0, protocols
);
908 CFArraySortValues(sorted
,
912 CFRelease(protocols
);
919 SCPrint(TRUE
, stdout
, CFSTR("configured protocols = "));
920 for (i
= 0; i
< n
; i
++) {
921 SCNetworkProtocolRef protocol
;
923 protocol
= CFArrayGetValueAtIndex(protocols
, i
);
924 SCPrint(TRUE
, stdout
, CFSTR("%s%@"),
925 (i
== 0) ? "" : ", ",
926 SCNetworkProtocolGetProtocolType(protocol
));
928 SCPrint(TRUE
, stdout
, CFSTR("\n"));
930 __show_service_protocols(service
, " ", FALSE
);
932 SCPrint(TRUE
, stdout
, CFSTR("no configured protocols\n"));
935 CFRelease(protocols
);
939 SCPrint(TRUE
, stdout
, CFSTR("\n%@\n"), service
);
948 show_services(int argc
, char **argv
)
954 SCPrint(TRUE
, stdout
, CFSTR("network configuration not open\n"));
959 if (services
!= NULL
) CFRelease(services
);
960 services
= SCNetworkServiceCopyAll(prefs
);
962 if (net_set
== NULL
) {
963 SCPrint(TRUE
, stdout
, CFSTR("set not selected\n"));
967 if (services
!= NULL
) CFRelease(services
);
968 services
= SCNetworkSetCopyServices(net_set
);
969 n
= (services
!= NULL
) ? CFArrayGetCount(services
) : 0;
972 CFMutableArrayRef sorted
;
974 order
= SCNetworkSetGetServiceOrder(net_set
);
975 sorted
= CFArrayCreateMutableCopy(NULL
, 0, services
);
976 CFArraySortValues(sorted
,
977 CFRangeMake(0, CFArrayGetCount(sorted
)),
985 if (services
== NULL
) {
986 SCPrint(TRUE
, stdout
, CFSTR("%s\n"), SCErrorString(SCError()));
990 n
= CFArrayGetCount(services
);
991 for (i
= 0; i
< n
; i
++) {
992 SCNetworkServiceRef service
;
993 CFStringRef serviceName
;
994 CFStringRef serviceID
;
996 service
= CFArrayGetValueAtIndex(services
, i
);
997 serviceID
= SCNetworkServiceGetServiceID(service
);
998 serviceName
= SCNetworkServiceGetName(service
);
999 if (serviceName
== NULL
) serviceName
= CFSTR("");
1001 SCPrint(TRUE
, stdout
, CFSTR("%c%2d: %@%-*s (%@)%s\n"),
1002 ((net_service
!= NULL
) && CFEqual(service
, net_service
)) ? '>' : ' ',
1005 30 - CFStringGetLength(serviceName
),
1008 SCNetworkServiceGetEnabled(service
) ? "" : " *DISABLED*");
1010 __show_service_interface(service
, " Interface : ");
1011 __show_service_protocols(service
, " ", TRUE
);