8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / cmd / scadm / sparc / mpxu / common / show.c
blob18c2dbbf5a8277df8051233d07d919c8482978a5
1 /*
2 * CDDL HEADER START
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.
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.
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]
20 * CDDL HEADER END
23 * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
30 * show.c: support for scadm show <variable> option (to show the value of
31 * a service processor NV variable)
34 #include <libintl.h>
35 #include <stdio.h>
36 #include <string.h>
37 #include <time.h> /* required by librsc.h */
39 #include "librsc.h"
40 #include "adm.h"
44 char *ADM_Get_Var(char *Variable);
46 static void ADM_Show_Var(char *Variable);
47 static int ADM_Get_Next_Var(char *oldVar, char *newVar, int maxSize);
48 static void command_line();
51 void
52 ADM_Process_show(int argc, char *argv[])
54 char *oldVar;
55 static char newVar[128];
58 if ((argc != 2) && (argc != 3)) {
59 (void) fprintf(stderr, "\n%s\n\n",
60 gettext("USAGE: scadm show [variable]"));
61 exit(-1);
64 ADM_Start();
66 if (argc == 2) {
67 oldVar = NULL;
68 newVar[0] = 0x0;
69 while (ADM_Get_Next_Var(oldVar, newVar, 128) == 0) {
70 ADM_Show_Var(newVar);
71 oldVar = newVar;
73 } else {
74 ADM_Show_Var(argv[2]);
78 void
79 ADM_Process_show_network()
81 rscp_msg_t Message;
82 struct timespec Timeout;
83 dp_get_network_cfg_r_t *netParams;
85 ADM_Start();
87 Message.type = DP_GET_NETWORK_CFG;
88 Message.len = 0;
89 Message.data = NULL;
91 ADM_Send(&Message);
93 Timeout.tv_nsec = 0;
94 Timeout.tv_sec = ADM_TIMEOUT;
95 ADM_Recv(&Message, &Timeout,
96 DP_GET_NETWORK_CFG_R, sizeof (dp_get_network_cfg_r_t));
98 netParams = (dp_get_network_cfg_r_t *)Message.data;
100 /* Print the network configuration */
101 if (netParams->status != 0) {
102 (void) printf("%s \r\n", gettext("SC ethernet is disabled."));
103 } else {
104 #if 0
105 /* Include this if we want to display the IP mode */
106 (void) printf("%s %s\r\n",
107 gettext("SC network configuration is:"),
108 netParams->ipMode);
109 #endif
110 if (strcmp(netParams->ipMode, "dhcp") == 0)
111 (void) printf("%s %s\r\n", gettext("DHCP server:"),
112 netParams->ipDHCPServer);
113 (void) printf("%s %s\r\n", gettext("IP Address:"),
114 netParams->ipAddr);
115 (void) printf("%s %s\r\n", gettext("Gateway address:"),
116 netParams->ipGateway);
117 (void) printf("%s %s\r\n", gettext("Netmask:"),
118 netParams->ipMask);
119 (void) printf("%s %s\r\n", gettext("Ethernet address:"),
120 netParams->ethAddr);
123 ADM_Free(&Message);
127 char
128 *ADM_Get_Var(char *Variable)
130 rscp_msg_t Message;
131 struct timespec Timeout;
132 char *varValue;
134 varValue = NULL;
136 Message.type = DP_GET_CFGVAR;
137 Message.len = strlen(Variable) + 1; /* + 1 for string termination */
138 if (Message.len > DP_MAX_MSGLEN-4) {
139 command_line();
140 exit(-1);
143 Message.data = Variable;
144 ADM_Send(&Message);
146 Timeout.tv_nsec = 0;
147 Timeout.tv_sec = ADM_TIMEOUT;
148 ADM_Recv(&Message, &Timeout,
149 DP_GET_CFGVAR_R, sizeof (dp_get_cfgvar_r_t));
151 if (*(int *)Message.data != 0) {
152 (void) fprintf(stderr, "\n%s - \"%s\"\n\n",
153 gettext("scadm: invalid variable"), Variable);
154 exit(-1);
157 /* show variable setting */
158 /* The variable setting is right after the Status of the message */
159 varValue = (char *)(&((char *)Message.data)[
160 sizeof (dp_get_cfgvar_r_t)]);
162 ADM_Free(&Message);
164 return (varValue);
167 static void
168 ADM_Show_Var(char *Variable)
170 char *varValue;
172 varValue = ADM_Get_Var(Variable);
173 (void) printf("%s=\"%s\"\n", Variable, varValue);
174 (void) fflush(stdout);
177 static int
178 ADM_Get_Next_Var(char *oldVar, char *newVar, int maxSize)
180 rscp_msg_t Message;
181 struct timespec Timeout;
182 char *var;
185 Message.type = DP_GET_CFGVAR_NAME;
186 if (oldVar == NULL)
187 Message.len = 0;
188 else
189 Message.len = strlen(oldVar) + 1; /* + 1 for string */
190 /* termination */
192 if (Message.len > DP_MAX_MSGLEN-4) {
193 command_line();
194 exit(-1);
197 Message.data = oldVar;
198 ADM_Send(&Message);
200 Timeout.tv_nsec = 0;
201 Timeout.tv_sec = ADM_TIMEOUT;
202 ADM_Recv(&Message, &Timeout,
203 DP_GET_CFGVAR_NAME_R, sizeof (dp_get_cfgvar_name_r_t));
204 if (*(int *)Message.data != 0) {
205 /* Last variable read */
206 return (-1);
209 /* The variable is right after the Status of the message */
210 var = (char *)(&((char *)Message.data)[
211 sizeof (dp_get_cfgvar_name_r_t)]);
212 (void) strncpy(newVar, var, maxSize);
214 ADM_Free(&Message);
216 return (0);
220 static void
221 command_line()
223 (void) fprintf(stderr, "\n%s\n\n",
224 gettext("scadm: command line too long"));