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 CFRetain(net_interface
);
351 interfaceName
= SCNetworkInterfaceGetLocalizedDisplayName(interface
);
352 if (interfaceName
== NULL
) {
353 interfaceName
= SCNetworkInterfaceGetBSDName(interface
);
355 if (interfaceName
== NULL
) {
356 interfaceName
= SCNetworkInterfaceGetInterfaceType(interface
);
359 SCPrint(TRUE
, stdout
,
360 CFSTR("& interface \"%@\" selected\n"),
363 if (protocols
!= NULL
) {
364 CFRelease(protocols
);
368 if (net_protocol
!= NULL
) {
369 CFRelease(net_protocol
);
371 SCPrint(TRUE
, stdout
, CFSTR("& no protocol selected\n"));
374 if (services
!= NULL
) {
381 if (service
!= NULL
) CFRelease(service
);
388 disable_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
, FALSE
)) {
408 SCPrint(TRUE
, stdout
, CFSTR("%s\n"), SCErrorString(SCError()));
412 _prefs_changed
= TRUE
;
419 enable_service(int argc
, char **argv
)
421 SCNetworkServiceRef service
;
424 service
= _find_service(argv
[0]);
426 if (net_service
!= NULL
) {
427 service
= net_service
;
429 SCPrint(TRUE
, stdout
, CFSTR("service not selected\n"));
434 if (service
== NULL
) {
438 if (!SCNetworkServiceSetEnabled(service
, TRUE
)) {
439 SCPrint(TRUE
, stdout
, CFSTR("%s\n"), SCErrorString(SCError()));
443 _prefs_changed
= TRUE
;
450 remove_service(int argc
, char **argv
)
452 SCNetworkServiceRef service
= NULL
;
453 CFStringRef serviceName
;
456 service
= _find_service(argv
[0]);
458 if (net_service
!= NULL
) {
459 service
= net_service
;
463 if (service
== NULL
) {
469 if (!SCNetworkServiceRemove(service
)) {
470 SCPrint(TRUE
, stdout
, CFSTR("%s\n"), SCErrorString(SCError()));
474 _prefs_changed
= TRUE
;
476 serviceName
= SCNetworkServiceGetName(service
);
477 if (serviceName
!= NULL
) {
478 SCPrint(TRUE
, stdout
, CFSTR("service \"%@\" removed\n"), serviceName
);
480 SCPrint(TRUE
, stdout
,
481 CFSTR("service ID \"%@\" removed\n"),
482 SCNetworkServiceGetServiceID(service
));
485 if ((net_service
!= NULL
) && CFEqual(service
, net_service
)) {
486 CFRelease(net_service
);
488 SCPrint(TRUE
, stdout
, CFSTR("& no service selected\n"));
490 if (protocols
!= NULL
) {
491 CFRelease(protocols
);
495 if (net_protocol
!= NULL
) {
496 CFRelease(net_protocol
);
498 SCPrint(TRUE
, stdout
, CFSTR("& no protocol selected\n"));
501 if (net_interface
!= NULL
) {
502 CFRelease(net_interface
);
503 net_interface
= NULL
;
504 SCPrint(TRUE
, stdout
, CFSTR("& no interface selected\n"));
508 if (services
!= NULL
) {
522 select_service(int argc
, char **argv
)
524 SCNetworkInterfaceRef interface
;
525 SCNetworkServiceRef service
;
526 CFStringRef serviceName
;
528 service
= _find_service(argv
[0]);
530 if (service
== NULL
) {
534 if (net_service
!= NULL
) CFRelease(net_service
);
535 net_service
= CFRetain(service
);
537 serviceName
= SCNetworkServiceGetName(service
);
538 if (serviceName
!= NULL
) {
539 SCPrint(TRUE
, stdout
, CFSTR("service \"%@\" selected\n"), serviceName
);
541 SCPrint(TRUE
, stdout
,
542 CFSTR("service ID \"%@\" selected\n"),
543 SCNetworkServiceGetServiceID(service
));
546 interface
= SCNetworkServiceGetInterface(service
);
547 if (interface
!= NULL
) {
548 CFStringRef interfaceName
;
550 if (net_interface
!= NULL
) CFRelease(net_interface
);
551 net_interface
= CFRetain(interface
);
553 interfaceName
= SCNetworkInterfaceGetLocalizedDisplayName(interface
);
554 if (interfaceName
== NULL
) {
555 interfaceName
= SCNetworkInterfaceGetBSDName(interface
);
557 if (interfaceName
== NULL
) {
558 interfaceName
= SCNetworkInterfaceGetInterfaceType(interface
);
561 SCPrint(TRUE
, stdout
,
562 CFSTR("& interface \"%@\" selected\n"),
565 if (net_interface
!= NULL
) {
566 CFRelease(net_interface
);
567 net_interface
= NULL
;
568 SCPrint(TRUE
, stdout
, CFSTR("& no interface selected\n"));
572 if (protocols
!= NULL
) {
573 CFRelease(protocols
);
577 if (net_protocol
!= NULL
) {
578 CFRelease(net_protocol
);
580 SCPrint(TRUE
, stdout
, CFSTR("& no protocol selected\n"));
589 set_service(int argc
, char **argv
)
593 if (net_service
== NULL
) {
594 SCPrint(TRUE
, stdout
, CFSTR("service not selected\n"));
599 SCPrint(TRUE
, stdout
, CFSTR("set what?\n"));
610 if (strcmp(command
, "name") == 0) {
611 CFStringRef serviceName
;
614 SCPrint(TRUE
, stdout
, CFSTR("name not specified\n"));
618 serviceName
= (strlen(argv
[0]) > 0)
619 ? CFStringCreateWithCString(NULL
, argv
[0], kCFStringEncodingUTF8
)
624 ok
= SCNetworkServiceSetName(net_service
, serviceName
);
625 if (serviceName
!= NULL
) CFRelease(serviceName
);
627 SCPrint(TRUE
, stdout
, CFSTR("%s\n"), SCErrorString(SCError()));
631 _prefs_changed
= TRUE
;
632 } else if (strcmp(command
, "order") == 0) {
640 services
= SCNetworkSetCopyServices(net_set
);
641 nServices
= CFArrayGetCount(services
);
645 SCPrint(TRUE
, stdout
, CFSTR("order not specified\n"));
649 if (net_set
== NULL
) {
650 SCPrint(TRUE
, stdout
, CFSTR("set not selected\n"));
659 newIndex
= strtol(str
, &end
, 10);
660 if ((*str
!= '\0') && (*end
== '\0') && (errno
== 0)) {
661 if ((newIndex
> 0) && (newIndex
<= nServices
)) {
663 CFMutableArrayRef newOrder
;
665 CFStringRef serviceID
= SCNetworkServiceGetServiceID(net_service
);
667 order
= SCNetworkSetGetServiceOrder(net_set
);
669 newOrder
= CFArrayCreateMutable(NULL
, 0, &kCFTypeArrayCallBacks
);
671 newOrder
= CFArrayCreateMutableCopy(NULL
, 0, order
);
674 curIndex
= CFArrayGetFirstIndexOfValue(newOrder
,
675 CFRangeMake(0, CFArrayGetCount(newOrder
)),
677 if (curIndex
!= kCFNotFound
) {
678 CFArrayRemoveValueAtIndex(newOrder
, curIndex
);
681 if (newIndex
<= CFArrayGetCount(newOrder
)) {
682 CFArrayInsertValueAtIndex(newOrder
, newIndex
- 1, serviceID
);
684 CFArrayAppendValue(newOrder
, serviceID
);
687 ok
= SCNetworkSetSetServiceOrder(net_set
, newOrder
);
690 SCPrint(TRUE
, stdout
, CFSTR("%s\n"), SCErrorString(SCError()));
694 _prefs_changed
= TRUE
;
696 SCPrint(TRUE
, stdout
, CFSTR("set order to what?\n"));
700 SCPrint(TRUE
, stdout
, CFSTR("set what?\n"));
703 } else if (strcmp(command
, "rank") == 0) {
704 SCNetworkServicePrimaryRank rank
= kSCNetworkServicePrimaryRankDefault
;
705 SCNetworkServiceRef service
= (argc
< 2) ? net_service
: NULL
;
708 SCPrint(TRUE
, stdout
, CFSTR("rank not specified\n"));
712 if (strlen(argv
[0]) > 0) {
713 if (strcasecmp(argv
[0], "Never") == 0) {
714 rank
= kSCNetworkServicePrimaryRankNever
;
715 } else if ((service
!= net_service
) && (strcasecmp(argv
[0], "First") == 0)) {
716 rank
= kSCNetworkServicePrimaryRankFirst
;
717 } else if ((service
!= net_service
) && (strcasecmp(argv
[0], "Last") == 0)) {
718 rank
= kSCNetworkServicePrimaryRankLast
;
720 SCPrint(TRUE
, stdout
, CFSTR("rank not valid\n"));
727 if (service
== NULL
) {
728 CFStringRef serviceID
;
729 SCDynamicStoreRef store
;
731 store
= SCDynamicStoreCreate(NULL
,
732 CFSTR("scutil (set primary rank)"),
735 serviceID
= SCNetworkServiceGetServiceID(net_service
);
736 service
= _SCNetworkServiceCopyActive(store
, serviceID
);
743 ok
= SCNetworkServiceSetPrimaryRank(service
, rank
);
744 if (service
!= net_service
) CFRelease(service
);
746 if (service
== net_service
) _prefs_changed
= TRUE
;
748 SCPrint(TRUE
, stdout
, CFSTR("%s\n"), SCErrorString(SCError()));
752 SCPrint(TRUE
, stdout
, CFSTR("set what?\n"));
761 __show_service_interface(SCNetworkServiceRef service
, const char *prefix
)
763 CFStringRef description
;
764 SCNetworkInterfaceRef interface
;
766 interface
= SCNetworkServiceGetInterface(service
);
767 if (interface
== NULL
) {
771 description
= _interface_description(interface
);
772 SCPrint(TRUE
, stdout
, CFSTR("%s%@\n"), prefix
, description
);
773 CFRelease(description
);
779 __show_service_protocols(SCNetworkServiceRef service
, const char *prefix
, Boolean skipEmpty
)
783 CFArrayRef protocols
;
785 protocols
= SCNetworkServiceCopyProtocols(service
);
786 if (protocols
== NULL
) {
790 n
= CFArrayGetCount(protocols
);
792 CFMutableArrayRef sorted
;
794 sorted
= CFArrayCreateMutableCopy(NULL
, 0, protocols
);
795 CFArraySortValues(sorted
,
799 CFRelease(protocols
);
803 for (i
= 0; i
< n
; i
++) {
804 CFStringRef description
;
805 SCNetworkProtocolRef protocol
;
807 protocol
= CFArrayGetValueAtIndex(protocols
, i
);
808 description
= _protocol_description(protocol
, skipEmpty
);
809 if (description
!= NULL
) {
810 CFStringRef protocolType
;
812 protocolType
= SCNetworkProtocolGetProtocolType(protocol
);
813 SCPrint(TRUE
, stdout
,
814 CFSTR("%s%@%*s : %@\n"),
817 sizeof("Interface") - CFStringGetLength(protocolType
) - 1,
820 CFRelease(description
);
824 CFRelease(protocols
);
831 show_service(int argc
, char **argv
)
833 SCNetworkInterfaceRef interface
;
834 CFArrayRef protocols
;
835 SCNetworkServiceRef service
;
836 CFStringRef serviceName
;
837 SCNetworkServicePrimaryRank serviceRank
;
840 service
= _find_service(argv
[0]);
842 if (net_service
!= NULL
) {
843 service
= net_service
;
845 SCPrint(TRUE
, stdout
, CFSTR("service not selected\n"));
850 if (service
== NULL
) {
854 SCPrint(TRUE
, stdout
, CFSTR("service id = %@\n"), SCNetworkServiceGetServiceID(service
));
856 serviceName
= SCNetworkServiceGetName(service
);
857 SCPrint(TRUE
, stdout
, CFSTR("name = %@\n"),
858 (serviceName
!= NULL
) ? serviceName
: CFSTR(""));
860 serviceRank
= SCNetworkServiceGetPrimaryRank(service
);
861 switch (serviceRank
) {
862 case kSCNetworkServicePrimaryRankDefault
:
865 case kSCNetworkServicePrimaryRankFirst
:
866 SCPrint(TRUE
, stdout
, CFSTR("primary rank = FIRST\n"));
868 case kSCNetworkServicePrimaryRankLast
:
869 SCPrint(TRUE
, stdout
, CFSTR("primary rank = LAST\n"));
871 case kSCNetworkServicePrimaryRankNever
:
872 SCPrint(TRUE
, stdout
, CFSTR("primary rank = NEVER\n"));
875 SCPrint(TRUE
, stdout
, CFSTR("primary rank = %d\n"), serviceRank
);
879 interface
= SCNetworkServiceGetInterface(service
);
880 if (interface
!= NULL
) {
881 CFStringRef interfaceName
;
883 interfaceName
= SCNetworkInterfaceGetLocalizedDisplayName(interface
);
884 if (interfaceName
!= NULL
) {
885 CFRetain(interfaceName
);
887 interfaceName
= _interface_description(interface
);
889 if (interfaceName
!= NULL
) {
890 SCPrint(TRUE
, stdout
, CFSTR("interface = %@\n"), interfaceName
);
891 CFRelease(interfaceName
);
894 SCPrint(TRUE
, stdout
, CFSTR("\n No interface!\n\n"));
897 protocols
= SCNetworkServiceCopyProtocols(service
);
898 if (protocols
!= NULL
) {
901 n
= CFArrayGetCount(protocols
);
903 CFMutableArrayRef sorted
;
905 sorted
= CFArrayCreateMutableCopy(NULL
, 0, protocols
);
906 CFArraySortValues(sorted
,
910 CFRelease(protocols
);
917 SCPrint(TRUE
, stdout
, CFSTR("configured protocols = "));
918 for (i
= 0; i
< n
; i
++) {
919 SCNetworkProtocolRef protocol
;
921 protocol
= CFArrayGetValueAtIndex(protocols
, i
);
922 SCPrint(TRUE
, stdout
, CFSTR("%s%@"),
923 (i
== 0) ? "" : ", ",
924 SCNetworkProtocolGetProtocolType(protocol
));
926 SCPrint(TRUE
, stdout
, CFSTR("\n"));
928 __show_service_protocols(service
, " ", FALSE
);
930 SCPrint(TRUE
, stdout
, CFSTR("no configured protocols\n"));
933 CFRelease(protocols
);
937 SCPrint(TRUE
, stdout
, CFSTR("\n%@\n"), service
);
946 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
)),
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%2d: %@%-*s (%@)%s\n"),
1000 ((net_service
!= NULL
) && CFEqual(service
, net_service
)) ? '>' : ' ',
1003 30 - CFStringGetLength(serviceName
),
1006 SCNetworkServiceGetEnabled(service
) ? "" : " *DISABLED*");
1008 __show_service_interface(service
, " Interface : ");
1009 __show_service_protocols(service
, " ", TRUE
);