]>
Commit | Line | Data |
---|---|---|
1815bff5 A |
1 | /* |
2 | * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
6 | * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights | |
7 | * Reserved. This file contains Original Code and/or Modifications of | |
8 | * Original Code as defined in and that are subject to the Apple Public | |
9 | * Source License Version 1.0 (the 'License'). You may not use this file | |
10 | * except in compliance with the License. Please obtain a copy of the | |
11 | * License at http://www.apple.com/publicsource and read it before using | |
12 | * this file. | |
13 | * | |
14 | * The Original Code and all software distributed under the License are | |
15 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
16 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, | |
17 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
18 | * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the | |
19 | * License for the specific language governing rights and limitations | |
20 | * under the License." | |
21 | * | |
22 | * @APPLE_LICENSE_HEADER_END@ | |
23 | */ | |
24 | #import "bootstrap.h" | |
25 | ||
26 | #import <mach.h> | |
27 | #import <stdarg.h> | |
28 | #import <stdio.h> | |
29 | #import <sys/boolean.h> | |
30 | ||
31 | #define NELEM(x) (sizeof(x)/sizeof(x[0])) | |
32 | #define LAST_ELEMENT(x) ((x)[NELEM(x)-1]) | |
33 | ||
34 | print(const char *format, ...) | |
35 | { | |
36 | va_list ap; | |
37 | ||
38 | va_start(ap, format); | |
39 | vfprintf(stderr, format, ap); | |
40 | fprintf(stderr, "\n"); | |
41 | va_end(ap); | |
42 | } | |
43 | ||
44 | error(const char *format, ...) | |
45 | { | |
46 | va_list ap; | |
47 | ||
48 | va_start(ap, format); | |
49 | fprintf(stderr, "ERROR: "); | |
50 | vfprintf(stderr, format, ap); | |
51 | fprintf(stderr, "\n"); | |
52 | va_end(ap); | |
53 | } | |
54 | ||
55 | ||
56 | main() | |
57 | { | |
58 | kern_return_t result; | |
59 | port_t bootstrap_port; | |
60 | name_array_t service_names; | |
61 | unsigned service_cnt, server_cnt, service_active_cnt; | |
62 | name_array_t server_names; | |
63 | boolean_t *service_actives; | |
64 | int i; | |
65 | ||
66 | result = task_get_bootstrap_port(task_self(), &bootstrap_port); | |
67 | if (result != KERN_SUCCESS) { | |
68 | error("Couldn't get bootstrap port: %d", result); | |
69 | exit(1); | |
70 | } | |
71 | if (bootstrap_port == PORT_NULL) { | |
72 | error("Invalid bootstrap port"); | |
73 | exit(1); | |
74 | } | |
75 | ||
76 | result = bootstrap_info(bootstrap_port, &service_names, &service_cnt, | |
77 | &server_names, &server_cnt, &service_actives, &service_active_cnt); | |
78 | if (result != BOOTSTRAP_SUCCESS) | |
79 | error("info failed: %d", result); | |
80 | else { | |
81 | for (i = 0; i < service_cnt; i++) | |
82 | print("Name: %-15s Server: %-15s Active: %-4s", | |
83 | service_names[i], | |
84 | server_names[i][0] == '\0' ? "Unknown" : server_names[i], | |
85 | service_actives[i] ? "Yes" : "No"); | |
86 | } | |
87 | ||
88 | exit(0); | |
89 | } | |
90 | ||
91 | ||
92 | ||
93 |