1 /*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
8 *
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
13 *
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 *
20 * CDDL HEADER END
21 */
22 /*
23 * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 */
26 #pragma ident "%Z%%M% %I% %E% SMI"
27
28 /*
29 * This program extracts network interface parameters from the information
30 * passed to the kernel from the bootstrap (i.e. as properties of /chosen).
31 *
32 * Returns:
33 * = 0 - success
34 * > 0 - error (see exit codes below)
35 */
36
37 #include <libintl.h>
38 #include <locale.h>
39 #include <stdio.h>
40 #include <strings.h>
41 #include <parseURL.h>
42 #include <wanbootutil.h>
43 #include <bootinfo.h>
44
45 /*
46 * Exit codes:
47 */
48 #define NETBOOTINFO_SUCCESS 0
49 #define NETBOOTINFO_UNKNOWN_PARAM 1
50 #define NETBOOTINFO_BOOTINFO_ERR 2
51 #define NETBOOTINFO_USAGE 3
52
53 int
main(int argc,char ** argv)54 main(int argc, char **argv)
55 {
56 int i;
57
58 /*
59 * Do the necessary magic for localization support.
60 */
61 (void) setlocale(LC_ALL, "");
62 #if !defined(TEXT_DOMAIN)
63 #define TEXT_DOMAIN "SYS_TEST"
64 #endif /* !defined(TEXT_DOMAIN) */
65 (void) textdomain(TEXT_DOMAIN);
66
67 /*
68 * Initialize program name for use by wbku_printerr().
69 */
70 wbku_errinit(argv[0]);
71
72 /*
73 * Check usage is legal.
74 */
75 if (argc < 2) {
76 (void) fprintf(stderr,
77 gettext("Usage: %s param [ param ... ]\n"), argv[0]);
78 return (NETBOOTINFO_USAGE);
79 }
80
81 /*
82 * Initialize bootinfo.
83 */
84 if (!bootinfo_init()) {
85 wbku_printerr("Internal error\n");
86 return (NETBOOTINFO_BOOTINFO_ERR);
87 }
88
89 /*
90 * Retrieve and print parameter value(s).
91 */
92 for (i = 1; i < argc; ++i) {
93 char *name = argv[i];
94 char valbuf[URL_MAX_STRLEN];
95 size_t vallen = sizeof (valbuf);
96
97 /*
98 * Call get_bootinfo() to fetch it's value.
99 */
100 switch (bootinfo_get(name, valbuf, &vallen, NULL)) {
101 case BI_E_SUCCESS:
102 break;
103
104 case BI_E_NOVAL:
105 (void) strlcpy(valbuf, "none", sizeof (valbuf));
106 break;
107
108 case BI_E_ILLNAME:
109 wbku_printerr("Unknown parameter %s\n", name);
110 bootinfo_end();
111 return (NETBOOTINFO_UNKNOWN_PARAM);
112
113 default:
114 wbku_printerr("Internal error\n");
115 bootinfo_end();
116 return (NETBOOTINFO_BOOTINFO_ERR);
117 }
118 (void) printf("%s\n", valbuf);
119 }
120 bootinfo_end();
121
122 return (NETBOOTINFO_SUCCESS);
123 }
124