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
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]
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)
37 #include <time.h> /* required by librsc.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();
52 ADM_Process_show(int argc
, char *argv
[])
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]"));
69 while (ADM_Get_Next_Var(oldVar
, newVar
, 128) == 0) {
74 ADM_Show_Var(argv
[2]);
79 ADM_Process_show_network()
82 struct timespec Timeout
;
83 dp_get_network_cfg_r_t
*netParams
;
87 Message
.type
= DP_GET_NETWORK_CFG
;
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."));
105 /* Include this if we want to display the IP mode */
106 (void) printf("%s %s\r\n",
107 gettext("SC network configuration is:"),
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:"),
115 (void) printf("%s %s\r\n", gettext("Gateway address:"),
116 netParams
->ipGateway
);
117 (void) printf("%s %s\r\n", gettext("Netmask:"),
119 (void) printf("%s %s\r\n", gettext("Ethernet address:"),
128 *ADM_Get_Var(char *Variable
)
131 struct timespec Timeout
;
136 Message
.type
= DP_GET_CFGVAR
;
137 Message
.len
= strlen(Variable
) + 1; /* + 1 for string termination */
138 if (Message
.len
> DP_MAX_MSGLEN
-4) {
143 Message
.data
= Variable
;
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
);
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
)]);
168 ADM_Show_Var(char *Variable
)
172 varValue
= ADM_Get_Var(Variable
);
173 (void) printf("%s=\"%s\"\n", Variable
, varValue
);
174 (void) fflush(stdout
);
178 ADM_Get_Next_Var(char *oldVar
, char *newVar
, int maxSize
)
181 struct timespec Timeout
;
185 Message
.type
= DP_GET_CFGVAR_NAME
;
189 Message
.len
= strlen(oldVar
) + 1; /* + 1 for string */
192 if (Message
.len
> DP_MAX_MSGLEN
-4) {
197 Message
.data
= oldVar
;
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 */
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
);
223 (void) fprintf(stderr
, "\n%s\n\n",
224 gettext("scadm: command line too long"));