xref: /illumos-gate/usr/src/cmd/cmd-inet/usr.sbin/snoop/snoop_bparam.c (revision 2aeafac3612e19716bf8164f89c3c9196342979c)
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 (c) 1991, 1999 by Sun Microsystems, Inc.
24  * All rights reserved.
25  */
26 
27 #ident	"%Z%%M%	%I%	%E% SMI"	/* SunOS	*/
28 
29 #include <sys/types.h>
30 #include <sys/errno.h>
31 #include <setjmp.h>
32 #include <string.h>
33 
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"
43 
44 extern char *dlc_header;
45 extern jmp_buf xdr_err;
46 
47 static void show_address(char *);
48 static char *sum_address(void);
49 
50 static char *procnames_short[] = {
51 	"Null",		/*  0 */
52 	"WHOAMI?",	/*  1 */
53 	"GETFILE",	/*  2 */
54 };
55 
56 static char *procnames_long[] = {
57 	"Null procedure",	/*  0 */
58 	"Who am I?",		/*  1 */
59 	"Get file name",	/*  2 */
60 };
61 
62 #define	MAXPROC	2
63 
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;
69 {
70 	char *line;
71 	char buff[MAX_PATH_LEN + 1];
72 	char buff2[MAX_MACHINE_NAME + 1];
73 
74 	if (proc < 0 || proc > MAXPROC)
75 		return;
76 
77 	if (flags & F_SUM) {
78 		if (setjmp(xdr_err)) {
79 			return;
80 		}
81 
82 		line = get_sum_line();
83 
84 		if (type == CALL) {
85 			(void) sprintf(line,
86 				"BPARAM C %s",
87 				procnames_short[proc]);
88 			line += strlen(line);
89 
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;
102 			}
103 
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;
126 			}
127 		}
128 	}
129 
130 	if (flags & F_DTAIL) {
131 		show_header("BPARAM:  ", "Boot Parameters", len);
132 		show_space();
133 		if (setjmp(xdr_err)) {
134 			return;
135 		}
136 		(void) sprintf(get_line(0, 0),
137 			"Proc = %d (%s)",
138 			proc, procnames_long[proc]);
139 
140 		if (type == CALL) {
141 			switch (proc) {
142 			case BOOTPARAMPROC_WHOAMI:
143 				show_address("Client address");
144 				break;
145 
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;
152 			}
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;
162 
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;
170 			}
171 		}
172 
173 		show_trailer();
174 	}
175 }
176 
177 static char *
178 sum_address()
179 {
180 	struct in_addr host;
181 	extern char *inet_ntoa();
182 	int atype;
183 
184 	atype = getxdr_u_long();
185 	if (atype != IP_ADDR_TYPE)
186 		return ("?");
187 
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();
192 
193 	return (inet_ntoa(host));
194 }
195 
196 static void
197 show_address(label)
198 	char *label;
199 {
200 	struct in_addr host;
201 	extern char *inet_ntoa();
202 	int atype;
203 
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();
210 
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)");
219 	}
220 }
221