xref: /titanic_50/usr/src/cmd/cmd-inet/usr.sbin/snoop/snoop_pmap.c (revision c64d0c7c2b822e28df7036ee627f438587d05037)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate  * with the License.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate  * and limitations under the License.
137c478bd9Sstevel@tonic-gate  *
147c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * CDDL HEADER END
217c478bd9Sstevel@tonic-gate  */
227c478bd9Sstevel@tonic-gate /*
237c478bd9Sstevel@tonic-gate  * Copyright (c) 1991, 1999 by Sun Microsystems, Inc.
247c478bd9Sstevel@tonic-gate  * All rights reserved.
257c478bd9Sstevel@tonic-gate  */
2678fb3df6SMarcel Telka /*
2778fb3df6SMarcel Telka  * Copyright 2014 Nexenta Systems, Inc.  All rights reserved.
2878fb3df6SMarcel Telka  */
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate #include <sys/types.h>
317c478bd9Sstevel@tonic-gate #include <sys/errno.h>
327c478bd9Sstevel@tonic-gate #include <setjmp.h>
337c478bd9Sstevel@tonic-gate #include <sys/tiuser.h>
347c478bd9Sstevel@tonic-gate #include <string.h>
357c478bd9Sstevel@tonic-gate 
367c478bd9Sstevel@tonic-gate #include <rpc/types.h>
377c478bd9Sstevel@tonic-gate #include <rpc/xdr.h>
387c478bd9Sstevel@tonic-gate #include <rpc/auth.h>
397c478bd9Sstevel@tonic-gate #include <rpc/clnt.h>
407c478bd9Sstevel@tonic-gate #include <rpc/rpc_msg.h>
417c478bd9Sstevel@tonic-gate #include <rpc/pmap_prot.h>
427c478bd9Sstevel@tonic-gate #include "snoop.h"
437c478bd9Sstevel@tonic-gate 
447c478bd9Sstevel@tonic-gate /*
457c478bd9Sstevel@tonic-gate  * Number of bytes to display from a string (address, netid, etc.).
467c478bd9Sstevel@tonic-gate  */
477c478bd9Sstevel@tonic-gate #define	MAXSTRINGLEN	64
487c478bd9Sstevel@tonic-gate 
497c478bd9Sstevel@tonic-gate extern char *dlc_header;
507c478bd9Sstevel@tonic-gate extern jmp_buf xdr_err;
517c478bd9Sstevel@tonic-gate 
527c478bd9Sstevel@tonic-gate static void interpret_pmap_2(int, int, int, int, int, char *, int);
537c478bd9Sstevel@tonic-gate static void interpret_pmap_4(int, int, int, int, int, char *, int);
547c478bd9Sstevel@tonic-gate static void stash_callit(ulong_t, int, int, int, int);
557c478bd9Sstevel@tonic-gate 
567c478bd9Sstevel@tonic-gate void
interpret_pmap(flags,type,xid,vers,proc,data,len)577c478bd9Sstevel@tonic-gate interpret_pmap(flags, type, xid, vers, proc, data, len)
587c478bd9Sstevel@tonic-gate 	int flags, type, xid, vers, proc;
597c478bd9Sstevel@tonic-gate 	char *data;
607c478bd9Sstevel@tonic-gate 	int len;
617c478bd9Sstevel@tonic-gate {
627c478bd9Sstevel@tonic-gate 	switch (vers) {
637c478bd9Sstevel@tonic-gate 	case 2:	interpret_pmap_2(flags, type, xid, vers, proc, data, len);
647c478bd9Sstevel@tonic-gate 		break;
657c478bd9Sstevel@tonic-gate 
667c478bd9Sstevel@tonic-gate 	/* Version 3 is a subset of version 4 */
677c478bd9Sstevel@tonic-gate 	case 3:
687c478bd9Sstevel@tonic-gate 	case 4:	interpret_pmap_4(flags, type, xid, vers, proc, data, len);
697c478bd9Sstevel@tonic-gate 		break;
707c478bd9Sstevel@tonic-gate 	}
717c478bd9Sstevel@tonic-gate }
727c478bd9Sstevel@tonic-gate 
737c478bd9Sstevel@tonic-gate void show_pmap();
747c478bd9Sstevel@tonic-gate char *sum_pmaplist();
757c478bd9Sstevel@tonic-gate void show_pmaplist();
767c478bd9Sstevel@tonic-gate 
777c478bd9Sstevel@tonic-gate static char *procnames_short_2[] = {
787c478bd9Sstevel@tonic-gate 	"Null",		/* 0 */
797c478bd9Sstevel@tonic-gate 	"SET",		/* 1 */
807c478bd9Sstevel@tonic-gate 	"UNSET",	/* 2 */
817c478bd9Sstevel@tonic-gate 	"GETPORT",	/* 3 */
827c478bd9Sstevel@tonic-gate 	"DUMP",		/* 4 */
837c478bd9Sstevel@tonic-gate 	"CALLIT",	/* 5 */
847c478bd9Sstevel@tonic-gate };
857c478bd9Sstevel@tonic-gate 
867c478bd9Sstevel@tonic-gate static char *procnames_long_2[] = {
877c478bd9Sstevel@tonic-gate 	"Null procedure",	/* 0 */
887c478bd9Sstevel@tonic-gate 	"Set port",		/* 1 */
897c478bd9Sstevel@tonic-gate 	"Unset port",		/* 2 */
907c478bd9Sstevel@tonic-gate 	"Get port number",	/* 3 */
917c478bd9Sstevel@tonic-gate 	"Dump the mappings",	/* 4 */
927c478bd9Sstevel@tonic-gate 	"Indirect call",	/* 5 */
937c478bd9Sstevel@tonic-gate };
947c478bd9Sstevel@tonic-gate 
957c478bd9Sstevel@tonic-gate #define	MAXPROC_2	5
967c478bd9Sstevel@tonic-gate 
977c478bd9Sstevel@tonic-gate void
interpret_pmap_2(flags,type,xid,vers,proc,data,len)987c478bd9Sstevel@tonic-gate interpret_pmap_2(flags, type, xid, vers, proc, data, len)
997c478bd9Sstevel@tonic-gate 	int flags, type, xid, vers, proc;
1007c478bd9Sstevel@tonic-gate 	char *data;
1017c478bd9Sstevel@tonic-gate 	int len;
1027c478bd9Sstevel@tonic-gate {
1037c478bd9Sstevel@tonic-gate 	char *line;
1047c478bd9Sstevel@tonic-gate 	unsigned port, proto;
1057c478bd9Sstevel@tonic-gate 	unsigned iprog, ivers, iproc, ilen;
1067c478bd9Sstevel@tonic-gate 	extern int pi_frame;
1077c478bd9Sstevel@tonic-gate 	struct cache_struct *x, *find_callit();
1087c478bd9Sstevel@tonic-gate 	int trailer_done = 0;
1097c478bd9Sstevel@tonic-gate 
1107c478bd9Sstevel@tonic-gate 	if (proc < 0 || proc > MAXPROC_2)
1117c478bd9Sstevel@tonic-gate 		return;
1127c478bd9Sstevel@tonic-gate 
1137c478bd9Sstevel@tonic-gate 	if (proc == PMAPPROC_CALLIT) {
1147c478bd9Sstevel@tonic-gate 		if (type == CALL) {
1157c478bd9Sstevel@tonic-gate 			iprog = getxdr_u_long();
1167c478bd9Sstevel@tonic-gate 			ivers = getxdr_u_long();
1177c478bd9Sstevel@tonic-gate 			iproc = getxdr_u_long();
11878fb3df6SMarcel Telka 			stash_callit(xid, pi_frame, iprog, ivers, iproc);
1197c478bd9Sstevel@tonic-gate 		} else {
1207c478bd9Sstevel@tonic-gate 			x = find_callit(xid);
1217c478bd9Sstevel@tonic-gate 		}
1227c478bd9Sstevel@tonic-gate 	}
1237c478bd9Sstevel@tonic-gate 
1247c478bd9Sstevel@tonic-gate 	if (flags & F_SUM) {
1257c478bd9Sstevel@tonic-gate 		if (setjmp(xdr_err)) {
1267c478bd9Sstevel@tonic-gate 			return;
1277c478bd9Sstevel@tonic-gate 		}
1287c478bd9Sstevel@tonic-gate 
1297c478bd9Sstevel@tonic-gate 		line = get_sum_line();
1307c478bd9Sstevel@tonic-gate 
1317c478bd9Sstevel@tonic-gate 		if (type == CALL) {
13278fb3df6SMarcel Telka 			(void) sprintf(line, "PORTMAP C %s",
1337c478bd9Sstevel@tonic-gate 			    procnames_short_2[proc]);
1347c478bd9Sstevel@tonic-gate 			line += strlen(line);
1357c478bd9Sstevel@tonic-gate 			switch (proc) {
1367c478bd9Sstevel@tonic-gate 			case PMAPPROC_GETPORT:
1377c478bd9Sstevel@tonic-gate 				iprog = getxdr_u_long();
1387c478bd9Sstevel@tonic-gate 				ivers = getxdr_u_long();
1397c478bd9Sstevel@tonic-gate 				proto = getxdr_u_long();
1407c478bd9Sstevel@tonic-gate 				(void) sprintf(line,
1417c478bd9Sstevel@tonic-gate 				    " prog=%d (%s) vers=%d proto=%s",
1427c478bd9Sstevel@tonic-gate 				    iprog, nameof_prog(iprog),
1437c478bd9Sstevel@tonic-gate 				    ivers,
1447c478bd9Sstevel@tonic-gate 				    getproto(proto));
1457c478bd9Sstevel@tonic-gate 				break;
1467c478bd9Sstevel@tonic-gate 			case PMAPPROC_CALLIT:
1477c478bd9Sstevel@tonic-gate 				(void) sprintf(line,
1487c478bd9Sstevel@tonic-gate 				    " prog=%s vers=%d proc=%d",
1497c478bd9Sstevel@tonic-gate 				    nameof_prog(iprog),
1507c478bd9Sstevel@tonic-gate 				    ivers, iproc);
15178fb3df6SMarcel Telka 				if (flags & F_ALLSUM) {
15278fb3df6SMarcel Telka 					(void) getxdr_u_long(); /* length */
1537c478bd9Sstevel@tonic-gate 					data += 16; /* prog+ver+proc+len */
1547c478bd9Sstevel@tonic-gate 					len -= 16;
1557c478bd9Sstevel@tonic-gate 					protoprint(flags, type, xid,
1567c478bd9Sstevel@tonic-gate 					    iprog, ivers, iproc,
1577c478bd9Sstevel@tonic-gate 					    data, len);
15878fb3df6SMarcel Telka 				}
1597c478bd9Sstevel@tonic-gate 				break;
1607c478bd9Sstevel@tonic-gate 			default:
1617c478bd9Sstevel@tonic-gate 				break;
1627c478bd9Sstevel@tonic-gate 			}
1637c478bd9Sstevel@tonic-gate 			check_retransmit(line, xid);
1647c478bd9Sstevel@tonic-gate 		} else {
1657c478bd9Sstevel@tonic-gate 			(void) sprintf(line, "PORTMAP R %s ",
1667c478bd9Sstevel@tonic-gate 			    procnames_short_2[proc]);
1677c478bd9Sstevel@tonic-gate 			line += strlen(line);
1687c478bd9Sstevel@tonic-gate 			switch (proc) {
1697c478bd9Sstevel@tonic-gate 			case PMAPPROC_GETPORT:
1707c478bd9Sstevel@tonic-gate 				port = getxdr_u_long();
17178fb3df6SMarcel Telka 				(void) sprintf(line, "port=%d", port);
1727c478bd9Sstevel@tonic-gate 				break;
1737c478bd9Sstevel@tonic-gate 			case PMAPPROC_DUMP:
17478fb3df6SMarcel Telka 				(void) sprintf(line, "%s", sum_pmaplist());
1757c478bd9Sstevel@tonic-gate 				break;
1767c478bd9Sstevel@tonic-gate 			case PMAPPROC_CALLIT:
1777c478bd9Sstevel@tonic-gate 				port = getxdr_u_long();
1787c478bd9Sstevel@tonic-gate 				ilen = getxdr_u_long();
1797c478bd9Sstevel@tonic-gate 				(void) sprintf(line, "port=%d len=%d",
1807c478bd9Sstevel@tonic-gate 				    port, ilen);
18178fb3df6SMarcel Telka 				if (flags & F_ALLSUM && x != NULL) {
18278fb3df6SMarcel Telka 					data += 8; /* port+len */
18378fb3df6SMarcel Telka 					len -= 8;
1847c478bd9Sstevel@tonic-gate 					protoprint(flags, type, xid,
1857c478bd9Sstevel@tonic-gate 					    x->xid_prog,
1867c478bd9Sstevel@tonic-gate 					    x->xid_vers,
1877c478bd9Sstevel@tonic-gate 					    x->xid_proc,
1887c478bd9Sstevel@tonic-gate 					    data, len);
1897c478bd9Sstevel@tonic-gate 				}
1907c478bd9Sstevel@tonic-gate 				break;
1917c478bd9Sstevel@tonic-gate 			default:
1927c478bd9Sstevel@tonic-gate 				break;
1937c478bd9Sstevel@tonic-gate 			}
1947c478bd9Sstevel@tonic-gate 		}
1957c478bd9Sstevel@tonic-gate 	}
1967c478bd9Sstevel@tonic-gate 
1977c478bd9Sstevel@tonic-gate 	if (flags & F_DTAIL) {
1987c478bd9Sstevel@tonic-gate 		show_header("PMAP:  ", "Portmapper", len);
1997c478bd9Sstevel@tonic-gate 		show_space();
2007c478bd9Sstevel@tonic-gate 		if (setjmp(xdr_err)) {
2017c478bd9Sstevel@tonic-gate 			return;
2027c478bd9Sstevel@tonic-gate 		}
2037c478bd9Sstevel@tonic-gate 		(void) sprintf(get_line(0, 0),
2047c478bd9Sstevel@tonic-gate 			"Proc = %d (%s)",
2057c478bd9Sstevel@tonic-gate 			proc, procnames_long_2[proc]);
2067c478bd9Sstevel@tonic-gate 		if (type == CALL) {
2077c478bd9Sstevel@tonic-gate 			switch (proc) {
2087c478bd9Sstevel@tonic-gate 			case PMAPPROC_NULL:
2097c478bd9Sstevel@tonic-gate 			case PMAPPROC_SET:
2107c478bd9Sstevel@tonic-gate 			case PMAPPROC_UNSET:
2117c478bd9Sstevel@tonic-gate 				break;
2127c478bd9Sstevel@tonic-gate 			case PMAPPROC_GETPORT:
2137c478bd9Sstevel@tonic-gate 				iprog = getxdr_u_long();
2147c478bd9Sstevel@tonic-gate 				(void) sprintf(get_line(0, 0),
2157c478bd9Sstevel@tonic-gate 				    "Program = %d (%s)",
2167c478bd9Sstevel@tonic-gate 				    iprog, nameof_prog(iprog));
2177c478bd9Sstevel@tonic-gate 				(void) showxdr_u_long("Version = %d");
2187c478bd9Sstevel@tonic-gate 				proto = getxdr_u_long();
2197c478bd9Sstevel@tonic-gate 				(void) sprintf(get_line(0, 0),
2207c478bd9Sstevel@tonic-gate 				    "Protocol = %d (%s)",
2217c478bd9Sstevel@tonic-gate 				    proto, getproto(proto));
2227c478bd9Sstevel@tonic-gate 				break;
2237c478bd9Sstevel@tonic-gate 			case PMAPPROC_DUMP:
2247c478bd9Sstevel@tonic-gate 				break;
2257c478bd9Sstevel@tonic-gate 			case PMAPPROC_CALLIT:
2267c478bd9Sstevel@tonic-gate 				(void) sprintf(get_line(0, 0),
2277c478bd9Sstevel@tonic-gate 				    "Program = %d (%s)",
2287c478bd9Sstevel@tonic-gate 				    iprog, nameof_prog(iprog));
2297c478bd9Sstevel@tonic-gate 				(void) sprintf(get_line(0, 0),
2307c478bd9Sstevel@tonic-gate 				    "Version = %d", ivers);
2317c478bd9Sstevel@tonic-gate 				(void) sprintf(get_line(0, 0),
2327c478bd9Sstevel@tonic-gate 				    "Proc    = %d", iproc);
23378fb3df6SMarcel Telka 				(void) showxdr_u_long("Callit data = %d bytes");
2347c478bd9Sstevel@tonic-gate 				show_trailer();
2357c478bd9Sstevel@tonic-gate 				trailer_done = 1;
2367c478bd9Sstevel@tonic-gate 				data += 16; /* prog+ver+proc+len */
2377c478bd9Sstevel@tonic-gate 				len -= 16;
2387c478bd9Sstevel@tonic-gate 				protoprint(flags, type, xid,
2397c478bd9Sstevel@tonic-gate 				    iprog, ivers, iproc,
2407c478bd9Sstevel@tonic-gate 				    data, len);
2417c478bd9Sstevel@tonic-gate 				break;
2427c478bd9Sstevel@tonic-gate 			}
2437c478bd9Sstevel@tonic-gate 		} else {
2447c478bd9Sstevel@tonic-gate 			switch (proc) {
2457c478bd9Sstevel@tonic-gate 			case PMAPPROC_NULL:
2467c478bd9Sstevel@tonic-gate 			case PMAPPROC_SET:
2477c478bd9Sstevel@tonic-gate 			case PMAPPROC_UNSET:
2487c478bd9Sstevel@tonic-gate 				break;
2497c478bd9Sstevel@tonic-gate 			case PMAPPROC_GETPORT:
2507c478bd9Sstevel@tonic-gate 				(void) showxdr_u_long("Port = %d");
2517c478bd9Sstevel@tonic-gate 				break;
2527c478bd9Sstevel@tonic-gate 			case PMAPPROC_DUMP:
2537c478bd9Sstevel@tonic-gate 				show_pmaplist();
2547c478bd9Sstevel@tonic-gate 				break;
2557c478bd9Sstevel@tonic-gate 			case PMAPPROC_CALLIT:
2567c478bd9Sstevel@tonic-gate 				(void) showxdr_u_long("Port = %d");
2577c478bd9Sstevel@tonic-gate 				(void) showxdr_u_long("Length = %d bytes");
2587c478bd9Sstevel@tonic-gate 				show_trailer();
2597c478bd9Sstevel@tonic-gate 				trailer_done = 1;
2607c478bd9Sstevel@tonic-gate 				if (x != NULL) {
2617c478bd9Sstevel@tonic-gate 					protoprint(flags, type, xid,
2627c478bd9Sstevel@tonic-gate 					    x->xid_prog,
2637c478bd9Sstevel@tonic-gate 					    x->xid_vers,
2647c478bd9Sstevel@tonic-gate 					    x->xid_proc,
2657c478bd9Sstevel@tonic-gate 					    data, len);
2667c478bd9Sstevel@tonic-gate 				}
2677c478bd9Sstevel@tonic-gate 				break;
2687c478bd9Sstevel@tonic-gate 			}
2697c478bd9Sstevel@tonic-gate 		}
2707c478bd9Sstevel@tonic-gate 		if (!trailer_done)
2717c478bd9Sstevel@tonic-gate 			show_trailer();
2727c478bd9Sstevel@tonic-gate 	}
2737c478bd9Sstevel@tonic-gate }
2747c478bd9Sstevel@tonic-gate 
2757c478bd9Sstevel@tonic-gate char *
sum_pmaplist()2767c478bd9Sstevel@tonic-gate sum_pmaplist()
2777c478bd9Sstevel@tonic-gate {
2787c478bd9Sstevel@tonic-gate 	int maps = 0;
2797c478bd9Sstevel@tonic-gate 	static char buff[16];
2807c478bd9Sstevel@tonic-gate 
2817c478bd9Sstevel@tonic-gate 	if (setjmp(xdr_err)) {
2827c478bd9Sstevel@tonic-gate 		(void) sprintf(buff, "%d+ map(s) found", maps);
2837c478bd9Sstevel@tonic-gate 		return (buff);
2847c478bd9Sstevel@tonic-gate 	}
2857c478bd9Sstevel@tonic-gate 
2867c478bd9Sstevel@tonic-gate 	while (getxdr_u_long()) {
2877c478bd9Sstevel@tonic-gate 		(void) getxdr_u_long();	/* program */
2887c478bd9Sstevel@tonic-gate 		(void) getxdr_u_long();	/* version */
2897c478bd9Sstevel@tonic-gate 		(void) getxdr_u_long();	/* protocol */
2907c478bd9Sstevel@tonic-gate 		(void) getxdr_u_long();	/* port */
2917c478bd9Sstevel@tonic-gate 		maps++;
2927c478bd9Sstevel@tonic-gate 	}
2937c478bd9Sstevel@tonic-gate 
2947c478bd9Sstevel@tonic-gate 	(void) sprintf(buff, "%d map(s) found", maps);
2957c478bd9Sstevel@tonic-gate 	return (buff);
2967c478bd9Sstevel@tonic-gate }
2977c478bd9Sstevel@tonic-gate 
2987c478bd9Sstevel@tonic-gate void
show_pmaplist()2997c478bd9Sstevel@tonic-gate show_pmaplist()
3007c478bd9Sstevel@tonic-gate {
3017c478bd9Sstevel@tonic-gate 	unsigned prog, vers, proto, port;
3027c478bd9Sstevel@tonic-gate 	int maps = 0;
3037c478bd9Sstevel@tonic-gate 
3047c478bd9Sstevel@tonic-gate 	if (setjmp(xdr_err)) {
3057c478bd9Sstevel@tonic-gate 		(void) sprintf(get_line(0, 0),
3067c478bd9Sstevel@tonic-gate 		    " %d+ maps. (Frame is incomplete)",
3077c478bd9Sstevel@tonic-gate 		    maps);
3087c478bd9Sstevel@tonic-gate 		return;
3097c478bd9Sstevel@tonic-gate 	}
3107c478bd9Sstevel@tonic-gate 
31178fb3df6SMarcel Telka 	(void) sprintf(get_line(0, 0), " Program Version Protocol   Port");
3127c478bd9Sstevel@tonic-gate 
3137c478bd9Sstevel@tonic-gate 	while (getxdr_u_long()) {
3147c478bd9Sstevel@tonic-gate 		prog  = getxdr_u_long();
3157c478bd9Sstevel@tonic-gate 		vers  = getxdr_u_long();
3167c478bd9Sstevel@tonic-gate 		proto = getxdr_u_long();
3177c478bd9Sstevel@tonic-gate 		port  = getxdr_u_long();
3187c478bd9Sstevel@tonic-gate 		(void) sprintf(get_line(0, 0),
3197c478bd9Sstevel@tonic-gate 		    "%8d%8d%9d%7d  %s",
3207c478bd9Sstevel@tonic-gate 		    prog, vers, proto, port, nameof_prog(prog));
3217c478bd9Sstevel@tonic-gate 		maps++;
3227c478bd9Sstevel@tonic-gate 	}
3237c478bd9Sstevel@tonic-gate 
3247c478bd9Sstevel@tonic-gate 	(void) sprintf(get_line(0, 0), " %d maps", maps);
3257c478bd9Sstevel@tonic-gate }
3267c478bd9Sstevel@tonic-gate 
3277c478bd9Sstevel@tonic-gate /*
3287c478bd9Sstevel@tonic-gate  * ******************************************
3297c478bd9Sstevel@tonic-gate  */
3307c478bd9Sstevel@tonic-gate char *sum_rpcblist();
3317c478bd9Sstevel@tonic-gate void show_rpcblist();
3327c478bd9Sstevel@tonic-gate char *sum_rpcb_entry_list();
3337c478bd9Sstevel@tonic-gate void show_rpcb_entry_list();
3347c478bd9Sstevel@tonic-gate 
3357c478bd9Sstevel@tonic-gate static char *procnames_short_4[] = {
3367c478bd9Sstevel@tonic-gate 	/*
3377c478bd9Sstevel@tonic-gate 	 * version 3 and 4 procs
3387c478bd9Sstevel@tonic-gate 	 */
3397c478bd9Sstevel@tonic-gate 	"Null",		/* 0 */
3407c478bd9Sstevel@tonic-gate 	"SET",		/* 1 */
3417c478bd9Sstevel@tonic-gate 	"UNSET",	/* 2 */
3427c478bd9Sstevel@tonic-gate 	"GETADDR",	/* 3 */
3437c478bd9Sstevel@tonic-gate 	"DUMP",		/* 4 */
3447c478bd9Sstevel@tonic-gate 	"BCAST",	/* 5 */
3457c478bd9Sstevel@tonic-gate 	"GETTIME",	/* 6 */
3467c478bd9Sstevel@tonic-gate 	"UADDR2TADDR",	/* 7 */
3477c478bd9Sstevel@tonic-gate 	"TADDR2UADDR",	/* 8 */
3487c478bd9Sstevel@tonic-gate 	/*
3497c478bd9Sstevel@tonic-gate 	 * version 4 procs only
3507c478bd9Sstevel@tonic-gate 	 */
3517c478bd9Sstevel@tonic-gate 	"GETVERSADDR",	/* 9 */
3527c478bd9Sstevel@tonic-gate 	"INDIRECT",	/* 10 */
3537c478bd9Sstevel@tonic-gate 	"GETADDRLIST",	/* 11 */
3547c478bd9Sstevel@tonic-gate 	"GETSTAT",	/* 12 */
3557c478bd9Sstevel@tonic-gate };
3567c478bd9Sstevel@tonic-gate 
3577c478bd9Sstevel@tonic-gate static char *procnames_long_4[] = {
3587c478bd9Sstevel@tonic-gate 	/*
3597c478bd9Sstevel@tonic-gate 	 * version 3 and 4 procs
3607c478bd9Sstevel@tonic-gate 	 */
3617c478bd9Sstevel@tonic-gate 	"Null procedure",			/* 0 */
3627c478bd9Sstevel@tonic-gate 	"Set address",				/* 1 */
3637c478bd9Sstevel@tonic-gate 	"Unset address",			/* 2 */
3647c478bd9Sstevel@tonic-gate 	"Get address",				/* 3 */
3657c478bd9Sstevel@tonic-gate 	"Dump the mappings",			/* 4 */
3667c478bd9Sstevel@tonic-gate 	"Broadcast call (no error)",		/* 5 */
3677c478bd9Sstevel@tonic-gate 	"Get the time",				/* 6 */
3687c478bd9Sstevel@tonic-gate 	"Universal to transport address",	/* 7 */
3697c478bd9Sstevel@tonic-gate 	"Transport to universal address",	/* 8 */
3707c478bd9Sstevel@tonic-gate 	/*
3717c478bd9Sstevel@tonic-gate 	 * version 4 procs only
3727c478bd9Sstevel@tonic-gate 	 */
3737c478bd9Sstevel@tonic-gate 	"Get address of specific version",	/* 9 */
3747c478bd9Sstevel@tonic-gate 	"Indirect call (return error)",		/* 10 */
3757c478bd9Sstevel@tonic-gate 	"Return addresses of prog/vers",	/* 11 */
3767c478bd9Sstevel@tonic-gate 	"Get statistics",			/* 12 */
3777c478bd9Sstevel@tonic-gate };
3787c478bd9Sstevel@tonic-gate 
37978fb3df6SMarcel Telka #define	MAXPROC_3		8
3807c478bd9Sstevel@tonic-gate #define	MAXPROC_4		12
3817c478bd9Sstevel@tonic-gate #define	RPCBPROC_NULL		0
3827c478bd9Sstevel@tonic-gate 
3837c478bd9Sstevel@tonic-gate void
interpret_pmap_4(flags,type,xid,vers,proc,data,len)3847c478bd9Sstevel@tonic-gate interpret_pmap_4(flags, type, xid, vers, proc, data, len)
3857c478bd9Sstevel@tonic-gate 	int flags, type, xid, vers, proc;
3867c478bd9Sstevel@tonic-gate 	char *data;
3877c478bd9Sstevel@tonic-gate 	int len;
3887c478bd9Sstevel@tonic-gate {
3897c478bd9Sstevel@tonic-gate 	char *line;
3907c478bd9Sstevel@tonic-gate 	unsigned prog, ver;
3917c478bd9Sstevel@tonic-gate 	char buff1[MAXSTRINGLEN + 1];
3927c478bd9Sstevel@tonic-gate 	int iprog, ivers, iproc, ilen;
3937c478bd9Sstevel@tonic-gate 	extern int pi_frame;
3947c478bd9Sstevel@tonic-gate 	struct cache_struct *x, *find_callit();
3957c478bd9Sstevel@tonic-gate 	int trailer_done = 0;
3967c478bd9Sstevel@tonic-gate 
39778fb3df6SMarcel Telka 	if (proc < 0 || proc > MAXPROC_4 || (vers == 3 && proc > MAXPROC_3))
3987c478bd9Sstevel@tonic-gate 		return;
3997c478bd9Sstevel@tonic-gate 
40078fb3df6SMarcel Telka 	if (proc == RPCBPROC_BCAST || proc == RPCBPROC_INDIRECT) {
4017c478bd9Sstevel@tonic-gate 		if (type == CALL) {
4027c478bd9Sstevel@tonic-gate 			iprog = getxdr_u_long();
4037c478bd9Sstevel@tonic-gate 			ivers = getxdr_u_long();
4047c478bd9Sstevel@tonic-gate 			iproc = getxdr_u_long();
4057c478bd9Sstevel@tonic-gate 			stash_callit(xid, pi_frame,
4067c478bd9Sstevel@tonic-gate 				iprog, ivers, iproc);
4077c478bd9Sstevel@tonic-gate 		} else {
4087c478bd9Sstevel@tonic-gate 			x = find_callit(xid);
4097c478bd9Sstevel@tonic-gate 		}
4107c478bd9Sstevel@tonic-gate 	}
4117c478bd9Sstevel@tonic-gate 
4127c478bd9Sstevel@tonic-gate 	if (flags & F_SUM) {
4137c478bd9Sstevel@tonic-gate 		if (setjmp(xdr_err)) {
4147c478bd9Sstevel@tonic-gate 			return;
4157c478bd9Sstevel@tonic-gate 		}
4167c478bd9Sstevel@tonic-gate 
4177c478bd9Sstevel@tonic-gate 		line = get_sum_line();
4187c478bd9Sstevel@tonic-gate 
4197c478bd9Sstevel@tonic-gate 		if (type == CALL) {
4207c478bd9Sstevel@tonic-gate 			(void) sprintf(line,
4217c478bd9Sstevel@tonic-gate 				"RPCBIND C %s",
4227c478bd9Sstevel@tonic-gate 				procnames_short_4[proc]);
4237c478bd9Sstevel@tonic-gate 			line += strlen(line);
4247c478bd9Sstevel@tonic-gate 			switch (proc) {
4257c478bd9Sstevel@tonic-gate 			case RPCBPROC_SET:
4267c478bd9Sstevel@tonic-gate 			case RPCBPROC_UNSET:
4277c478bd9Sstevel@tonic-gate 			case RPCBPROC_GETADDR:
4287c478bd9Sstevel@tonic-gate 			case RPCBPROC_GETVERSADDR:
4297c478bd9Sstevel@tonic-gate 			case RPCBPROC_GETADDRLIST:
4307c478bd9Sstevel@tonic-gate 				prog = getxdr_u_long();
4317c478bd9Sstevel@tonic-gate 				ver  = getxdr_u_long();
4327c478bd9Sstevel@tonic-gate 				(void) sprintf(line,
4337c478bd9Sstevel@tonic-gate 					" prog=%d (%s) vers=%d",
4347c478bd9Sstevel@tonic-gate 					prog, nameof_prog(prog),
4357c478bd9Sstevel@tonic-gate 					ver);
4367c478bd9Sstevel@tonic-gate 				break;
4377c478bd9Sstevel@tonic-gate 			case RPCBPROC_BCAST:
4387c478bd9Sstevel@tonic-gate 			case RPCBPROC_INDIRECT:
4397c478bd9Sstevel@tonic-gate 				(void) sprintf(line,
4407c478bd9Sstevel@tonic-gate 					" prog=%s vers=%d proc=%d",
4417c478bd9Sstevel@tonic-gate 					nameof_prog(iprog),
4427c478bd9Sstevel@tonic-gate 					ivers, iproc);
44378fb3df6SMarcel Telka 				if (flags & F_ALLSUM) {
44478fb3df6SMarcel Telka 					(void) getxdr_u_long(); /* length */
4457c478bd9Sstevel@tonic-gate 					data += 16; /* prog+ver+proc+len */
4467c478bd9Sstevel@tonic-gate 					len -= 16;
4477c478bd9Sstevel@tonic-gate 					protoprint(flags, type, xid,
4487c478bd9Sstevel@tonic-gate 						iprog, ivers, iproc,
4497c478bd9Sstevel@tonic-gate 						data, len);
45078fb3df6SMarcel Telka 				}
4517c478bd9Sstevel@tonic-gate 				break;
4527c478bd9Sstevel@tonic-gate 			default:
4537c478bd9Sstevel@tonic-gate 				break;
4547c478bd9Sstevel@tonic-gate 			}
4557c478bd9Sstevel@tonic-gate 
4567c478bd9Sstevel@tonic-gate 			check_retransmit(line, xid);
4577c478bd9Sstevel@tonic-gate 		} else {
45878fb3df6SMarcel Telka 			int pos;
45978fb3df6SMarcel Telka 
4607c478bd9Sstevel@tonic-gate 			(void) sprintf(line, "RPCBIND R %s ",
4617c478bd9Sstevel@tonic-gate 				procnames_short_4[proc]);
4627c478bd9Sstevel@tonic-gate 			line += strlen(line);
4637c478bd9Sstevel@tonic-gate 			switch (proc) {
4647c478bd9Sstevel@tonic-gate 			case RPCBPROC_GETADDR:
4657c478bd9Sstevel@tonic-gate 			case RPCBPROC_TADDR2UADDR:
4667c478bd9Sstevel@tonic-gate 			case RPCBPROC_GETVERSADDR:
4677c478bd9Sstevel@tonic-gate 				(void) getxdr_string(buff1, MAXSTRINGLEN);
4687c478bd9Sstevel@tonic-gate 				(void) sprintf(line,
4697c478bd9Sstevel@tonic-gate 					" Uaddr=%s",
4707c478bd9Sstevel@tonic-gate 					buff1);
4717c478bd9Sstevel@tonic-gate 				break;
4727c478bd9Sstevel@tonic-gate 			case RPCBPROC_BCAST:
4737c478bd9Sstevel@tonic-gate 			case RPCBPROC_INDIRECT:
47478fb3df6SMarcel Telka 				pos = getxdr_pos();
4757c478bd9Sstevel@tonic-gate 				(void) getxdr_string(buff1, MAXSTRINGLEN);
4767c478bd9Sstevel@tonic-gate 				ilen = getxdr_u_long();
4777c478bd9Sstevel@tonic-gate 				(void) sprintf(line, "Uaddr=%s len=%d",
4787c478bd9Sstevel@tonic-gate 					buff1, ilen);
47978fb3df6SMarcel Telka 				if (flags & F_ALLSUM && x != NULL) {
48078fb3df6SMarcel Telka 					pos = getxdr_pos() - pos;
48178fb3df6SMarcel Telka 					data += pos; /* uaddr+len */
48278fb3df6SMarcel Telka 					len -= pos;
4837c478bd9Sstevel@tonic-gate 					protoprint(flags, type, xid,
4847c478bd9Sstevel@tonic-gate 						x->xid_prog,
4857c478bd9Sstevel@tonic-gate 						x->xid_vers,
4867c478bd9Sstevel@tonic-gate 						x->xid_proc,
4877c478bd9Sstevel@tonic-gate 						data, len);
4887c478bd9Sstevel@tonic-gate 				}
4897c478bd9Sstevel@tonic-gate 				break;
4907c478bd9Sstevel@tonic-gate 			case RPCBPROC_DUMP:
4917c478bd9Sstevel@tonic-gate 				(void) sprintf(line, "%s",
4927c478bd9Sstevel@tonic-gate 					sum_rpcblist());
4937c478bd9Sstevel@tonic-gate 				break;
4947c478bd9Sstevel@tonic-gate 			case RPCBPROC_GETTIME:
495*c64d0c7cSMarcel Telka 				{
496*c64d0c7cSMarcel Telka 					time_t sec = getxdr_long();
497*c64d0c7cSMarcel Telka 					struct tm *tmp = gmtime(&sec);
498*c64d0c7cSMarcel Telka 					(void) strftime(line, MAXLINE,
499*c64d0c7cSMarcel Telka 					    "%d-%h-%y %T GMT", tmp);
500*c64d0c7cSMarcel Telka 				}
5017c478bd9Sstevel@tonic-gate 				break;
5027c478bd9Sstevel@tonic-gate 			case RPCBPROC_GETADDRLIST:
5037c478bd9Sstevel@tonic-gate 				(void) sprintf(line, "%s",
5047c478bd9Sstevel@tonic-gate 					sum_rpcb_entry_list());
5057c478bd9Sstevel@tonic-gate 				break;
5067c478bd9Sstevel@tonic-gate 			default:
5077c478bd9Sstevel@tonic-gate 				break;
5087c478bd9Sstevel@tonic-gate 			}
5097c478bd9Sstevel@tonic-gate 		}
5107c478bd9Sstevel@tonic-gate 	}
5117c478bd9Sstevel@tonic-gate 
5127c478bd9Sstevel@tonic-gate 	if (flags & F_DTAIL) {
5137c478bd9Sstevel@tonic-gate 		show_header("RPCB:  ", "RPC Bind", len);
5147c478bd9Sstevel@tonic-gate 		show_space();
5157c478bd9Sstevel@tonic-gate 		if (setjmp(xdr_err)) {
5167c478bd9Sstevel@tonic-gate 			return;
5177c478bd9Sstevel@tonic-gate 		}
5187c478bd9Sstevel@tonic-gate 		(void) sprintf(get_line(0, 0),
5197c478bd9Sstevel@tonic-gate 			"Proc = %d (%s)",
5207c478bd9Sstevel@tonic-gate 			proc, procnames_long_4[proc]);
5217c478bd9Sstevel@tonic-gate 		if (type == CALL) {
5227c478bd9Sstevel@tonic-gate 			switch (proc) {
5237c478bd9Sstevel@tonic-gate 			case RPCBPROC_NULL:
5247c478bd9Sstevel@tonic-gate 				break;
5257c478bd9Sstevel@tonic-gate 			case RPCBPROC_SET:
5267c478bd9Sstevel@tonic-gate 			case RPCBPROC_UNSET:
5277c478bd9Sstevel@tonic-gate 			case RPCBPROC_GETADDR:
5287c478bd9Sstevel@tonic-gate 			case RPCBPROC_GETVERSADDR:
5297c478bd9Sstevel@tonic-gate 			case RPCBPROC_GETADDRLIST:
5307c478bd9Sstevel@tonic-gate 				(void) showxdr_u_long("Program = %d");
5317c478bd9Sstevel@tonic-gate 				(void) showxdr_u_long("Version = %d");
5327c478bd9Sstevel@tonic-gate 				(void) showxdr_string(64, "Netid   = %s");
5337c478bd9Sstevel@tonic-gate 				break;
5347c478bd9Sstevel@tonic-gate 			case RPCBPROC_DUMP:
5357c478bd9Sstevel@tonic-gate 				break;
5367c478bd9Sstevel@tonic-gate 			case RPCBPROC_BCAST:
5377c478bd9Sstevel@tonic-gate 			case RPCBPROC_INDIRECT:
5387c478bd9Sstevel@tonic-gate 				(void) sprintf(get_line(0, 0),
5397c478bd9Sstevel@tonic-gate 					"Program = %d (%s)",
5407c478bd9Sstevel@tonic-gate 					iprog, nameof_prog(iprog));
5417c478bd9Sstevel@tonic-gate 				(void) sprintf(get_line(0, 0),
5427c478bd9Sstevel@tonic-gate 					"Version = %d", ivers);
5437c478bd9Sstevel@tonic-gate 				(void) sprintf(get_line(0, 0),
5447c478bd9Sstevel@tonic-gate 					"Proc    = %d", iproc);
5457c478bd9Sstevel@tonic-gate 				(void) showxdr_u_long(
5467c478bd9Sstevel@tonic-gate 					"Callit data = %d bytes");
5477c478bd9Sstevel@tonic-gate 				show_trailer();
5487c478bd9Sstevel@tonic-gate 				trailer_done = 1;
5497c478bd9Sstevel@tonic-gate 				data += 16; /* prog+ver+proc+len */
5507c478bd9Sstevel@tonic-gate 				len -= 16;
5517c478bd9Sstevel@tonic-gate 				protoprint(flags, type, xid,
5527c478bd9Sstevel@tonic-gate 					iprog, ivers, iproc,
5537c478bd9Sstevel@tonic-gate 					data, len);
5547c478bd9Sstevel@tonic-gate 				break;
5557c478bd9Sstevel@tonic-gate 			case RPCBPROC_GETTIME:
5567c478bd9Sstevel@tonic-gate 				break;
5577c478bd9Sstevel@tonic-gate 			case RPCBPROC_UADDR2TADDR:
5587c478bd9Sstevel@tonic-gate 			case RPCBPROC_TADDR2UADDR:
5597c478bd9Sstevel@tonic-gate 				break;
5607c478bd9Sstevel@tonic-gate 			}
5617c478bd9Sstevel@tonic-gate 		} else {
5627c478bd9Sstevel@tonic-gate 			switch (proc) {
5637c478bd9Sstevel@tonic-gate 			case RPCBPROC_NULL:
5647c478bd9Sstevel@tonic-gate 			case RPCBPROC_SET:
5657c478bd9Sstevel@tonic-gate 			case RPCBPROC_UNSET:
5667c478bd9Sstevel@tonic-gate 				break;
5677c478bd9Sstevel@tonic-gate 			case RPCBPROC_GETADDR:
5687c478bd9Sstevel@tonic-gate 			case RPCBPROC_TADDR2UADDR:
5697c478bd9Sstevel@tonic-gate 			case RPCBPROC_GETVERSADDR:
5707c478bd9Sstevel@tonic-gate 				(void) showxdr_string(64, "Uaddr = %s");
5717c478bd9Sstevel@tonic-gate 				break;
5727c478bd9Sstevel@tonic-gate 			case RPCBPROC_DUMP:
5737c478bd9Sstevel@tonic-gate 				show_rpcblist();
5747c478bd9Sstevel@tonic-gate 				break;
5757c478bd9Sstevel@tonic-gate 			case RPCBPROC_BCAST:
5767c478bd9Sstevel@tonic-gate 			case RPCBPROC_INDIRECT:
5777c478bd9Sstevel@tonic-gate 				(void) showxdr_string(64, "Uaddr = %s");
5787c478bd9Sstevel@tonic-gate 				(void) showxdr_u_long("Length = %d bytes");
5797c478bd9Sstevel@tonic-gate 				show_trailer();
5807c478bd9Sstevel@tonic-gate 				trailer_done = 1;
5817c478bd9Sstevel@tonic-gate 				if (x != NULL) {
5827c478bd9Sstevel@tonic-gate 					protoprint(flags, type, xid,
5837c478bd9Sstevel@tonic-gate 						x->xid_prog,
5847c478bd9Sstevel@tonic-gate 						x->xid_vers,
5857c478bd9Sstevel@tonic-gate 						x->xid_proc,
5867c478bd9Sstevel@tonic-gate 						data, len);
5877c478bd9Sstevel@tonic-gate 				}
5887c478bd9Sstevel@tonic-gate 				break;
5897c478bd9Sstevel@tonic-gate 			case RPCBPROC_GETTIME:
590*c64d0c7cSMarcel Telka 				{
591*c64d0c7cSMarcel Telka 					int pos = getxdr_pos();
592*c64d0c7cSMarcel Telka 					time_t sec = getxdr_long();
593*c64d0c7cSMarcel Telka 					struct tm *tmp = gmtime(&sec);
594*c64d0c7cSMarcel Telka 					(void) strftime(get_line(pos,
595*c64d0c7cSMarcel Telka 					    getxdr_pos()), MAXLINE,
596*c64d0c7cSMarcel Telka 					    "Time = %d-%h-%y %T GMT", tmp);
597*c64d0c7cSMarcel Telka 				}
5987c478bd9Sstevel@tonic-gate 				break;
5997c478bd9Sstevel@tonic-gate 			case RPCBPROC_UADDR2TADDR:
6007c478bd9Sstevel@tonic-gate 				break;
6017c478bd9Sstevel@tonic-gate 			case RPCBPROC_GETADDRLIST:
6027c478bd9Sstevel@tonic-gate 				show_rpcb_entry_list();
6037c478bd9Sstevel@tonic-gate 				break;
6047c478bd9Sstevel@tonic-gate 			}
6057c478bd9Sstevel@tonic-gate 		}
6067c478bd9Sstevel@tonic-gate 		if (!trailer_done)
6077c478bd9Sstevel@tonic-gate 			show_trailer();
6087c478bd9Sstevel@tonic-gate 	}
6097c478bd9Sstevel@tonic-gate }
6107c478bd9Sstevel@tonic-gate 
6117c478bd9Sstevel@tonic-gate char *
sum_rpcblist()6127c478bd9Sstevel@tonic-gate sum_rpcblist()
6137c478bd9Sstevel@tonic-gate {
6147c478bd9Sstevel@tonic-gate 	int maps = 0;
6157c478bd9Sstevel@tonic-gate 	static char buff[MAXSTRINGLEN + 1];
6167c478bd9Sstevel@tonic-gate 
6177c478bd9Sstevel@tonic-gate 	if (setjmp(xdr_err)) {
6187c478bd9Sstevel@tonic-gate 		(void) sprintf(buff, "%d+ map(s) found", maps);
6197c478bd9Sstevel@tonic-gate 		return (buff);
6207c478bd9Sstevel@tonic-gate 	}
6217c478bd9Sstevel@tonic-gate 
6227c478bd9Sstevel@tonic-gate 	while (getxdr_u_long()) {
6237c478bd9Sstevel@tonic-gate 		(void) getxdr_u_long();		/* program */
6247c478bd9Sstevel@tonic-gate 		(void) getxdr_u_long();		/* version */
6257c478bd9Sstevel@tonic-gate 		(void) getxdr_string(buff, MAXSTRINGLEN); /* netid */
6267c478bd9Sstevel@tonic-gate 		(void) getxdr_string(buff, MAXSTRINGLEN); /* uaddr */
6277c478bd9Sstevel@tonic-gate 		(void) getxdr_string(buff, MAXSTRINGLEN); /* owner */
6287c478bd9Sstevel@tonic-gate 		maps++;
6297c478bd9Sstevel@tonic-gate 	}
6307c478bd9Sstevel@tonic-gate 
6317c478bd9Sstevel@tonic-gate 	(void) sprintf(buff, "%d map(s) found", maps);
6327c478bd9Sstevel@tonic-gate 	return (buff);
6337c478bd9Sstevel@tonic-gate }
6347c478bd9Sstevel@tonic-gate 
6357c478bd9Sstevel@tonic-gate void
show_rpcblist()6367c478bd9Sstevel@tonic-gate show_rpcblist()
6377c478bd9Sstevel@tonic-gate {
6387c478bd9Sstevel@tonic-gate 	unsigned prog, vers;
6397c478bd9Sstevel@tonic-gate 	char netid[MAXSTRINGLEN + 1], uaddr[MAXSTRINGLEN + 1];
6407c478bd9Sstevel@tonic-gate 	char owner[MAXSTRINGLEN + 1];
6417c478bd9Sstevel@tonic-gate 	int maps = 0;
6427c478bd9Sstevel@tonic-gate 
6437c478bd9Sstevel@tonic-gate 	if (setjmp(xdr_err)) {
6447c478bd9Sstevel@tonic-gate 		(void) sprintf(get_line(0, 0),
6457c478bd9Sstevel@tonic-gate 		    " %d+ maps. (Frame is incomplete)",
6467c478bd9Sstevel@tonic-gate 		    maps);
6477c478bd9Sstevel@tonic-gate 		return;
6487c478bd9Sstevel@tonic-gate 	}
6497c478bd9Sstevel@tonic-gate 
6507c478bd9Sstevel@tonic-gate 	show_space();
6517c478bd9Sstevel@tonic-gate 	(void) sprintf(get_line(0, 0),
6527c478bd9Sstevel@tonic-gate 	    " Program Vers Netid        Uaddr              Owner");
6537c478bd9Sstevel@tonic-gate 
6547c478bd9Sstevel@tonic-gate 	while (getxdr_u_long()) {
6557c478bd9Sstevel@tonic-gate 		prog  = getxdr_u_long();
6567c478bd9Sstevel@tonic-gate 		vers  = getxdr_u_long();
6577c478bd9Sstevel@tonic-gate 		(void) getxdr_string(netid, MAXSTRINGLEN);
6587c478bd9Sstevel@tonic-gate 		(void) getxdr_string(uaddr, MAXSTRINGLEN);
6597c478bd9Sstevel@tonic-gate 		(void) getxdr_string(owner, MAXSTRINGLEN);
6607c478bd9Sstevel@tonic-gate 		(void) sprintf(get_line(0, 0),
6617c478bd9Sstevel@tonic-gate 		    "%8d%5d %-12s %-18s %-10s (%s)",
6627c478bd9Sstevel@tonic-gate 		    prog, vers,
6637c478bd9Sstevel@tonic-gate 		    netid, uaddr, owner,
6647c478bd9Sstevel@tonic-gate 		    nameof_prog(prog));
6657c478bd9Sstevel@tonic-gate 		maps++;
6667c478bd9Sstevel@tonic-gate 	}
6677c478bd9Sstevel@tonic-gate 
6687c478bd9Sstevel@tonic-gate 	(void) sprintf(get_line(0, 0), " (%d maps)", maps);
6697c478bd9Sstevel@tonic-gate }
6707c478bd9Sstevel@tonic-gate 
6717c478bd9Sstevel@tonic-gate char *
sum_rpcb_entry_list()6727c478bd9Sstevel@tonic-gate sum_rpcb_entry_list()
6737c478bd9Sstevel@tonic-gate {
6747c478bd9Sstevel@tonic-gate 	int maps = 0;
6757c478bd9Sstevel@tonic-gate 	static char buff[MAXSTRINGLEN + 1];
6767c478bd9Sstevel@tonic-gate 
6777c478bd9Sstevel@tonic-gate 	if (setjmp(xdr_err)) {
6787c478bd9Sstevel@tonic-gate 		(void) sprintf(buff, "%d+ map(s) found", maps);
6797c478bd9Sstevel@tonic-gate 		return (buff);
6807c478bd9Sstevel@tonic-gate 	}
6817c478bd9Sstevel@tonic-gate 
6827c478bd9Sstevel@tonic-gate 	while (getxdr_u_long()) {
6837c478bd9Sstevel@tonic-gate 		(void) getxdr_string(buff, MAXSTRINGLEN); /* maddr	*/
6847c478bd9Sstevel@tonic-gate 		(void) getxdr_string(buff, MAXSTRINGLEN); /* nc_netid	*/
6857c478bd9Sstevel@tonic-gate 		(void) getxdr_u_long();			  /* nc_semantics */
6867c478bd9Sstevel@tonic-gate 		(void) getxdr_string(buff, MAXSTRINGLEN); /* nc_protofmly */
6877c478bd9Sstevel@tonic-gate 		(void) getxdr_string(buff, MAXSTRINGLEN); /* nc_proto	*/
6887c478bd9Sstevel@tonic-gate 		maps++;
6897c478bd9Sstevel@tonic-gate 	}
6907c478bd9Sstevel@tonic-gate 
6917c478bd9Sstevel@tonic-gate 	(void) sprintf(buff, "%d map(s) found", maps);
6927c478bd9Sstevel@tonic-gate 	return (buff);
6937c478bd9Sstevel@tonic-gate }
6947c478bd9Sstevel@tonic-gate 
6957c478bd9Sstevel@tonic-gate char *semantics_strs[] = {"", "CLTS", "COTS", "COTS-ORD", "RAW"};
6967c478bd9Sstevel@tonic-gate 
6977c478bd9Sstevel@tonic-gate void
show_rpcb_entry_list()6987c478bd9Sstevel@tonic-gate show_rpcb_entry_list()
6997c478bd9Sstevel@tonic-gate {
7007c478bd9Sstevel@tonic-gate 	char maddr[MAXSTRINGLEN + 1], netid[MAXSTRINGLEN + 1];
7017c478bd9Sstevel@tonic-gate 	char protofmly[MAXSTRINGLEN + 1], proto[MAXSTRINGLEN + 1];
7027c478bd9Sstevel@tonic-gate 	unsigned sem;
7037c478bd9Sstevel@tonic-gate 	int maps = 0;
7047c478bd9Sstevel@tonic-gate 
7057c478bd9Sstevel@tonic-gate 	if (setjmp(xdr_err)) {
7067c478bd9Sstevel@tonic-gate 		(void) sprintf(get_line(0, 0),
7077c478bd9Sstevel@tonic-gate 		    " %d+ maps. (Frame is incomplete)",
7087c478bd9Sstevel@tonic-gate 		    maps);
7097c478bd9Sstevel@tonic-gate 		return;
7107c478bd9Sstevel@tonic-gate 	}
7117c478bd9Sstevel@tonic-gate 
7127c478bd9Sstevel@tonic-gate 	show_space();
7137c478bd9Sstevel@tonic-gate 	(void) sprintf(get_line(0, 0),
7147c478bd9Sstevel@tonic-gate 	    " Maddr      Netid        Semantics Protofmly Proto");
7157c478bd9Sstevel@tonic-gate 
7167c478bd9Sstevel@tonic-gate 	while (getxdr_u_long()) {
7177c478bd9Sstevel@tonic-gate 		(void) getxdr_string(maddr, MAXSTRINGLEN);
7187c478bd9Sstevel@tonic-gate 		(void) getxdr_string(netid, MAXSTRINGLEN);
7197c478bd9Sstevel@tonic-gate 		sem  = getxdr_u_long();
7207c478bd9Sstevel@tonic-gate 		(void) getxdr_string(protofmly, MAXSTRINGLEN);
7217c478bd9Sstevel@tonic-gate 		(void) getxdr_string(proto, MAXSTRINGLEN);
7227c478bd9Sstevel@tonic-gate 		(void) sprintf(get_line(0, 0),
7237c478bd9Sstevel@tonic-gate 		    "%-12s %-12s %-8s %-8s %-8s",
7247c478bd9Sstevel@tonic-gate 		    maddr, netid,
7257c478bd9Sstevel@tonic-gate 		    semantics_strs[sem],
7267c478bd9Sstevel@tonic-gate 		    protofmly, proto);
7277c478bd9Sstevel@tonic-gate 		maps++;
7287c478bd9Sstevel@tonic-gate 	}
7297c478bd9Sstevel@tonic-gate 
7307c478bd9Sstevel@tonic-gate 	(void) sprintf(get_line(0, 0), " (%d maps)", maps);
7317c478bd9Sstevel@tonic-gate }
7327c478bd9Sstevel@tonic-gate 
7337c478bd9Sstevel@tonic-gate #define	CXID_CACHE_SIZE	16
7347c478bd9Sstevel@tonic-gate struct cache_struct cxid_cache[CXID_CACHE_SIZE];
7357c478bd9Sstevel@tonic-gate struct cache_struct *cxcpfirst	= &cxid_cache[0];
7367c478bd9Sstevel@tonic-gate struct cache_struct *cxcp	= &cxid_cache[0];
7377c478bd9Sstevel@tonic-gate struct cache_struct *cxcplast   = &cxid_cache[CXID_CACHE_SIZE - 1];
7387c478bd9Sstevel@tonic-gate 
7397c478bd9Sstevel@tonic-gate struct cache_struct *
find_callit(xid)7407c478bd9Sstevel@tonic-gate find_callit(xid)
7417c478bd9Sstevel@tonic-gate 	ulong_t xid;
7427c478bd9Sstevel@tonic-gate {
7437c478bd9Sstevel@tonic-gate 	struct cache_struct *x;
7447c478bd9Sstevel@tonic-gate 
7457c478bd9Sstevel@tonic-gate 	for (x = cxcp; x >= cxcpfirst; x--)
7467c478bd9Sstevel@tonic-gate 		if (x->xid_num == xid)
7477c478bd9Sstevel@tonic-gate 			return (x);
7487c478bd9Sstevel@tonic-gate 	for (x = cxcplast; x > cxcp; x--)
7497c478bd9Sstevel@tonic-gate 		if (x->xid_num == xid)
7507c478bd9Sstevel@tonic-gate 			return (x);
7517c478bd9Sstevel@tonic-gate 	return (NULL);
7527c478bd9Sstevel@tonic-gate }
7537c478bd9Sstevel@tonic-gate 
7547c478bd9Sstevel@tonic-gate static void
stash_callit(xid,frame,prog,vers,proc)7557c478bd9Sstevel@tonic-gate stash_callit(xid, frame, prog, vers, proc)
7567c478bd9Sstevel@tonic-gate 	ulong_t xid;
7577c478bd9Sstevel@tonic-gate 	int frame, prog, vers, proc;
7587c478bd9Sstevel@tonic-gate {
7597c478bd9Sstevel@tonic-gate 	struct cache_struct *x;
7607c478bd9Sstevel@tonic-gate 
7617c478bd9Sstevel@tonic-gate 	x = find_callit(xid);
7627c478bd9Sstevel@tonic-gate 	if (x == NULL) {
7637c478bd9Sstevel@tonic-gate 		x = cxcp++;
7647c478bd9Sstevel@tonic-gate 		if (cxcp > cxcplast)
7657c478bd9Sstevel@tonic-gate 			cxcp = cxcpfirst;
7667c478bd9Sstevel@tonic-gate 		x->xid_num = xid;
7677c478bd9Sstevel@tonic-gate 		x->xid_frame = frame;
7687c478bd9Sstevel@tonic-gate 	}
7697c478bd9Sstevel@tonic-gate 	x->xid_prog = prog;
7707c478bd9Sstevel@tonic-gate 	x->xid_vers = vers;
7717c478bd9Sstevel@tonic-gate 	x->xid_proc = proc;
7727c478bd9Sstevel@tonic-gate }
773