dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / cmd / cmd-inet / usr.sbin / snoop / snoop_bparam.c
blob5d1be717bf31d4dee7fdabb31dcf0dc7164f0c62
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 (c) 1991, 1999 by Sun Microsystems, Inc.
24 * All rights reserved.
27 #ident "%Z%%M% %I% %E% SMI" /* SunOS */
29 #include <sys/types.h>
30 #include <sys/errno.h>
31 #include <setjmp.h>
32 #include <string.h>
34 #include <netinet/in.h>
35 #include <rpc/types.h>
36 #include <rpc/rpc.h>
37 #include <rpc/xdr.h>
38 #include <rpc/auth.h>
39 #include <rpc/clnt.h>
40 #include <rpc/rpc_msg.h>
41 #include <rpcsvc/bootparam_prot.h>
42 #include "snoop.h"
44 extern char *dlc_header;
45 extern jmp_buf xdr_err;
47 static void show_address(char *);
48 static char *sum_address(void);
50 static char *procnames_short[] = {
51 "Null", /* 0 */
52 "WHOAMI?", /* 1 */
53 "GETFILE", /* 2 */
56 static char *procnames_long[] = {
57 "Null procedure", /* 0 */
58 "Who am I?", /* 1 */
59 "Get file name", /* 2 */
62 #define MAXPROC 2
64 void
65 interpret_bparam(flags, type, xid, vers, proc, data, len)
66 int flags, type, xid, vers, proc;
67 char *data;
68 int len;
70 char *line;
71 char buff[MAX_PATH_LEN + 1];
72 char buff2[MAX_MACHINE_NAME + 1];
74 if (proc < 0 || proc > MAXPROC)
75 return;
77 if (flags & F_SUM) {
78 if (setjmp(xdr_err)) {
79 return;
82 line = get_sum_line();
84 if (type == CALL) {
85 (void) sprintf(line,
86 "BPARAM C %s",
87 procnames_short[proc]);
88 line += strlen(line);
90 switch (proc) {
91 case BOOTPARAMPROC_WHOAMI:
92 (void) sprintf(line, " %s",
93 sum_address());
94 break;
95 case BOOTPARAMPROC_GETFILE:
96 (void) getxdr_string(buff,
97 MAX_MACHINE_NAME);
98 (void) sprintf(line, " %s",
99 getxdr_string(buff,
100 MAX_FILEID));
101 break;
104 check_retransmit(line, xid);
105 } else {
106 (void) sprintf(line, "BPARAM R %s ",
107 procnames_short[proc]);
108 line += strlen(line);
109 switch (proc) {
110 case BOOTPARAMPROC_WHOAMI:
111 (void) getxdr_string(buff,
112 MAX_MACHINE_NAME);
113 (void) getxdr_string(buff2,
114 MAX_MACHINE_NAME);
115 (void) sprintf(line, "%s in %s",
116 buff, buff2);
117 break;
118 case BOOTPARAMPROC_GETFILE:
119 (void) getxdr_string(buff,
120 MAX_MACHINE_NAME);
121 (void) sum_address();
122 (void) sprintf(line, "File=%s",
123 getxdr_string(buff,
124 MAX_PATH_LEN));
125 break;
130 if (flags & F_DTAIL) {
131 show_header("BPARAM: ", "Boot Parameters", len);
132 show_space();
133 if (setjmp(xdr_err)) {
134 return;
136 (void) sprintf(get_line(0, 0),
137 "Proc = %d (%s)",
138 proc, procnames_long[proc]);
140 if (type == CALL) {
141 switch (proc) {
142 case BOOTPARAMPROC_WHOAMI:
143 show_address("Client address");
144 break;
146 case BOOTPARAMPROC_GETFILE:
147 (void) showxdr_string(MAX_MACHINE_NAME,
148 "Hostname = %s");
149 (void) showxdr_string(MAX_FILEID,
150 "File = %s");
151 break;
153 } else {
154 switch (proc) {
155 case BOOTPARAMPROC_WHOAMI:
156 (void) showxdr_string(MAX_MACHINE_NAME,
157 "Client name = %s");
158 (void) showxdr_string(MAX_MACHINE_NAME,
159 "Domain name = %s");
160 show_address("Router addr");
161 break;
163 case BOOTPARAMPROC_GETFILE:
164 (void) showxdr_string(MAX_MACHINE_NAME,
165 "Server name = %s");
166 show_address("Server addr");
167 (void) showxdr_string(MAX_PATH_LEN,
168 "Server file = %s");
169 break;
173 show_trailer();
177 static char *
178 sum_address()
180 struct in_addr host;
181 extern char *inet_ntoa();
182 int atype;
184 atype = getxdr_u_long();
185 if (atype != IP_ADDR_TYPE)
186 return ("?");
188 host.S_un.S_un_b.s_b1 = getxdr_char();
189 host.S_un.S_un_b.s_b2 = getxdr_char();
190 host.S_un.S_un_b.s_b3 = getxdr_char();
191 host.S_un.S_un_b.s_b4 = getxdr_char();
193 return (inet_ntoa(host));
196 static void
197 show_address(label)
198 char *label;
200 struct in_addr host;
201 extern char *inet_ntoa();
202 int atype;
204 atype = getxdr_u_long();
205 if (atype == IP_ADDR_TYPE) {
206 host.S_un.S_un_b.s_b1 = getxdr_char();
207 host.S_un.S_un_b.s_b2 = getxdr_char();
208 host.S_un.S_un_b.s_b3 = getxdr_char();
209 host.S_un.S_un_b.s_b4 = getxdr_char();
211 (void) sprintf(get_line(0, 0),
212 "%s = %s (%s)",
213 label,
214 inet_ntoa(host),
215 addrtoname(AF_INET, &host));
216 } else {
217 (void) sprintf(get_line(0, 0),
218 "Router addr = ? (type not known)");