xref: /illumos-gate/usr/src/cmd/rpcinfo/rpcinfo.c (revision a1cf91d7)
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
5791dfaa7SVallish Vaidyeshwara  * Common Development and Distribution License (the "License").
6791dfaa7SVallish Vaidyeshwara  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
2020d0ade9SMarcel Telka  */
2120d0ade9SMarcel Telka 
2220d0ade9SMarcel Telka /*
2320d0ade9SMarcel Telka  * Copyright 2015 Nexenta Systems, Inc.  All rights reserved.
2420d0ade9SMarcel Telka  */
2520d0ade9SMarcel Telka 
2620d0ade9SMarcel Telka /*
27791dfaa7SVallish Vaidyeshwara  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
287c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
297c478bd9Sstevel@tonic-gate  */
307c478bd9Sstevel@tonic-gate /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
317c478bd9Sstevel@tonic-gate /* All Rights Reserved */
327c478bd9Sstevel@tonic-gate /*
337c478bd9Sstevel@tonic-gate  * University Copyright- Copyright (c) 1982, 1986, 1988
347c478bd9Sstevel@tonic-gate  * The Regents of the University of California
357c478bd9Sstevel@tonic-gate  * All Rights Reserved
367c478bd9Sstevel@tonic-gate  *
377c478bd9Sstevel@tonic-gate  * University Acknowledgment- Portions of this document are derived from
387c478bd9Sstevel@tonic-gate  * software developed by the University of California, Berkeley, and its
397c478bd9Sstevel@tonic-gate  * contributors.
407c478bd9Sstevel@tonic-gate  */
417c478bd9Sstevel@tonic-gate 
427c478bd9Sstevel@tonic-gate /*
437c478bd9Sstevel@tonic-gate  * rpcinfo: ping a particular rpc program
447c478bd9Sstevel@tonic-gate  * 	or dump the the registered programs on the remote machine.
457c478bd9Sstevel@tonic-gate  */
467c478bd9Sstevel@tonic-gate 
477c478bd9Sstevel@tonic-gate /*
4820d0ade9SMarcel Telka  * We are for now defining PORTMAP here.  It doesn't even compile
497c478bd9Sstevel@tonic-gate  * unless it is defined.
507c478bd9Sstevel@tonic-gate  */
517c478bd9Sstevel@tonic-gate #ifndef	PORTMAP
527c478bd9Sstevel@tonic-gate #define	PORTMAP
537c478bd9Sstevel@tonic-gate #endif
547c478bd9Sstevel@tonic-gate 
557c478bd9Sstevel@tonic-gate /*
567c478bd9Sstevel@tonic-gate  * If PORTMAP is defined, rpcinfo will talk to both portmapper and
577c478bd9Sstevel@tonic-gate  * rpcbind programs; else it talks only to rpcbind. In the latter case
587c478bd9Sstevel@tonic-gate  * all the portmapper specific options such as -u, -t, -p become void.
597c478bd9Sstevel@tonic-gate  */
607c478bd9Sstevel@tonic-gate #include <rpc/rpc.h>
617c478bd9Sstevel@tonic-gate #include <stdio.h>
627c478bd9Sstevel@tonic-gate #include <rpc/rpcb_prot.h>
637c478bd9Sstevel@tonic-gate #include <rpc/nettype.h>
647c478bd9Sstevel@tonic-gate #include <netdir.h>
657c478bd9Sstevel@tonic-gate #include <rpc/rpcent.h>
667c478bd9Sstevel@tonic-gate #include <stdlib.h>
677c478bd9Sstevel@tonic-gate #include <string.h>
68791dfaa7SVallish Vaidyeshwara #include <ctype.h>
697c478bd9Sstevel@tonic-gate 
707c478bd9Sstevel@tonic-gate #ifdef PORTMAP		/* Support for version 2 portmapper */
717c478bd9Sstevel@tonic-gate #include <netinet/in.h>
727c478bd9Sstevel@tonic-gate #include <sys/socket.h>
737c478bd9Sstevel@tonic-gate #include <netdb.h>
747c478bd9Sstevel@tonic-gate #include <arpa/inet.h>
757c478bd9Sstevel@tonic-gate #include <rpc/pmap_prot.h>
767c478bd9Sstevel@tonic-gate #include <rpc/pmap_clnt.h>
777c478bd9Sstevel@tonic-gate #endif
787c478bd9Sstevel@tonic-gate 
797c478bd9Sstevel@tonic-gate #define	MAXHOSTLEN	256
807c478bd9Sstevel@tonic-gate #define	MIN_VERS	((ulong_t)0)
81653c780cSssdevi #define	MAX_VERS	(4294967295UL)
827c478bd9Sstevel@tonic-gate #define	UNKNOWN		"unknown"
837c478bd9Sstevel@tonic-gate 
847c478bd9Sstevel@tonic-gate #define	MAX(a, b) (((a) > (b)) ? (a) : (b))
857c478bd9Sstevel@tonic-gate 
867c478bd9Sstevel@tonic-gate extern int	t_errno;
877c478bd9Sstevel@tonic-gate extern long	strtol();
887c478bd9Sstevel@tonic-gate static char *spaces();
897c478bd9Sstevel@tonic-gate 
907c478bd9Sstevel@tonic-gate #ifdef PORTMAP
917c478bd9Sstevel@tonic-gate static void	ip_ping(/*ushort_t portflag, char *trans,
927c478bd9Sstevel@tonic-gate 				int argc, char **argv*/);
937c478bd9Sstevel@tonic-gate static CLIENT	*clnt_com_create(/* struct sockaddr_in *addr, long prog,
947c478bd9Sstevel@tonic-gate 			long vers, int *fd, char *trans*/);
957c478bd9Sstevel@tonic-gate static void	pmapdump(/*int argc, char **argv*/);
967c478bd9Sstevel@tonic-gate static void	get_inet_address(/*struct sockaddr_in *addr, char *host*/);
977c478bd9Sstevel@tonic-gate #endif
987c478bd9Sstevel@tonic-gate 
997c478bd9Sstevel@tonic-gate static bool_t	reply_proc(/*void *res, struct netbuf *who*,
1007c478bd9Sstevel@tonic-gate 			struct netconfig *nconf*/);
1017c478bd9Sstevel@tonic-gate static void	brdcst(/*int argc, char **argv*/);
1027c478bd9Sstevel@tonic-gate static void	addrping(/*char *address, char *netid,
1037c478bd9Sstevel@tonic-gate 				int argc, char **argv*/);
1047c478bd9Sstevel@tonic-gate static void	progping(/* char *netid, int argc, char **argv*/);
1057c478bd9Sstevel@tonic-gate static CLIENT	*clnt_addr_create(/* char *addr, struct netconfig *nconf,
1067c478bd9Sstevel@tonic-gate 				long prog, long vers*/);
1077c478bd9Sstevel@tonic-gate static CLIENT   *clnt_rpcbind_create(/* char *host, int vers */);
1087c478bd9Sstevel@tonic-gate static CLIENT   *getclnthandle(/* host, nconf, rpcbversnum */);
1097c478bd9Sstevel@tonic-gate static int	pstatus(/*CLIENT *client, ulong_t prognum, ulong_t vers*/);
1107c478bd9Sstevel@tonic-gate static void	rpcbdump(/*char *netid, int argc, char **argv*/);
1117c478bd9Sstevel@tonic-gate static void	rpcbgetstat(/* int argc, char **argv*/);
1127c478bd9Sstevel@tonic-gate static void	rpcbaddrlist(/*char *netid, int argc, char **argv*/);
1137c478bd9Sstevel@tonic-gate static void	deletereg(/*char *netid, int argc, char **argv */);
1147c478bd9Sstevel@tonic-gate static void	print_rmtcallstat(/* rtype, infp */);
1157c478bd9Sstevel@tonic-gate static void	print_getaddrstat(/* rtype, infp */);
1167c478bd9Sstevel@tonic-gate static void	usage(/*void*/);
1177c478bd9Sstevel@tonic-gate static ulong_t	getprognum(/*char *arg*/);
1187c478bd9Sstevel@tonic-gate static ulong_t	getvers(/*char *arg*/);
1197c478bd9Sstevel@tonic-gate 
1207c478bd9Sstevel@tonic-gate /*
1217c478bd9Sstevel@tonic-gate  * Functions to be performed.
1227c478bd9Sstevel@tonic-gate  */
1237c478bd9Sstevel@tonic-gate #define	NONE		0	/* no function */
1247c478bd9Sstevel@tonic-gate #define	PMAPDUMP	1	/* dump portmapper registrations */
1257c478bd9Sstevel@tonic-gate #define	TCPPING		2	/* ping TCP service */
1267c478bd9Sstevel@tonic-gate #define	UDPPING		3	/* ping UDP service */
1277c478bd9Sstevel@tonic-gate #define	BROADCAST	4	/* ping broadcast service */
1287c478bd9Sstevel@tonic-gate #define	DELETES		5	/* delete registration for the service */
1297c478bd9Sstevel@tonic-gate #define	ADDRPING	6	/* pings at the given address */
1307c478bd9Sstevel@tonic-gate #define	PROGPING	7	/* pings a program on a given host */
1317c478bd9Sstevel@tonic-gate #define	RPCBDUMP	8	/* dump rpcbind registrations */
1327c478bd9Sstevel@tonic-gate #define	RPCBDUMP_SHORT	9	/* dump rpcbind registrations - short version */
1337c478bd9Sstevel@tonic-gate #define	RPCBADDRLIST	10	/* dump addr list about one prog */
1347c478bd9Sstevel@tonic-gate #define	RPCBGETSTAT	11	/* Get statistics */
1357c478bd9Sstevel@tonic-gate 
1367c478bd9Sstevel@tonic-gate struct netidlist {
1377c478bd9Sstevel@tonic-gate 	char *netid;
1387c478bd9Sstevel@tonic-gate 	struct netidlist *next;
1397c478bd9Sstevel@tonic-gate };
1407c478bd9Sstevel@tonic-gate 
1417c478bd9Sstevel@tonic-gate struct verslist {
1427c478bd9Sstevel@tonic-gate 	int vers;
1437c478bd9Sstevel@tonic-gate 	struct verslist *next;
1447c478bd9Sstevel@tonic-gate };
1457c478bd9Sstevel@tonic-gate 
1467c478bd9Sstevel@tonic-gate struct rpcbdump_short {
1477c478bd9Sstevel@tonic-gate 	ulong_t prog;
1487c478bd9Sstevel@tonic-gate 	struct verslist *vlist;
1497c478bd9Sstevel@tonic-gate 	struct netidlist *nlist;
1507c478bd9Sstevel@tonic-gate 	struct rpcbdump_short *next;
1517c478bd9Sstevel@tonic-gate 	char *owner;
1527c478bd9Sstevel@tonic-gate };
1537c478bd9Sstevel@tonic-gate 
1547c478bd9Sstevel@tonic-gate 
1557c478bd9Sstevel@tonic-gate char *loopback_netid = NULL;
1567c478bd9Sstevel@tonic-gate struct netconfig *loopback_nconf;
1577c478bd9Sstevel@tonic-gate 
1587c478bd9Sstevel@tonic-gate int
main(argc,argv)1597c478bd9Sstevel@tonic-gate main(argc, argv)
1607c478bd9Sstevel@tonic-gate 	int argc;
1617c478bd9Sstevel@tonic-gate 	char **argv;
1627c478bd9Sstevel@tonic-gate {
1637c478bd9Sstevel@tonic-gate 	register int c;
1647c478bd9Sstevel@tonic-gate 	extern char *optarg;
1657c478bd9Sstevel@tonic-gate 	extern int optind;
1667c478bd9Sstevel@tonic-gate 	int errflg;
1677c478bd9Sstevel@tonic-gate 	int function;
1687c478bd9Sstevel@tonic-gate 	char *netid = NULL;
1697c478bd9Sstevel@tonic-gate 	char *address = NULL;
1707c478bd9Sstevel@tonic-gate 	void *handle;
1717c478bd9Sstevel@tonic-gate #ifdef PORTMAP
1727c478bd9Sstevel@tonic-gate 	char *strptr;
1737c478bd9Sstevel@tonic-gate 	ushort_t portnum = 0;
1747c478bd9Sstevel@tonic-gate #endif
1757c478bd9Sstevel@tonic-gate 
1767c478bd9Sstevel@tonic-gate 	function = NONE;
1777c478bd9Sstevel@tonic-gate 	errflg = 0;
1787c478bd9Sstevel@tonic-gate #ifdef PORTMAP
1797c478bd9Sstevel@tonic-gate 	while ((c = getopt(argc, argv, "a:bdlmn:pstT:u")) != EOF) {
1807c478bd9Sstevel@tonic-gate #else
1817c478bd9Sstevel@tonic-gate 	while ((c = getopt(argc, argv, "a:bdlmn:sT:")) != EOF) {
1827c478bd9Sstevel@tonic-gate #endif
1837c478bd9Sstevel@tonic-gate 		switch (c) {
1847c478bd9Sstevel@tonic-gate #ifdef PORTMAP
1857c478bd9Sstevel@tonic-gate 		case 'p':
1867c478bd9Sstevel@tonic-gate 			if (function != NONE)
1877c478bd9Sstevel@tonic-gate 				errflg = 1;
1887c478bd9Sstevel@tonic-gate 			else
1897c478bd9Sstevel@tonic-gate 				function = PMAPDUMP;
1907c478bd9Sstevel@tonic-gate 			break;
1917c478bd9Sstevel@tonic-gate 
1927c478bd9Sstevel@tonic-gate 		case 't':
1937c478bd9Sstevel@tonic-gate 			if (function != NONE)
1947c478bd9Sstevel@tonic-gate 				errflg = 1;
1957c478bd9Sstevel@tonic-gate 			else
1967c478bd9Sstevel@tonic-gate 				function = TCPPING;
1977c478bd9Sstevel@tonic-gate 			break;
1987c478bd9Sstevel@tonic-gate 
1997c478bd9Sstevel@tonic-gate 		case 'u':
2007c478bd9Sstevel@tonic-gate 			if (function != NONE)
2017c478bd9Sstevel@tonic-gate 				errflg = 1;
2027c478bd9Sstevel@tonic-gate 			else
2037c478bd9Sstevel@tonic-gate 				function = UDPPING;
2047c478bd9Sstevel@tonic-gate 			break;
2057c478bd9Sstevel@tonic-gate 
2067c478bd9Sstevel@tonic-gate 		case 'n':
2077c478bd9Sstevel@tonic-gate 			portnum = (ushort_t)strtol(optarg, &strptr, 10);
2087c478bd9Sstevel@tonic-gate 			if (strptr == optarg || *strptr != '\0') {
209791dfaa7SVallish Vaidyeshwara 				(void) fprintf(stderr,
2107c478bd9Sstevel@tonic-gate 			"rpcinfo: %s is illegal port number\n",
2117c478bd9Sstevel@tonic-gate 					optarg);
2127c478bd9Sstevel@tonic-gate 				exit(1);
2137c478bd9Sstevel@tonic-gate 			}
2147c478bd9Sstevel@tonic-gate 			break;
2157c478bd9Sstevel@tonic-gate #endif
2167c478bd9Sstevel@tonic-gate 		case 'a':
2177c478bd9Sstevel@tonic-gate 			address = optarg;
2187c478bd9Sstevel@tonic-gate 			if (function != NONE)
2197c478bd9Sstevel@tonic-gate 				errflg = 1;
2207c478bd9Sstevel@tonic-gate 			else
2217c478bd9Sstevel@tonic-gate 				function = ADDRPING;
2227c478bd9Sstevel@tonic-gate 			break;
2237c478bd9Sstevel@tonic-gate 		case 'b':
2247c478bd9Sstevel@tonic-gate 			if (function != NONE)
2257c478bd9Sstevel@tonic-gate 				errflg = 1;
2267c478bd9Sstevel@tonic-gate 			else
2277c478bd9Sstevel@tonic-gate 				function = BROADCAST;
2287c478bd9Sstevel@tonic-gate 			break;
2297c478bd9Sstevel@tonic-gate 
2307c478bd9Sstevel@tonic-gate 		case 'd':
2317c478bd9Sstevel@tonic-gate 			if (function != NONE)
2327c478bd9Sstevel@tonic-gate 				errflg = 1;
2337c478bd9Sstevel@tonic-gate 			else
2347c478bd9Sstevel@tonic-gate 				function = DELETES;
2357c478bd9Sstevel@tonic-gate 			break;
2367c478bd9Sstevel@tonic-gate 
2377c478bd9Sstevel@tonic-gate 		case 'l':
2387c478bd9Sstevel@tonic-gate 			if (function != NONE)
2397c478bd9Sstevel@tonic-gate 				errflg = 1;
2407c478bd9Sstevel@tonic-gate 			else
2417c478bd9Sstevel@tonic-gate 				function = RPCBADDRLIST;
2427c478bd9Sstevel@tonic-gate 			break;
2437c478bd9Sstevel@tonic-gate 
2447c478bd9Sstevel@tonic-gate 		case 'm':
2457c478bd9Sstevel@tonic-gate 			if (function != NONE)
2467c478bd9Sstevel@tonic-gate 				errflg = 1;
2477c478bd9Sstevel@tonic-gate 			else
2487c478bd9Sstevel@tonic-gate 				function = RPCBGETSTAT;
2497c478bd9Sstevel@tonic-gate 			break;
2507c478bd9Sstevel@tonic-gate 
2517c478bd9Sstevel@tonic-gate 		case 's':
2527c478bd9Sstevel@tonic-gate 			if (function != NONE)
2537c478bd9Sstevel@tonic-gate 				errflg = 1;
2547c478bd9Sstevel@tonic-gate 			else
2557c478bd9Sstevel@tonic-gate 				function = RPCBDUMP_SHORT;
2567c478bd9Sstevel@tonic-gate 			break;
2577c478bd9Sstevel@tonic-gate 
2587c478bd9Sstevel@tonic-gate 		case 'T':
2597c478bd9Sstevel@tonic-gate 			netid = optarg;
2607c478bd9Sstevel@tonic-gate 			break;
2617c478bd9Sstevel@tonic-gate 		case '?':
2627c478bd9Sstevel@tonic-gate 			errflg = 1;
2637c478bd9Sstevel@tonic-gate 			break;
2647c478bd9Sstevel@tonic-gate 		}
2657c478bd9Sstevel@tonic-gate 	}
2667c478bd9Sstevel@tonic-gate 
2677c478bd9Sstevel@tonic-gate 	if (errflg || ((function == ADDRPING) && !netid)) {
2687c478bd9Sstevel@tonic-gate 		usage();
2697c478bd9Sstevel@tonic-gate 		return (1);
2707c478bd9Sstevel@tonic-gate 	}
2717c478bd9Sstevel@tonic-gate 	if (netid == NULL) {	/* user has not selected transport to use */
2727c478bd9Sstevel@tonic-gate 		/*
2737c478bd9Sstevel@tonic-gate 		 * See if a COTS loopback transport is available, in case we
2747c478bd9Sstevel@tonic-gate 		 * will be talking to the local system.
2757c478bd9Sstevel@tonic-gate 		 */
2767c478bd9Sstevel@tonic-gate 		handle = setnetconfig();
2777c478bd9Sstevel@tonic-gate 		while ((loopback_nconf = getnetconfig(handle)) != NULL) {
2787c478bd9Sstevel@tonic-gate 			if (strcmp(loopback_nconf->nc_protofmly,
2797c478bd9Sstevel@tonic-gate 				NC_LOOPBACK) == 0 &&
2807c478bd9Sstevel@tonic-gate 			    (loopback_nconf->nc_semantics == NC_TPI_COTS ||
2817c478bd9Sstevel@tonic-gate 			    loopback_nconf->nc_semantics == NC_TPI_COTS_ORD)) {
2827c478bd9Sstevel@tonic-gate 				loopback_netid = loopback_nconf->nc_netid;
2837c478bd9Sstevel@tonic-gate 				break;
2847c478bd9Sstevel@tonic-gate 			}
2857c478bd9Sstevel@tonic-gate 		}
2867c478bd9Sstevel@tonic-gate 		if (loopback_netid == NULL) {
287791dfaa7SVallish Vaidyeshwara 			(void) endnetconfig(handle);
2887c478bd9Sstevel@tonic-gate 		}
2897c478bd9Sstevel@tonic-gate 	}
2907c478bd9Sstevel@tonic-gate 	if (function == NONE) {
2917c478bd9Sstevel@tonic-gate 		if (argc - optind > 1)
2927c478bd9Sstevel@tonic-gate 			function = PROGPING;
2937c478bd9Sstevel@tonic-gate 		else
2947c478bd9Sstevel@tonic-gate 			function = RPCBDUMP;
2957c478bd9Sstevel@tonic-gate 	}
2967c478bd9Sstevel@tonic-gate 
2977c478bd9Sstevel@tonic-gate 	switch (function) {
2987c478bd9Sstevel@tonic-gate #ifdef PORTMAP
2997c478bd9Sstevel@tonic-gate 	case PMAPDUMP:
3007c478bd9Sstevel@tonic-gate 		if (portnum != 0) {
3017c478bd9Sstevel@tonic-gate 			usage();
3027c478bd9Sstevel@tonic-gate 			return (1);
3037c478bd9Sstevel@tonic-gate 		}
3047c478bd9Sstevel@tonic-gate 		pmapdump(argc - optind, argv + optind);
3057c478bd9Sstevel@tonic-gate 		break;
3067c478bd9Sstevel@tonic-gate 
3077c478bd9Sstevel@tonic-gate 	case UDPPING:
3087c478bd9Sstevel@tonic-gate 		ip_ping(portnum, "udp", argc - optind, argv + optind);
3097c478bd9Sstevel@tonic-gate 		break;
3107c478bd9Sstevel@tonic-gate 
3117c478bd9Sstevel@tonic-gate 	case TCPPING:
3127c478bd9Sstevel@tonic-gate 		ip_ping(portnum, "tcp", argc - optind, argv + optind);
3137c478bd9Sstevel@tonic-gate 		break;
3147c478bd9Sstevel@tonic-gate #endif
3157c478bd9Sstevel@tonic-gate 	case BROADCAST:
3167c478bd9Sstevel@tonic-gate 		brdcst(argc - optind, argv + optind);
3177c478bd9Sstevel@tonic-gate 		break;
3187c478bd9Sstevel@tonic-gate 	case DELETES:
3197c478bd9Sstevel@tonic-gate 		deletereg(netid, argc - optind, argv + optind);
3207c478bd9Sstevel@tonic-gate 		break;
3217c478bd9Sstevel@tonic-gate 	case ADDRPING:
3227c478bd9Sstevel@tonic-gate 		addrping(address, netid, argc - optind, argv + optind);
3237c478bd9Sstevel@tonic-gate 		break;
3247c478bd9Sstevel@tonic-gate 	case PROGPING:
3257c478bd9Sstevel@tonic-gate 		progping(netid, argc - optind, argv + optind);
3267c478bd9Sstevel@tonic-gate 		break;
3277c478bd9Sstevel@tonic-gate 	case RPCBDUMP:
3287c478bd9Sstevel@tonic-gate 	case RPCBDUMP_SHORT:
3297c478bd9Sstevel@tonic-gate 		rpcbdump(function, netid, argc - optind, argv + optind);
3307c478bd9Sstevel@tonic-gate 		break;
3317c478bd9Sstevel@tonic-gate 	case RPCBGETSTAT:
3327c478bd9Sstevel@tonic-gate 		rpcbgetstat(argc - optind, argv + optind);
3337c478bd9Sstevel@tonic-gate 		break;
3347c478bd9Sstevel@tonic-gate 	case RPCBADDRLIST:
3357c478bd9Sstevel@tonic-gate 		rpcbaddrlist(netid, argc - optind, argv + optind);
3367c478bd9Sstevel@tonic-gate 		break;
3377c478bd9Sstevel@tonic-gate 	}
3387c478bd9Sstevel@tonic-gate 	return (0);
3397c478bd9Sstevel@tonic-gate }
3407c478bd9Sstevel@tonic-gate 
3417c478bd9Sstevel@tonic-gate #ifdef PORTMAP
3427c478bd9Sstevel@tonic-gate static CLIENT *
clnt_com_create(addr,prog,vers,fdp,trans)3437c478bd9Sstevel@tonic-gate clnt_com_create(addr, prog, vers, fdp, trans)
3447c478bd9Sstevel@tonic-gate 	struct sockaddr_in *addr;
3457c478bd9Sstevel@tonic-gate 	ulong_t prog;
3467c478bd9Sstevel@tonic-gate 	ulong_t vers;
3477c478bd9Sstevel@tonic-gate 	int *fdp;
3487c478bd9Sstevel@tonic-gate 	char *trans;
3497c478bd9Sstevel@tonic-gate {
3507c478bd9Sstevel@tonic-gate 	CLIENT *clnt;
3517c478bd9Sstevel@tonic-gate 
3527c478bd9Sstevel@tonic-gate 	if (strcmp(trans, "tcp") == 0) {
3537c478bd9Sstevel@tonic-gate 		clnt = clnttcp_create(addr, prog, vers, fdp, 0, 0);
3547c478bd9Sstevel@tonic-gate 	} else {
3557c478bd9Sstevel@tonic-gate 		struct timeval to;
3567c478bd9Sstevel@tonic-gate 
3577c478bd9Sstevel@tonic-gate 		to.tv_sec = 5;
3587c478bd9Sstevel@tonic-gate 		to.tv_usec = 0;
3597c478bd9Sstevel@tonic-gate 		clnt = clntudp_create(addr, prog, vers, to, fdp);
3607c478bd9Sstevel@tonic-gate 	}
3617c478bd9Sstevel@tonic-gate 	if (clnt == (CLIENT *)NULL) {
3627c478bd9Sstevel@tonic-gate 		clnt_pcreateerror("rpcinfo");
3637c478bd9Sstevel@tonic-gate 		if (vers == MIN_VERS)
364791dfaa7SVallish Vaidyeshwara 			(void) printf("program %lu is not available\n", prog);
3657c478bd9Sstevel@tonic-gate 		else
366791dfaa7SVallish Vaidyeshwara 			(void) printf(
367791dfaa7SVallish Vaidyeshwara 				"program %lu version %lu is not available\n",
3687c478bd9Sstevel@tonic-gate 							prog, vers);
3697c478bd9Sstevel@tonic-gate 		exit(1);
3707c478bd9Sstevel@tonic-gate 	}
3717c478bd9Sstevel@tonic-gate 	return (clnt);
3727c478bd9Sstevel@tonic-gate }
3737c478bd9Sstevel@tonic-gate 
3747c478bd9Sstevel@tonic-gate /*
3757c478bd9Sstevel@tonic-gate  * If portnum is 0, then go and get the address from portmapper, which happens
3767c478bd9Sstevel@tonic-gate  * transparently through clnt*_create(); If version number is not given, it
3777c478bd9Sstevel@tonic-gate  * tries to find out the version number by making a call to version 0 and if
3787c478bd9Sstevel@tonic-gate  * that fails, it obtains the high order and the low order version number. If
3797c478bd9Sstevel@tonic-gate  * version 0 calls succeeds, it tries for MAXVERS call and repeats the same.
3807c478bd9Sstevel@tonic-gate  */
3817c478bd9Sstevel@tonic-gate static void
ip_ping(portnum,trans,argc,argv)3827c478bd9Sstevel@tonic-gate ip_ping(portnum, trans, argc, argv)
3837c478bd9Sstevel@tonic-gate 	ushort_t portnum;
3847c478bd9Sstevel@tonic-gate 	char *trans;
3857c478bd9Sstevel@tonic-gate 	int argc;
3867c478bd9Sstevel@tonic-gate 	char **argv;
3877c478bd9Sstevel@tonic-gate {
3887c478bd9Sstevel@tonic-gate 	CLIENT *client;
3897c478bd9Sstevel@tonic-gate 	int fd = RPC_ANYFD;
3907c478bd9Sstevel@tonic-gate 	struct timeval to;
3917c478bd9Sstevel@tonic-gate 	struct sockaddr_in addr;
3927c478bd9Sstevel@tonic-gate 	enum clnt_stat rpc_stat;
3937c478bd9Sstevel@tonic-gate 	ulong_t prognum, vers, minvers, maxvers;
3947c478bd9Sstevel@tonic-gate 	struct rpc_err rpcerr;
3957c478bd9Sstevel@tonic-gate 	int failure = 0;
3967c478bd9Sstevel@tonic-gate 
3977c478bd9Sstevel@tonic-gate 	if (argc < 2 || argc > 3) {
3987c478bd9Sstevel@tonic-gate 		usage();
3997c478bd9Sstevel@tonic-gate 		exit(1);
4007c478bd9Sstevel@tonic-gate 	}
4017c478bd9Sstevel@tonic-gate 	to.tv_sec = 10;
4027c478bd9Sstevel@tonic-gate 	to.tv_usec = 0;
4037c478bd9Sstevel@tonic-gate 	prognum = getprognum(argv[1]);
4047c478bd9Sstevel@tonic-gate 	get_inet_address(&addr, argv[0]);
4057c478bd9Sstevel@tonic-gate 	if (argc == 2) {	/* Version number not known */
4067c478bd9Sstevel@tonic-gate 		/*
4077c478bd9Sstevel@tonic-gate 		 * A call to version 0 should fail with a program/version
4087c478bd9Sstevel@tonic-gate 		 * mismatch, and give us the range of versions supported.
4097c478bd9Sstevel@tonic-gate 		 */
4107c478bd9Sstevel@tonic-gate 		vers = MIN_VERS;
4117c478bd9Sstevel@tonic-gate 	} else {
4127c478bd9Sstevel@tonic-gate 		vers = getvers(argv[2]);
4137c478bd9Sstevel@tonic-gate 	}
4147c478bd9Sstevel@tonic-gate 	addr.sin_port = htons(portnum);
4157c478bd9Sstevel@tonic-gate 	client = clnt_com_create(&addr, prognum, vers, &fd, trans);
4167c478bd9Sstevel@tonic-gate 	rpc_stat = CLNT_CALL(client, NULLPROC, (xdrproc_t)xdr_void,
4177c478bd9Sstevel@tonic-gate 			(char *)NULL, (xdrproc_t)xdr_void, (char *)NULL,
4187c478bd9Sstevel@tonic-gate 			to);
4197c478bd9Sstevel@tonic-gate 	if (argc != 2) {
4207c478bd9Sstevel@tonic-gate 		/* Version number was known */
4217c478bd9Sstevel@tonic-gate 		if (pstatus(client, prognum, vers) < 0)
4227c478bd9Sstevel@tonic-gate 			exit(1);
4237c478bd9Sstevel@tonic-gate 		(void) CLNT_DESTROY(client);
4247c478bd9Sstevel@tonic-gate 		return;
4257c478bd9Sstevel@tonic-gate 	}
4267c478bd9Sstevel@tonic-gate 	/* Version number not known */
4277c478bd9Sstevel@tonic-gate 	(void) CLNT_CONTROL(client, CLSET_FD_NCLOSE, (char *)NULL);
4287c478bd9Sstevel@tonic-gate 	if (rpc_stat == RPC_PROGVERSMISMATCH) {
4297c478bd9Sstevel@tonic-gate 		clnt_geterr(client, &rpcerr);
4307c478bd9Sstevel@tonic-gate 		minvers = rpcerr.re_vers.low;
4317c478bd9Sstevel@tonic-gate 		maxvers = rpcerr.re_vers.high;
4327c478bd9Sstevel@tonic-gate 	} else if (rpc_stat == RPC_SUCCESS) {
4337c478bd9Sstevel@tonic-gate 		/*
4347c478bd9Sstevel@tonic-gate 		 * Oh dear, it DOES support version 0.
4357c478bd9Sstevel@tonic-gate 		 * Let's try version MAX_VERS.
4367c478bd9Sstevel@tonic-gate 		 */
4377c478bd9Sstevel@tonic-gate 		(void) CLNT_DESTROY(client);
4387c478bd9Sstevel@tonic-gate 		addr.sin_port = htons(portnum);
4397c478bd9Sstevel@tonic-gate 		client = clnt_com_create(&addr, prognum, MAX_VERS, &fd, trans);
4407c478bd9Sstevel@tonic-gate 		rpc_stat = CLNT_CALL(client, NULLPROC, (xdrproc_t)xdr_void,
4417c478bd9Sstevel@tonic-gate 				(char *)NULL, (xdrproc_t)xdr_void,
4427c478bd9Sstevel@tonic-gate 				(char *)NULL, to);
4437c478bd9Sstevel@tonic-gate 		if (rpc_stat == RPC_PROGVERSMISMATCH) {
4447c478bd9Sstevel@tonic-gate 			clnt_geterr(client, &rpcerr);
4457c478bd9Sstevel@tonic-gate 			minvers = rpcerr.re_vers.low;
4467c478bd9Sstevel@tonic-gate 			maxvers = rpcerr.re_vers.high;
4477c478bd9Sstevel@tonic-gate 		} else if (rpc_stat == RPC_SUCCESS) {
4487c478bd9Sstevel@tonic-gate 			/*
4497c478bd9Sstevel@tonic-gate 			 * It also supports version MAX_VERS.
4507c478bd9Sstevel@tonic-gate 			 * Looks like we have a wise guy.
4517c478bd9Sstevel@tonic-gate 			 * OK, we give them information on all
4527c478bd9Sstevel@tonic-gate 			 * 4 billion versions they support...
4537c478bd9Sstevel@tonic-gate 			 */
4547c478bd9Sstevel@tonic-gate 			minvers = 0;
4557c478bd9Sstevel@tonic-gate 			maxvers = MAX_VERS;
4567c478bd9Sstevel@tonic-gate 		} else {
4577c478bd9Sstevel@tonic-gate 			(void) pstatus(client, prognum, MAX_VERS);
4587c478bd9Sstevel@tonic-gate 			exit(1);
4597c478bd9Sstevel@tonic-gate 		}
4607c478bd9Sstevel@tonic-gate 	} else {
4617c478bd9Sstevel@tonic-gate 		(void) pstatus(client, prognum, (ulong_t)0);
4627c478bd9Sstevel@tonic-gate 		exit(1);
4637c478bd9Sstevel@tonic-gate 	}
4647c478bd9Sstevel@tonic-gate 	(void) CLNT_DESTROY(client);
4657c478bd9Sstevel@tonic-gate 	for (vers = minvers; vers <= maxvers; vers++) {
4667c478bd9Sstevel@tonic-gate 		addr.sin_port = htons(portnum);
4677c478bd9Sstevel@tonic-gate 		client = clnt_com_create(&addr, prognum, vers, &fd, trans);
4687c478bd9Sstevel@tonic-gate 		rpc_stat = CLNT_CALL(client, NULLPROC, (xdrproc_t)xdr_void,
4697c478bd9Sstevel@tonic-gate 				(char *)NULL, (xdrproc_t)xdr_void,
4707c478bd9Sstevel@tonic-gate 				(char *)NULL, to);
4717c478bd9Sstevel@tonic-gate 		if (pstatus(client, prognum, vers) < 0)
4727c478bd9Sstevel@tonic-gate 				failure = 1;
4737c478bd9Sstevel@tonic-gate 		(void) CLNT_DESTROY(client);
4747c478bd9Sstevel@tonic-gate 	}
4757c478bd9Sstevel@tonic-gate 	if (failure)
4767c478bd9Sstevel@tonic-gate 		exit(1);
4777c478bd9Sstevel@tonic-gate 	(void) t_close(fd);
4787c478bd9Sstevel@tonic-gate }
4797c478bd9Sstevel@tonic-gate 
4807c478bd9Sstevel@tonic-gate /*
4817c478bd9Sstevel@tonic-gate  * Dump all the portmapper registerations
4827c478bd9Sstevel@tonic-gate  */
4837c478bd9Sstevel@tonic-gate static void
pmapdump(argc,argv)4847c478bd9Sstevel@tonic-gate pmapdump(argc, argv)
4857c478bd9Sstevel@tonic-gate 	int argc;
4867c478bd9Sstevel@tonic-gate 	char **argv;
4877c478bd9Sstevel@tonic-gate {
4887c478bd9Sstevel@tonic-gate 	struct sockaddr_in server_addr;
4897c478bd9Sstevel@tonic-gate 	pmaplist_ptr head = NULL;
4907c478bd9Sstevel@tonic-gate 	int socket = RPC_ANYSOCK;
4917c478bd9Sstevel@tonic-gate 	struct timeval minutetimeout;
4927c478bd9Sstevel@tonic-gate 	register CLIENT *client;
4937c478bd9Sstevel@tonic-gate 	struct rpcent *rpc;
4947c478bd9Sstevel@tonic-gate 	enum clnt_stat clnt_st;
4957c478bd9Sstevel@tonic-gate 	struct rpc_err err;
4967c478bd9Sstevel@tonic-gate 	char *host;
4977c478bd9Sstevel@tonic-gate 
4987c478bd9Sstevel@tonic-gate 	if (argc > 1) {
4997c478bd9Sstevel@tonic-gate 		usage();
5007c478bd9Sstevel@tonic-gate 		exit(1);
5017c478bd9Sstevel@tonic-gate 	}
5027c478bd9Sstevel@tonic-gate 	if (argc == 1) {
5037c478bd9Sstevel@tonic-gate 		host = argv[0];
5047c478bd9Sstevel@tonic-gate 	} else {
50520d0ade9SMarcel Telka 		host = HOST_SELF_CONNECT;
5067c478bd9Sstevel@tonic-gate 	}
50720d0ade9SMarcel Telka 	get_inet_address(&server_addr, host);
50820d0ade9SMarcel Telka 
5097c478bd9Sstevel@tonic-gate 	minutetimeout.tv_sec = 60;
5107c478bd9Sstevel@tonic-gate 	minutetimeout.tv_usec = 0;
5117c478bd9Sstevel@tonic-gate 	server_addr.sin_port = htons(PMAPPORT);
5127c478bd9Sstevel@tonic-gate 	if ((client = clnttcp_create(&server_addr, PMAPPROG,
5137c478bd9Sstevel@tonic-gate 		PMAPVERS, &socket, 50, 500)) == NULL) {
5147c478bd9Sstevel@tonic-gate 		if (rpc_createerr.cf_stat == RPC_TLIERROR) {
5157c478bd9Sstevel@tonic-gate 			/*
5167c478bd9Sstevel@tonic-gate 			 * "Misc. TLI error" is not too helpful. Most likely
5177c478bd9Sstevel@tonic-gate 			 * the connection to the remote server timed out, so
5187c478bd9Sstevel@tonic-gate 			 * this error is at least less perplexing.
5197c478bd9Sstevel@tonic-gate 			 */
5207c478bd9Sstevel@tonic-gate 			rpc_createerr.cf_stat = RPC_PMAPFAILURE;
5217c478bd9Sstevel@tonic-gate 			rpc_createerr.cf_error.re_status = RPC_FAILED;
5227c478bd9Sstevel@tonic-gate 		}
5237c478bd9Sstevel@tonic-gate 		clnt_pcreateerror("rpcinfo: can't contact portmapper");
5247c478bd9Sstevel@tonic-gate 		exit(1);
5257c478bd9Sstevel@tonic-gate 	}
5267c478bd9Sstevel@tonic-gate 	clnt_st = CLNT_CALL(client, PMAPPROC_DUMP, (xdrproc_t)xdr_void,
5277c478bd9Sstevel@tonic-gate 		NULL, (xdrproc_t)xdr_pmaplist_ptr, (char *)&head,
5287c478bd9Sstevel@tonic-gate 		minutetimeout);
5297c478bd9Sstevel@tonic-gate 	if (clnt_st != RPC_SUCCESS) {
5307c478bd9Sstevel@tonic-gate 		if ((clnt_st == RPC_PROGVERSMISMATCH) ||
5317c478bd9Sstevel@tonic-gate 		    (clnt_st == RPC_PROGUNAVAIL)) {
5327c478bd9Sstevel@tonic-gate 			CLNT_GETERR(client, &err);
5337c478bd9Sstevel@tonic-gate 			if (err.re_vers.low > PMAPVERS)
534791dfaa7SVallish Vaidyeshwara 				(void) fprintf(stderr,
5357c478bd9Sstevel@tonic-gate 		"%s does not support portmapper.  Try rpcinfo %s instead\n",
5367c478bd9Sstevel@tonic-gate 					host, host);
5377c478bd9Sstevel@tonic-gate 			exit(1);
5387c478bd9Sstevel@tonic-gate 		}
5397c478bd9Sstevel@tonic-gate 		clnt_perror(client, "rpcinfo: can't contact portmapper");
5407c478bd9Sstevel@tonic-gate 		exit(1);
5417c478bd9Sstevel@tonic-gate 	}
5427c478bd9Sstevel@tonic-gate 	if (head == NULL) {
543791dfaa7SVallish Vaidyeshwara 		(void) printf("No remote programs registered.\n");
5447c478bd9Sstevel@tonic-gate 	} else {
545791dfaa7SVallish Vaidyeshwara 		(void) printf("   program vers proto   port  service\n");
5467c478bd9Sstevel@tonic-gate 		for (; head != NULL; head = head->pml_next) {
547791dfaa7SVallish Vaidyeshwara 			(void) printf("%10ld%5ld",
5487c478bd9Sstevel@tonic-gate 				head->pml_map.pm_prog,
5497c478bd9Sstevel@tonic-gate 				head->pml_map.pm_vers);
5507c478bd9Sstevel@tonic-gate 			if (head->pml_map.pm_prot == IPPROTO_UDP)
551791dfaa7SVallish Vaidyeshwara 				(void) printf("%6s", "udp");
5527c478bd9Sstevel@tonic-gate 			else if (head->pml_map.pm_prot == IPPROTO_TCP)
553791dfaa7SVallish Vaidyeshwara 				(void) printf("%6s", "tcp");
5547c478bd9Sstevel@tonic-gate 			else
555791dfaa7SVallish Vaidyeshwara 				(void) printf("%6ld", head->pml_map.pm_prot);
556791dfaa7SVallish Vaidyeshwara 			(void) printf("%7ld", head->pml_map.pm_port);
5577c478bd9Sstevel@tonic-gate 			rpc = getrpcbynumber(head->pml_map.pm_prog);
5587c478bd9Sstevel@tonic-gate 			if (rpc)
559791dfaa7SVallish Vaidyeshwara 				(void) printf("  %s\n", rpc->r_name);
5607c478bd9Sstevel@tonic-gate 			else
561791dfaa7SVallish Vaidyeshwara 				(void) printf("\n");
5627c478bd9Sstevel@tonic-gate 		}
5637c478bd9Sstevel@tonic-gate 	}
5647c478bd9Sstevel@tonic-gate }
5657c478bd9Sstevel@tonic-gate 
5667c478bd9Sstevel@tonic-gate static void
get_inet_address(addr,host)5677c478bd9Sstevel@tonic-gate get_inet_address(addr, host)
5687c478bd9Sstevel@tonic-gate 	struct sockaddr_in *addr;
5697c478bd9Sstevel@tonic-gate 	char *host;
5707c478bd9Sstevel@tonic-gate {
5717c478bd9Sstevel@tonic-gate 	struct netconfig *nconf;
5727c478bd9Sstevel@tonic-gate 	struct nd_hostserv service;
5737c478bd9Sstevel@tonic-gate 	struct nd_addrlist *naddrs;
5747c478bd9Sstevel@tonic-gate 
5757c478bd9Sstevel@tonic-gate 	(void) memset((char *)addr, 0, sizeof (*addr));
5767c478bd9Sstevel@tonic-gate 	addr->sin_addr.s_addr = inet_addr(host);
577791dfaa7SVallish Vaidyeshwara 	if (addr->sin_addr.s_addr == (uint32_t)-1 ||
578791dfaa7SVallish Vaidyeshwara 	    addr->sin_addr.s_addr == 0) {
5797c478bd9Sstevel@tonic-gate 		if ((nconf = __rpc_getconfip("udp")) == NULL &&
5807c478bd9Sstevel@tonic-gate 		    (nconf = __rpc_getconfip("tcp")) == NULL) {
581791dfaa7SVallish Vaidyeshwara 			(void) fprintf(stderr,
5827c478bd9Sstevel@tonic-gate 			"rpcinfo: couldn't find a suitable transport\n");
5837c478bd9Sstevel@tonic-gate 			exit(1);
5847c478bd9Sstevel@tonic-gate 		} else {
5857c478bd9Sstevel@tonic-gate 			service.h_host = host;
5867c478bd9Sstevel@tonic-gate 			service.h_serv = "rpcbind";
5877c478bd9Sstevel@tonic-gate 			if (netdir_getbyname(nconf, &service, &naddrs)) {
588791dfaa7SVallish Vaidyeshwara 				(void) fprintf(stderr, "rpcinfo: %s: %s\n",
5897c478bd9Sstevel@tonic-gate 						host, netdir_sperror());
5907c478bd9Sstevel@tonic-gate 				exit(1);
5917c478bd9Sstevel@tonic-gate 			} else {
5927c478bd9Sstevel@tonic-gate 				(void) memcpy((caddr_t)addr,
5937c478bd9Sstevel@tonic-gate 				    naddrs->n_addrs->buf, naddrs->n_addrs->len);
5947c478bd9Sstevel@tonic-gate 				(void) netdir_free((char *)naddrs, ND_ADDRLIST);
5957c478bd9Sstevel@tonic-gate 			}
5967c478bd9Sstevel@tonic-gate 			(void) freenetconfigent(nconf);
5977c478bd9Sstevel@tonic-gate 		}
5987c478bd9Sstevel@tonic-gate 	} else {
5997c478bd9Sstevel@tonic-gate 		addr->sin_family = AF_INET;
6007c478bd9Sstevel@tonic-gate 	}
6017c478bd9Sstevel@tonic-gate }
6027c478bd9Sstevel@tonic-gate #endif /* PORTMAP */
6037c478bd9Sstevel@tonic-gate 
6047c478bd9Sstevel@tonic-gate /*
6057c478bd9Sstevel@tonic-gate  * reply_proc collects replies from the broadcast.
6067c478bd9Sstevel@tonic-gate  * to get a unique list of responses the output of rpcinfo should
6077c478bd9Sstevel@tonic-gate  * be piped through sort(1) and then uniq(1).
6087c478bd9Sstevel@tonic-gate  */
6097c478bd9Sstevel@tonic-gate 
6107c478bd9Sstevel@tonic-gate /*ARGSUSED*/
6117c478bd9Sstevel@tonic-gate static bool_t
reply_proc(res,who,nconf)6127c478bd9Sstevel@tonic-gate reply_proc(res, who, nconf)
6137c478bd9Sstevel@tonic-gate 	void *res;		/* Nothing comes back */
6147c478bd9Sstevel@tonic-gate 	struct netbuf *who;	/* Who sent us the reply */
6157c478bd9Sstevel@tonic-gate 	struct netconfig *nconf; /* On which transport the reply came */
6167c478bd9Sstevel@tonic-gate {
6177c478bd9Sstevel@tonic-gate 	struct nd_hostservlist *serv;
6187c478bd9Sstevel@tonic-gate 	char *uaddr;
6197c478bd9Sstevel@tonic-gate 	char *hostname;
6207c478bd9Sstevel@tonic-gate 
6217c478bd9Sstevel@tonic-gate 	if (netdir_getbyaddr(nconf, &serv, who)) {
6227c478bd9Sstevel@tonic-gate 		hostname = UNKNOWN;
6237c478bd9Sstevel@tonic-gate 	} else {
6247c478bd9Sstevel@tonic-gate 		hostname = serv->h_hostservs->h_host;
6257c478bd9Sstevel@tonic-gate 	}
6267c478bd9Sstevel@tonic-gate 	if (!(uaddr = taddr2uaddr(nconf, who))) {
6277c478bd9Sstevel@tonic-gate 		uaddr = UNKNOWN;
6287c478bd9Sstevel@tonic-gate 	}
629791dfaa7SVallish Vaidyeshwara 	(void) printf("%s\t%s\n", uaddr, hostname);
6307c478bd9Sstevel@tonic-gate 	if (strcmp(hostname, UNKNOWN))
6317c478bd9Sstevel@tonic-gate 		netdir_free((char *)serv, ND_HOSTSERVLIST);
6327c478bd9Sstevel@tonic-gate 	if (strcmp(uaddr, UNKNOWN))
6337c478bd9Sstevel@tonic-gate 		free((char *)uaddr);
6347c478bd9Sstevel@tonic-gate 	return (FALSE);
6357c478bd9Sstevel@tonic-gate }
6367c478bd9Sstevel@tonic-gate 
6377c478bd9Sstevel@tonic-gate static void
brdcst(argc,argv)6387c478bd9Sstevel@tonic-gate brdcst(argc, argv)
6397c478bd9Sstevel@tonic-gate 	int argc;
6407c478bd9Sstevel@tonic-gate 	char **argv;
6417c478bd9Sstevel@tonic-gate {
6427c478bd9Sstevel@tonic-gate 	enum clnt_stat rpc_stat;
6437c478bd9Sstevel@tonic-gate 	ulong_t prognum, vers;
6447c478bd9Sstevel@tonic-gate 
6457c478bd9Sstevel@tonic-gate 	if (argc != 2) {
6467c478bd9Sstevel@tonic-gate 		usage();
6477c478bd9Sstevel@tonic-gate 		exit(1);
6487c478bd9Sstevel@tonic-gate 	}
6497c478bd9Sstevel@tonic-gate 	prognum = getprognum(argv[0]);
6507c478bd9Sstevel@tonic-gate 	vers = getvers(argv[1]);
6517c478bd9Sstevel@tonic-gate 	rpc_stat = rpc_broadcast(prognum, vers, NULLPROC,
6527c478bd9Sstevel@tonic-gate 		(xdrproc_t)xdr_void, (char *)NULL, (xdrproc_t)xdr_void,
6537c478bd9Sstevel@tonic-gate 		(char *)NULL, (resultproc_t)reply_proc, NULL);
6547c478bd9Sstevel@tonic-gate 	if ((rpc_stat != RPC_SUCCESS) && (rpc_stat != RPC_TIMEDOUT)) {
655791dfaa7SVallish Vaidyeshwara 		(void) fprintf(stderr, "rpcinfo: broadcast failed: %s\n",
6567c478bd9Sstevel@tonic-gate 			clnt_sperrno(rpc_stat));
6577c478bd9Sstevel@tonic-gate 		exit(1);
6587c478bd9Sstevel@tonic-gate 	}
6597c478bd9Sstevel@tonic-gate 	exit(0);
6607c478bd9Sstevel@tonic-gate }
6617c478bd9Sstevel@tonic-gate 
6627c478bd9Sstevel@tonic-gate static bool_t
add_version(rs,vers)6637c478bd9Sstevel@tonic-gate add_version(rs, vers)
6647c478bd9Sstevel@tonic-gate 	struct rpcbdump_short *rs;
6657c478bd9Sstevel@tonic-gate 	ulong_t vers;
6667c478bd9Sstevel@tonic-gate {
6677c478bd9Sstevel@tonic-gate 	struct verslist *vl;
6687c478bd9Sstevel@tonic-gate 
6697c478bd9Sstevel@tonic-gate 	for (vl = rs->vlist; vl; vl = vl->next)
6707c478bd9Sstevel@tonic-gate 		if (vl->vers == vers)
6717c478bd9Sstevel@tonic-gate 			break;
6727c478bd9Sstevel@tonic-gate 	if (vl)
6737c478bd9Sstevel@tonic-gate 		return (TRUE);
6747c478bd9Sstevel@tonic-gate 	vl = (struct verslist *)malloc(sizeof (struct verslist));
6757c478bd9Sstevel@tonic-gate 	if (vl == NULL)
6767c478bd9Sstevel@tonic-gate 		return (FALSE);
6777c478bd9Sstevel@tonic-gate 	vl->vers = vers;
6787c478bd9Sstevel@tonic-gate 	vl->next = rs->vlist;
6797c478bd9Sstevel@tonic-gate 	rs->vlist = vl;
6807c478bd9Sstevel@tonic-gate 	return (TRUE);
6817c478bd9Sstevel@tonic-gate }
6827c478bd9Sstevel@tonic-gate 
6837c478bd9Sstevel@tonic-gate static bool_t
add_netid(rs,netid)6847c478bd9Sstevel@tonic-gate add_netid(rs, netid)
6857c478bd9Sstevel@tonic-gate 	struct rpcbdump_short *rs;
6867c478bd9Sstevel@tonic-gate 	char *netid;
6877c478bd9Sstevel@tonic-gate {
6887c478bd9Sstevel@tonic-gate 	struct netidlist *nl;
6897c478bd9Sstevel@tonic-gate 
6907c478bd9Sstevel@tonic-gate 	for (nl = rs->nlist; nl; nl = nl->next)
6917c478bd9Sstevel@tonic-gate 		if (strcmp(nl->netid, netid) == 0)
6927c478bd9Sstevel@tonic-gate 			break;
6937c478bd9Sstevel@tonic-gate 	if (nl)
6947c478bd9Sstevel@tonic-gate 		return (TRUE);
6957c478bd9Sstevel@tonic-gate 	nl = (struct netidlist *)malloc(sizeof (struct netidlist));
6967c478bd9Sstevel@tonic-gate 	if (nl == NULL)
6977c478bd9Sstevel@tonic-gate 		return (FALSE);
6987c478bd9Sstevel@tonic-gate 	nl->netid = netid;
6997c478bd9Sstevel@tonic-gate 	nl->next = rs->nlist;
7007c478bd9Sstevel@tonic-gate 	rs->nlist = nl;
7017c478bd9Sstevel@tonic-gate 	return (TRUE);
7027c478bd9Sstevel@tonic-gate }
7037c478bd9Sstevel@tonic-gate 
7047c478bd9Sstevel@tonic-gate static void
rpcbdump(dumptype,netid,argc,argv)7057c478bd9Sstevel@tonic-gate rpcbdump(dumptype, netid, argc, argv)
7067c478bd9Sstevel@tonic-gate 	int dumptype;
7077c478bd9Sstevel@tonic-gate 	char *netid;
7087c478bd9Sstevel@tonic-gate 	int argc;
7097c478bd9Sstevel@tonic-gate 	char **argv;
7107c478bd9Sstevel@tonic-gate {
7117c478bd9Sstevel@tonic-gate 	rpcblist_ptr head = NULL;
7127c478bd9Sstevel@tonic-gate 	struct timeval minutetimeout;
7137c478bd9Sstevel@tonic-gate 	register CLIENT *client;
7147c478bd9Sstevel@tonic-gate 	struct rpcent *rpc;
7157c478bd9Sstevel@tonic-gate 	char *host;
7167c478bd9Sstevel@tonic-gate 	struct netidlist *nl;
7177c478bd9Sstevel@tonic-gate 	struct verslist *vl;
7187c478bd9Sstevel@tonic-gate 	struct rpcbdump_short *rs, *rs_tail;
7197c478bd9Sstevel@tonic-gate 	enum clnt_stat clnt_st;
7207c478bd9Sstevel@tonic-gate 	struct rpc_err err;
7217c478bd9Sstevel@tonic-gate 	struct rpcbdump_short *rs_head = NULL;
7227c478bd9Sstevel@tonic-gate 
7237c478bd9Sstevel@tonic-gate 	if (argc > 1) {
7247c478bd9Sstevel@tonic-gate 		usage();
7257c478bd9Sstevel@tonic-gate 		exit(1);
7267c478bd9Sstevel@tonic-gate 	}
7277c478bd9Sstevel@tonic-gate 	if (argc == 1) {
7287c478bd9Sstevel@tonic-gate 		host = argv[0];
7297c478bd9Sstevel@tonic-gate 	} else {
73020d0ade9SMarcel Telka 		host = HOST_SELF_CONNECT;
7317c478bd9Sstevel@tonic-gate 	}
7327c478bd9Sstevel@tonic-gate 	if (netid == NULL) {
7337c478bd9Sstevel@tonic-gate 	    if (loopback_netid == NULL) {
7347c478bd9Sstevel@tonic-gate 		client = clnt_rpcbind_create(host, RPCBVERS, NULL);
7357c478bd9Sstevel@tonic-gate 	    } else {
7367c478bd9Sstevel@tonic-gate 		client = getclnthandle(host, loopback_nconf, RPCBVERS, NULL);
7377c478bd9Sstevel@tonic-gate 		if (client == NULL && rpc_createerr.cf_stat ==
7387c478bd9Sstevel@tonic-gate 				RPC_N2AXLATEFAILURE) {
7397c478bd9Sstevel@tonic-gate 			client = clnt_rpcbind_create(host, RPCBVERS, NULL);
7407c478bd9Sstevel@tonic-gate 		}
7417c478bd9Sstevel@tonic-gate 	    }
7427c478bd9Sstevel@tonic-gate 	} else {
7437c478bd9Sstevel@tonic-gate 		struct netconfig *nconf;
7447c478bd9Sstevel@tonic-gate 
7457c478bd9Sstevel@tonic-gate 		nconf = getnetconfigent(netid);
7467c478bd9Sstevel@tonic-gate 		if (nconf == NULL) {
7477c478bd9Sstevel@tonic-gate 			nc_perror("rpcinfo: invalid transport");
7487c478bd9Sstevel@tonic-gate 			exit(1);
7497c478bd9Sstevel@tonic-gate 		}
7507c478bd9Sstevel@tonic-gate 		client = getclnthandle(host, nconf, RPCBVERS, NULL);
7517c478bd9Sstevel@tonic-gate 		if (nconf)
7527c478bd9Sstevel@tonic-gate 			(void) freenetconfigent(nconf);
7537c478bd9Sstevel@tonic-gate 	}
7547c478bd9Sstevel@tonic-gate 	if (client == (CLIENT *)NULL) {
7557c478bd9Sstevel@tonic-gate 		clnt_pcreateerror("rpcinfo: can't contact rpcbind");
7567c478bd9Sstevel@tonic-gate 		exit(1);
7577c478bd9Sstevel@tonic-gate 	}
7587c478bd9Sstevel@tonic-gate 	minutetimeout.tv_sec = 60;
7597c478bd9Sstevel@tonic-gate 	minutetimeout.tv_usec = 0;
7607c478bd9Sstevel@tonic-gate 	clnt_st = CLNT_CALL(client, RPCBPROC_DUMP, (xdrproc_t)xdr_void,
7617c478bd9Sstevel@tonic-gate 		NULL, (xdrproc_t)xdr_rpcblist_ptr, (char *)&head,
7627c478bd9Sstevel@tonic-gate 		minutetimeout);
7637c478bd9Sstevel@tonic-gate 	if (clnt_st != RPC_SUCCESS) {
7647c478bd9Sstevel@tonic-gate 	    if ((clnt_st == RPC_PROGVERSMISMATCH) ||
7657c478bd9Sstevel@tonic-gate 		(clnt_st == RPC_PROGUNAVAIL)) {
7667c478bd9Sstevel@tonic-gate 		int vers;
7677c478bd9Sstevel@tonic-gate 
7687c478bd9Sstevel@tonic-gate 		CLNT_GETERR(client, &err);
7697c478bd9Sstevel@tonic-gate 		if (err.re_vers.low == RPCBVERS4) {
7707c478bd9Sstevel@tonic-gate 		    vers = RPCBVERS4;
7717c478bd9Sstevel@tonic-gate 		    clnt_control(client, CLSET_VERS, (char *)&vers);
7727c478bd9Sstevel@tonic-gate 		    clnt_st = CLNT_CALL(client, RPCBPROC_DUMP,
7737c478bd9Sstevel@tonic-gate 			(xdrproc_t)xdr_void, NULL,
7747c478bd9Sstevel@tonic-gate 			(xdrproc_t)xdr_rpcblist_ptr, (char *)&head,
7757c478bd9Sstevel@tonic-gate 			minutetimeout);
7767c478bd9Sstevel@tonic-gate 		    if (clnt_st != RPC_SUCCESS)
7777c478bd9Sstevel@tonic-gate 			goto failed;
7787c478bd9Sstevel@tonic-gate 		} else {
7797c478bd9Sstevel@tonic-gate 		    if (err.re_vers.high == PMAPVERS) {
7807c478bd9Sstevel@tonic-gate 			int high, low;
7817c478bd9Sstevel@tonic-gate 			pmaplist_ptr pmaphead = NULL;
782791dfaa7SVallish Vaidyeshwara 			rpcblist_ptr list, prev = NULL;
7837c478bd9Sstevel@tonic-gate 
7847c478bd9Sstevel@tonic-gate 			vers = PMAPVERS;
7857c478bd9Sstevel@tonic-gate 			clnt_control(client, CLSET_VERS, (char *)&vers);
7867c478bd9Sstevel@tonic-gate 			clnt_st = CLNT_CALL(client, PMAPPROC_DUMP,
7877c478bd9Sstevel@tonic-gate 				(xdrproc_t)xdr_void, NULL,
7887c478bd9Sstevel@tonic-gate 				(xdrproc_t)xdr_pmaplist_ptr,
7897c478bd9Sstevel@tonic-gate 				(char *)&pmaphead, minutetimeout);
7907c478bd9Sstevel@tonic-gate 			if (clnt_st != RPC_SUCCESS)
7917c478bd9Sstevel@tonic-gate 				goto failed;
7927c478bd9Sstevel@tonic-gate 			/*
7937c478bd9Sstevel@tonic-gate 			 * convert to rpcblist_ptr format
7947c478bd9Sstevel@tonic-gate 			 */
7957c478bd9Sstevel@tonic-gate 			for (head = NULL; pmaphead != NULL;
7967c478bd9Sstevel@tonic-gate 				pmaphead = pmaphead->pml_next) {
7977c478bd9Sstevel@tonic-gate 			    list = (rpcblist *)malloc(sizeof (rpcblist));
7987c478bd9Sstevel@tonic-gate 			    if (list == NULL)
7997c478bd9Sstevel@tonic-gate 				goto error;
8007c478bd9Sstevel@tonic-gate 			    if (head == NULL)
8017c478bd9Sstevel@tonic-gate 				head = list;
8027c478bd9Sstevel@tonic-gate 			    else
8037c478bd9Sstevel@tonic-gate 				prev->rpcb_next = (rpcblist_ptr) list;
8047c478bd9Sstevel@tonic-gate 
8057c478bd9Sstevel@tonic-gate 			    list->rpcb_next = NULL;
8067c478bd9Sstevel@tonic-gate 			    list->rpcb_map.r_prog = pmaphead->pml_map.pm_prog;
8077c478bd9Sstevel@tonic-gate 			    list->rpcb_map.r_vers = pmaphead->pml_map.pm_vers;
8087c478bd9Sstevel@tonic-gate 			    if (pmaphead->pml_map.pm_prot == IPPROTO_UDP)
8097c478bd9Sstevel@tonic-gate 				list->rpcb_map.r_netid = "udp";
8107c478bd9Sstevel@tonic-gate 			    else if (pmaphead->pml_map.pm_prot == IPPROTO_TCP)
8117c478bd9Sstevel@tonic-gate 				list->rpcb_map.r_netid = "tcp";
8127c478bd9Sstevel@tonic-gate 			    else {
8137c478bd9Sstevel@tonic-gate #define	MAXLONG_AS_STRING	"2147483648"
8147c478bd9Sstevel@tonic-gate 				list->rpcb_map.r_netid =
8157c478bd9Sstevel@tonic-gate 					malloc(strlen(MAXLONG_AS_STRING) + 1);
8167c478bd9Sstevel@tonic-gate 				if (list->rpcb_map.r_netid == NULL)
8177c478bd9Sstevel@tonic-gate 					goto error;
818791dfaa7SVallish Vaidyeshwara 				(void) sprintf(list->rpcb_map.r_netid, "%6ld",
8197c478bd9Sstevel@tonic-gate 					pmaphead->pml_map.pm_prot);
8207c478bd9Sstevel@tonic-gate 			    }
8217c478bd9Sstevel@tonic-gate 			    list->rpcb_map.r_owner = UNKNOWN;
8227c478bd9Sstevel@tonic-gate 			    low = pmaphead->pml_map.pm_port & 0xff;
8237c478bd9Sstevel@tonic-gate 			    high = (pmaphead->pml_map.pm_port >> 8) & 0xff;
8247c478bd9Sstevel@tonic-gate 			    list->rpcb_map.r_addr = strdup("0.0.0.0.XXX.XXX");
825791dfaa7SVallish Vaidyeshwara 			    (void) sprintf(&list->rpcb_map.r_addr[8], "%d.%d",
8267c478bd9Sstevel@tonic-gate 				high, low);
8277c478bd9Sstevel@tonic-gate 			    prev = list;
8287c478bd9Sstevel@tonic-gate 			}
8297c478bd9Sstevel@tonic-gate 		    }
8307c478bd9Sstevel@tonic-gate 		}
8317c478bd9Sstevel@tonic-gate 	    } else {	/* any other error */
8327c478bd9Sstevel@tonic-gate failed:
8337c478bd9Sstevel@tonic-gate 		    clnt_perror(client, "rpcinfo: can't contact rpcbind: ");
8347c478bd9Sstevel@tonic-gate 		    exit(1);
8357c478bd9Sstevel@tonic-gate 	    }
8367c478bd9Sstevel@tonic-gate 	}
8377c478bd9Sstevel@tonic-gate 	if (head == NULL) {
838791dfaa7SVallish Vaidyeshwara 		(void) printf("No remote programs registered.\n");
8397c478bd9Sstevel@tonic-gate 	} else if (dumptype == RPCBDUMP) {
840791dfaa7SVallish Vaidyeshwara 		(void) printf(
8417c478bd9Sstevel@tonic-gate "   program version netid     address             service    owner\n");
8427c478bd9Sstevel@tonic-gate 		for (; head != NULL; head = head->rpcb_next) {
843791dfaa7SVallish Vaidyeshwara 			(void) printf("%10ld%5ld    ",
8447c478bd9Sstevel@tonic-gate 				head->rpcb_map.r_prog, head->rpcb_map.r_vers);
845791dfaa7SVallish Vaidyeshwara 			(void) printf("%-9s ", head->rpcb_map.r_netid);
846791dfaa7SVallish Vaidyeshwara 			(void) printf("%-19s", head->rpcb_map.r_addr);
8477c478bd9Sstevel@tonic-gate 			rpc = getrpcbynumber(head->rpcb_map.r_prog);
8487c478bd9Sstevel@tonic-gate 			if (rpc)
849791dfaa7SVallish Vaidyeshwara 				(void) printf(" %-10s", rpc->r_name);
8507c478bd9Sstevel@tonic-gate 			else
851791dfaa7SVallish Vaidyeshwara 				(void) printf(" %-10s", "-");
852791dfaa7SVallish Vaidyeshwara 			(void) printf(" %s\n", head->rpcb_map.r_owner);
8537c478bd9Sstevel@tonic-gate 		}
8547c478bd9Sstevel@tonic-gate 	} else if (dumptype == RPCBDUMP_SHORT) {
8557c478bd9Sstevel@tonic-gate 		for (; head != NULL; head = head->rpcb_next) {
8567c478bd9Sstevel@tonic-gate 			for (rs = rs_head; rs; rs = rs->next)
8577c478bd9Sstevel@tonic-gate 				if (head->rpcb_map.r_prog == rs->prog)
8587c478bd9Sstevel@tonic-gate 					break;
8597c478bd9Sstevel@tonic-gate 			if (rs == NULL) {
8607c478bd9Sstevel@tonic-gate 				rs = (struct rpcbdump_short *)
8617c478bd9Sstevel@tonic-gate 					malloc(sizeof (struct rpcbdump_short));
8627c478bd9Sstevel@tonic-gate 				if (rs == NULL)
8637c478bd9Sstevel@tonic-gate 					goto error;
8647c478bd9Sstevel@tonic-gate 				rs->next = NULL;
8657c478bd9Sstevel@tonic-gate 				if (rs_head == NULL) {
8667c478bd9Sstevel@tonic-gate 					rs_head = rs;
8677c478bd9Sstevel@tonic-gate 					rs_tail = rs;
8687c478bd9Sstevel@tonic-gate 				} else {
8697c478bd9Sstevel@tonic-gate 					rs_tail->next = rs;
8707c478bd9Sstevel@tonic-gate 					rs_tail = rs;
8717c478bd9Sstevel@tonic-gate 				}
8727c478bd9Sstevel@tonic-gate 				rs->prog = head->rpcb_map.r_prog;
8737c478bd9Sstevel@tonic-gate 				rs->owner = head->rpcb_map.r_owner;
8747c478bd9Sstevel@tonic-gate 				rs->nlist = NULL;
8757c478bd9Sstevel@tonic-gate 				rs->vlist = NULL;
8767c478bd9Sstevel@tonic-gate 			}
8777c478bd9Sstevel@tonic-gate 			if (add_version(rs, head->rpcb_map.r_vers) == FALSE)
8787c478bd9Sstevel@tonic-gate 				goto error;
8797c478bd9Sstevel@tonic-gate 			if (add_netid(rs, head->rpcb_map.r_netid) == FALSE)
8807c478bd9Sstevel@tonic-gate 				goto error;
8817c478bd9Sstevel@tonic-gate 		}
882791dfaa7SVallish Vaidyeshwara 		(void) printf(
8837c478bd9Sstevel@tonic-gate "   program version(s) netid(s)                         service     owner\n");
8847c478bd9Sstevel@tonic-gate 		for (rs = rs_head; rs; rs = rs->next) {
885791dfaa7SVallish Vaidyeshwara 			int bytes_trans = 0;
886791dfaa7SVallish Vaidyeshwara 			int len;
8877c478bd9Sstevel@tonic-gate 
888791dfaa7SVallish Vaidyeshwara 			(void) printf("%10ld  ", rs->prog);
8897c478bd9Sstevel@tonic-gate 			for (vl = rs->vlist; vl; vl = vl->next) {
890791dfaa7SVallish Vaidyeshwara 				bytes_trans += (len = printf("%d", vl->vers))
891791dfaa7SVallish Vaidyeshwara 				    < 0 ? 0 : len;
8927c478bd9Sstevel@tonic-gate 				if (vl->next)
893791dfaa7SVallish Vaidyeshwara 					bytes_trans += (len = printf(",")) < 0
894791dfaa7SVallish Vaidyeshwara 					    ? 0 : len;
8957c478bd9Sstevel@tonic-gate 			}
896791dfaa7SVallish Vaidyeshwara 			/*
897791dfaa7SVallish Vaidyeshwara 			 * If number of bytes transferred is less than 10,
898791dfaa7SVallish Vaidyeshwara 			 * align 10 bytes for version(s) column. If bytes
899791dfaa7SVallish Vaidyeshwara 			 * transferred is more than 10, add a trailing white
900791dfaa7SVallish Vaidyeshwara 			 * space.
901791dfaa7SVallish Vaidyeshwara 			 */
902791dfaa7SVallish Vaidyeshwara 			if (bytes_trans < 10)
903791dfaa7SVallish Vaidyeshwara 				(void) printf("%*s", (bytes_trans - 10), " ");
904791dfaa7SVallish Vaidyeshwara 			else
905791dfaa7SVallish Vaidyeshwara 				(void) printf(" ");
906791dfaa7SVallish Vaidyeshwara 
907791dfaa7SVallish Vaidyeshwara 			bytes_trans = 0;
9087c478bd9Sstevel@tonic-gate 			for (nl = rs->nlist; nl; nl = nl->next) {
909791dfaa7SVallish Vaidyeshwara 				bytes_trans += (len = printf("%s", nl->netid))
910791dfaa7SVallish Vaidyeshwara 				    < 0 ? 0 : len;
9117c478bd9Sstevel@tonic-gate 				if (nl->next)
912791dfaa7SVallish Vaidyeshwara 					bytes_trans += (len = printf(",")) < 0
913791dfaa7SVallish Vaidyeshwara 					    ? 0 : len;
9147c478bd9Sstevel@tonic-gate 			}
915791dfaa7SVallish Vaidyeshwara 			/*
916791dfaa7SVallish Vaidyeshwara 			 * Align netid(s) column output for 32 bytes.
917791dfaa7SVallish Vaidyeshwara 			 */
918791dfaa7SVallish Vaidyeshwara 			if (bytes_trans < 32)
919791dfaa7SVallish Vaidyeshwara 				(void) printf("%*s", (bytes_trans - 32), " ");
920791dfaa7SVallish Vaidyeshwara 
9217c478bd9Sstevel@tonic-gate 			rpc = getrpcbynumber(rs->prog);
9227c478bd9Sstevel@tonic-gate 			if (rpc)
923791dfaa7SVallish Vaidyeshwara 				(void) printf(" %-11s", rpc->r_name);
9247c478bd9Sstevel@tonic-gate 			else
925791dfaa7SVallish Vaidyeshwara 				(void) printf(" %-11s", "-");
926791dfaa7SVallish Vaidyeshwara 			(void) printf(" %s\n", rs->owner);
9277c478bd9Sstevel@tonic-gate 		}
9287c478bd9Sstevel@tonic-gate 	}
9297c478bd9Sstevel@tonic-gate 	clnt_destroy(client);
9307c478bd9Sstevel@tonic-gate 	return;
9317c478bd9Sstevel@tonic-gate 
932791dfaa7SVallish Vaidyeshwara error:	(void) fprintf(stderr, "rpcinfo: no memory\n");
9337c478bd9Sstevel@tonic-gate }
9347c478bd9Sstevel@tonic-gate 
9357c478bd9Sstevel@tonic-gate static char nullstring[] = "\000";
9367c478bd9Sstevel@tonic-gate 
9377c478bd9Sstevel@tonic-gate static void
rpcbaddrlist(netid,argc,argv)9387c478bd9Sstevel@tonic-gate rpcbaddrlist(netid, argc, argv)
9397c478bd9Sstevel@tonic-gate 	char *netid;
9407c478bd9Sstevel@tonic-gate 	int argc;
9417c478bd9Sstevel@tonic-gate 	char **argv;
9427c478bd9Sstevel@tonic-gate {
9437c478bd9Sstevel@tonic-gate 	rpcb_entry_list_ptr head = NULL;
9447c478bd9Sstevel@tonic-gate 	struct timeval minutetimeout;
9457c478bd9Sstevel@tonic-gate 	register CLIENT *client;
9467c478bd9Sstevel@tonic-gate 	struct rpcent *rpc;
9477c478bd9Sstevel@tonic-gate 	char *host;
9487c478bd9Sstevel@tonic-gate 	RPCB parms;
9497c478bd9Sstevel@tonic-gate 	struct netbuf *targaddr;
9507c478bd9Sstevel@tonic-gate 
9517c478bd9Sstevel@tonic-gate 	if (argc != 3) {
9527c478bd9Sstevel@tonic-gate 		usage();
9537c478bd9Sstevel@tonic-gate 		exit(1);
9547c478bd9Sstevel@tonic-gate 	}
9557c478bd9Sstevel@tonic-gate 	host = argv[0];
9567c478bd9Sstevel@tonic-gate 	if (netid == NULL) {
9577c478bd9Sstevel@tonic-gate 	    if (loopback_netid == NULL) {
9587c478bd9Sstevel@tonic-gate 		client = clnt_rpcbind_create(host, RPCBVERS4, &targaddr);
9597c478bd9Sstevel@tonic-gate 	    } else {
9607c478bd9Sstevel@tonic-gate 		client = getclnthandle(host, loopback_nconf, RPCBVERS4,
9617c478bd9Sstevel@tonic-gate 			&targaddr);
9627c478bd9Sstevel@tonic-gate 		if (client == NULL && rpc_createerr.cf_stat ==
9637c478bd9Sstevel@tonic-gate 				RPC_N2AXLATEFAILURE) {
9647c478bd9Sstevel@tonic-gate 		    client = clnt_rpcbind_create(host, RPCBVERS4, &targaddr);
9657c478bd9Sstevel@tonic-gate 		}
9667c478bd9Sstevel@tonic-gate 	    }
9677c478bd9Sstevel@tonic-gate 	} else {
9687c478bd9Sstevel@tonic-gate 		struct netconfig *nconf;
9697c478bd9Sstevel@tonic-gate 
9707c478bd9Sstevel@tonic-gate 		nconf = getnetconfigent(netid);
9717c478bd9Sstevel@tonic-gate 		if (nconf == NULL) {
9727c478bd9Sstevel@tonic-gate 			nc_perror("rpcinfo: invalid transport");
9737c478bd9Sstevel@tonic-gate 			exit(1);
9747c478bd9Sstevel@tonic-gate 		}
9757c478bd9Sstevel@tonic-gate 		client = getclnthandle(host, nconf, RPCBVERS4, &targaddr);
9767c478bd9Sstevel@tonic-gate 		if (nconf)
9777c478bd9Sstevel@tonic-gate 			(void) freenetconfigent(nconf);
9787c478bd9Sstevel@tonic-gate 	}
9797c478bd9Sstevel@tonic-gate 	if (client == (CLIENT *)NULL) {
9807c478bd9Sstevel@tonic-gate 		clnt_pcreateerror("rpcinfo: can't contact rpcbind");
9817c478bd9Sstevel@tonic-gate 		exit(1);
9827c478bd9Sstevel@tonic-gate 	}
9837c478bd9Sstevel@tonic-gate 	minutetimeout.tv_sec = 60;
9847c478bd9Sstevel@tonic-gate 	minutetimeout.tv_usec = 0;
9857c478bd9Sstevel@tonic-gate 
9867c478bd9Sstevel@tonic-gate 	parms.r_prog = 	getprognum(argv[1]);
9877c478bd9Sstevel@tonic-gate 	parms.r_vers = 	getvers(argv[2]);
9887c478bd9Sstevel@tonic-gate 	parms.r_netid = client->cl_netid;
9897c478bd9Sstevel@tonic-gate 	if (targaddr == NULL) {
9907c478bd9Sstevel@tonic-gate 		parms.r_addr = nullstring;	/* for XDRing */
9917c478bd9Sstevel@tonic-gate 	} else {
9927c478bd9Sstevel@tonic-gate 		/*
9937c478bd9Sstevel@tonic-gate 		 * We also send the remote system the address we
9947c478bd9Sstevel@tonic-gate 		 * used to contact it in case it can help it
9957c478bd9Sstevel@tonic-gate 		 * connect back with us
9967c478bd9Sstevel@tonic-gate 		 */
9977c478bd9Sstevel@tonic-gate 		struct netconfig *nconf;
9987c478bd9Sstevel@tonic-gate 
9997c478bd9Sstevel@tonic-gate 		nconf = getnetconfigent(client->cl_netid);
10007c478bd9Sstevel@tonic-gate 		if (nconf != NULL) {
10017c478bd9Sstevel@tonic-gate 			parms.r_addr = taddr2uaddr(nconf, targaddr);
10027c478bd9Sstevel@tonic-gate 			if (parms.r_addr == NULL)
10037c478bd9Sstevel@tonic-gate 				parms.r_addr = nullstring;
10047c478bd9Sstevel@tonic-gate 			freenetconfigent(nconf);
10057c478bd9Sstevel@tonic-gate 		} else {
10067c478bd9Sstevel@tonic-gate 			parms.r_addr = nullstring;	/* for XDRing */
10077c478bd9Sstevel@tonic-gate 		}
10087c478bd9Sstevel@tonic-gate 		free(targaddr->buf);
10097c478bd9Sstevel@tonic-gate 		free(targaddr);
10107c478bd9Sstevel@tonic-gate 	}
10117c478bd9Sstevel@tonic-gate 	parms.r_owner = nullstring;
10127c478bd9Sstevel@tonic-gate 
10137c478bd9Sstevel@tonic-gate 	if (CLNT_CALL(client, RPCBPROC_GETADDRLIST, (xdrproc_t)xdr_rpcb,
10147c478bd9Sstevel@tonic-gate 		(char *)&parms, (xdrproc_t)xdr_rpcb_entry_list_ptr,
10157c478bd9Sstevel@tonic-gate 		(char *)&head, minutetimeout) != RPC_SUCCESS) {
10167c478bd9Sstevel@tonic-gate 		clnt_perror(client, "rpcinfo: can't contact rpcbind: ");
10177c478bd9Sstevel@tonic-gate 		exit(1);
10187c478bd9Sstevel@tonic-gate 	}
10197c478bd9Sstevel@tonic-gate 	if (head == NULL) {
1020791dfaa7SVallish Vaidyeshwara 		(void) printf("No remote programs registered.\n");
10217c478bd9Sstevel@tonic-gate 	} else {
1022791dfaa7SVallish Vaidyeshwara 		(void) printf(
10237c478bd9Sstevel@tonic-gate 	"   program vers  tp_family/name/class    address\t\t  service\n");
10247c478bd9Sstevel@tonic-gate 		for (; head != NULL; head = head->rpcb_entry_next) {
10257c478bd9Sstevel@tonic-gate 			rpcb_entry *re;
10267c478bd9Sstevel@tonic-gate 			char buf[128];
10277c478bd9Sstevel@tonic-gate 
10287c478bd9Sstevel@tonic-gate 			re = &head->rpcb_entry_map;
1029791dfaa7SVallish Vaidyeshwara 			(void) printf("%10ld%3ld    ",
10307c478bd9Sstevel@tonic-gate 				parms.r_prog, parms.r_vers);
1031791dfaa7SVallish Vaidyeshwara 			(void) snprintf(buf, sizeof (buf), "%s/%s/%s ",
10327c478bd9Sstevel@tonic-gate 				re->r_nc_protofmly, re->r_nc_proto,
10337c478bd9Sstevel@tonic-gate 				re->r_nc_semantics == NC_TPI_CLTS ? "clts" :
10347c478bd9Sstevel@tonic-gate 				re->r_nc_semantics == NC_TPI_COTS ? "cots" :
10357c478bd9Sstevel@tonic-gate 						"cots_ord");
1036791dfaa7SVallish Vaidyeshwara 			(void) printf("%-24s", buf);
1037791dfaa7SVallish Vaidyeshwara 			(void) printf("%-24s", re->r_maddr);
10387c478bd9Sstevel@tonic-gate 			rpc = getrpcbynumber(parms.r_prog);
10397c478bd9Sstevel@tonic-gate 			if (rpc)
1040791dfaa7SVallish Vaidyeshwara 				(void) printf(" %-13s", rpc->r_name);
10417c478bd9Sstevel@tonic-gate 			else
1042791dfaa7SVallish Vaidyeshwara 				(void) printf(" %-13s", "-");
1043791dfaa7SVallish Vaidyeshwara 			(void) printf("\n");
10447c478bd9Sstevel@tonic-gate 		}
10457c478bd9Sstevel@tonic-gate 	}
10467c478bd9Sstevel@tonic-gate 	clnt_destroy(client);
10477c478bd9Sstevel@tonic-gate }
10487c478bd9Sstevel@tonic-gate 
10497c478bd9Sstevel@tonic-gate /*
10507c478bd9Sstevel@tonic-gate  * monitor rpcbind
10517c478bd9Sstevel@tonic-gate  */
10527c478bd9Sstevel@tonic-gate static void
rpcbgetstat(argc,argv)10537c478bd9Sstevel@tonic-gate rpcbgetstat(argc, argv)
10547c478bd9Sstevel@tonic-gate 	int argc;
10557c478bd9Sstevel@tonic-gate 	char **argv;
10567c478bd9Sstevel@tonic-gate {
10577c478bd9Sstevel@tonic-gate 	rpcb_stat_byvers inf;
10587c478bd9Sstevel@tonic-gate 	struct timeval minutetimeout;
10597c478bd9Sstevel@tonic-gate 	register CLIENT *client;
10607c478bd9Sstevel@tonic-gate 	char *host;
10617c478bd9Sstevel@tonic-gate 	int i, j;
10627c478bd9Sstevel@tonic-gate 	rpcbs_addrlist *pa;
10637c478bd9Sstevel@tonic-gate 	rpcbs_rmtcalllist *pr;
10647c478bd9Sstevel@tonic-gate 	int cnt, flen;
10657c478bd9Sstevel@tonic-gate #define	MAXFIELD	64
10667c478bd9Sstevel@tonic-gate 	char fieldbuf[MAXFIELD];
10677c478bd9Sstevel@tonic-gate #define	MAXLINE		256
10687c478bd9Sstevel@tonic-gate 	char linebuf[MAXLINE];
1069791dfaa7SVallish Vaidyeshwara 	char *cp, *lp;
10707c478bd9Sstevel@tonic-gate 	char *pmaphdr[] = {
10717c478bd9Sstevel@tonic-gate 		"NULL", "SET", "UNSET", "GETPORT",
10727c478bd9Sstevel@tonic-gate 		"DUMP", "CALLIT"
10737c478bd9Sstevel@tonic-gate 	};
10747c478bd9Sstevel@tonic-gate 	char *rpcb3hdr[] = {
10757c478bd9Sstevel@tonic-gate 		"NULL", "SET", "UNSET", "GETADDR", "DUMP", "CALLIT", "TIME",
10767c478bd9Sstevel@tonic-gate 		"U2T", "T2U"
10777c478bd9Sstevel@tonic-gate 	};
10787c478bd9Sstevel@tonic-gate 	char *rpcb4hdr[] = {
10797c478bd9Sstevel@tonic-gate 		"NULL", "SET", "UNSET", "GETADDR", "DUMP", "CALLIT", "TIME",
10807c478bd9Sstevel@tonic-gate 		"U2T",  "T2U", "VERADDR", "INDRECT", "GETLIST", "GETSTAT"
10817c478bd9Sstevel@tonic-gate 	};
10827c478bd9Sstevel@tonic-gate 
10837c478bd9Sstevel@tonic-gate #define	TABSTOP	8
10847c478bd9Sstevel@tonic-gate 
10857c478bd9Sstevel@tonic-gate 	if (argc >= 1) {
10867c478bd9Sstevel@tonic-gate 		host = argv[0];
10877c478bd9Sstevel@tonic-gate 	} else {
108820d0ade9SMarcel Telka 		host = HOST_SELF_CONNECT;
10897c478bd9Sstevel@tonic-gate 	}
10907c478bd9Sstevel@tonic-gate 	if (loopback_netid != NULL) {
10917c478bd9Sstevel@tonic-gate 		client = getclnthandle(host, loopback_nconf, RPCBVERS4, NULL);
10927c478bd9Sstevel@tonic-gate 		if (client == NULL && rpc_createerr.cf_stat ==
10937c478bd9Sstevel@tonic-gate 				RPC_N2AXLATEFAILURE) {
10947c478bd9Sstevel@tonic-gate 			client = clnt_rpcbind_create(host, RPCBVERS4, NULL);
10957c478bd9Sstevel@tonic-gate 		}
10967c478bd9Sstevel@tonic-gate 	} else {
10977c478bd9Sstevel@tonic-gate 		client = clnt_rpcbind_create(host, RPCBVERS4, NULL);
10987c478bd9Sstevel@tonic-gate 	}
10997c478bd9Sstevel@tonic-gate 	if (client == (CLIENT *)NULL) {
11007c478bd9Sstevel@tonic-gate 		clnt_pcreateerror("rpcinfo: can't contact rpcbind");
11017c478bd9Sstevel@tonic-gate 		exit(1);
11027c478bd9Sstevel@tonic-gate 	}
11037c478bd9Sstevel@tonic-gate 	minutetimeout.tv_sec = 60;
11047c478bd9Sstevel@tonic-gate 	minutetimeout.tv_usec = 0;
1105791dfaa7SVallish Vaidyeshwara 	(void) memset((char *)&inf, 0, sizeof (rpcb_stat_byvers));
11067c478bd9Sstevel@tonic-gate 	if (CLNT_CALL(client, RPCBPROC_GETSTAT, (xdrproc_t)xdr_void, NULL,
11077c478bd9Sstevel@tonic-gate 		(xdrproc_t)xdr_rpcb_stat_byvers, (char *)&inf, minutetimeout)
11087c478bd9Sstevel@tonic-gate 			!= RPC_SUCCESS) {
11097c478bd9Sstevel@tonic-gate 		clnt_perror(client, "rpcinfo: can't contact rpcbind: ");
11107c478bd9Sstevel@tonic-gate 		exit(1);
11117c478bd9Sstevel@tonic-gate 	}
1112791dfaa7SVallish Vaidyeshwara 	(void) printf("PORTMAP (version 2) statistics\n");
11137c478bd9Sstevel@tonic-gate 	lp = linebuf;
11147c478bd9Sstevel@tonic-gate 	for (i = 0; i <= rpcb_highproc_2; i++) {
11157c478bd9Sstevel@tonic-gate 		fieldbuf[0] = '\0';
11167c478bd9Sstevel@tonic-gate 		switch (i) {
11177c478bd9Sstevel@tonic-gate 		case PMAPPROC_SET:
1118791dfaa7SVallish Vaidyeshwara 			(void) sprintf(fieldbuf, "%d/",
1119791dfaa7SVallish Vaidyeshwara 				inf[RPCBVERS_2_STAT].setinfo);
11207c478bd9Sstevel@tonic-gate 			break;
11217c478bd9Sstevel@tonic-gate 		case PMAPPROC_UNSET:
1122791dfaa7SVallish Vaidyeshwara 			(void) sprintf(fieldbuf, "%d/",
11237c478bd9Sstevel@tonic-gate 				inf[RPCBVERS_2_STAT].unsetinfo);
11247c478bd9Sstevel@tonic-gate 			break;
11257c478bd9Sstevel@tonic-gate 		case PMAPPROC_GETPORT:
11267c478bd9Sstevel@tonic-gate 			cnt = 0;
11277c478bd9Sstevel@tonic-gate 			for (pa = inf[RPCBVERS_2_STAT].addrinfo; pa;
11287c478bd9Sstevel@tonic-gate 				pa = pa->next)
11297c478bd9Sstevel@tonic-gate 				cnt += pa->success;
1130791dfaa7SVallish Vaidyeshwara 			(void) sprintf(fieldbuf, "%d/", cnt);
11317c478bd9Sstevel@tonic-gate 			break;
11327c478bd9Sstevel@tonic-gate 		case PMAPPROC_CALLIT:
11337c478bd9Sstevel@tonic-gate 			cnt = 0;
11347c478bd9Sstevel@tonic-gate 			for (pr = inf[RPCBVERS_2_STAT].rmtinfo; pr;
11357c478bd9Sstevel@tonic-gate 				pr = pr->next)
11367c478bd9Sstevel@tonic-gate 				cnt += pr->success;
1137791dfaa7SVallish Vaidyeshwara 			(void) sprintf(fieldbuf, "%d/", cnt);
11387c478bd9Sstevel@tonic-gate 			break;
11397c478bd9Sstevel@tonic-gate 		default: break;  /* For the remaining ones */
11407c478bd9Sstevel@tonic-gate 		}
11417c478bd9Sstevel@tonic-gate 		cp = &fieldbuf[0] + strlen(fieldbuf);
1142791dfaa7SVallish Vaidyeshwara 		(void) sprintf(cp, "%d", inf[RPCBVERS_2_STAT].info[i]);
11437c478bd9Sstevel@tonic-gate 		flen = strlen(fieldbuf);
1144791dfaa7SVallish Vaidyeshwara 		(void) printf("%s%s", pmaphdr[i],
1145791dfaa7SVallish Vaidyeshwara 			spaces((int)((TABSTOP * (1 + flen / TABSTOP))
1146791dfaa7SVallish Vaidyeshwara 			- strlen(pmaphdr[i]))));
1147791dfaa7SVallish Vaidyeshwara 		(void) snprintf(lp, (MAXLINE - (lp - linebuf)), "%s%s",
1148791dfaa7SVallish Vaidyeshwara 			fieldbuf, spaces(cnt = ((TABSTOP * (1 + flen / TABSTOP))
11497c478bd9Sstevel@tonic-gate 			- flen)));
11507c478bd9Sstevel@tonic-gate 		lp += (flen + cnt);
11517c478bd9Sstevel@tonic-gate 	}
1152791dfaa7SVallish Vaidyeshwara 	(void) printf("\n%s\n\n", linebuf);
11537c478bd9Sstevel@tonic-gate 
11547c478bd9Sstevel@tonic-gate 	if (inf[RPCBVERS_2_STAT].info[PMAPPROC_CALLIT]) {
1155791dfaa7SVallish Vaidyeshwara 		(void) printf("PMAP_RMTCALL call statistics\n");
11567c478bd9Sstevel@tonic-gate 		print_rmtcallstat(RPCBVERS_2_STAT, &inf[RPCBVERS_2_STAT]);
1157791dfaa7SVallish Vaidyeshwara 		(void) printf("\n");
11587c478bd9Sstevel@tonic-gate 	}
11597c478bd9Sstevel@tonic-gate 
11607c478bd9Sstevel@tonic-gate 	if (inf[RPCBVERS_2_STAT].info[PMAPPROC_GETPORT]) {
1161791dfaa7SVallish Vaidyeshwara 		(void) printf("PMAP_GETPORT call statistics\n");
11627c478bd9Sstevel@tonic-gate 		print_getaddrstat(RPCBVERS_2_STAT, &inf[RPCBVERS_2_STAT]);
1163791dfaa7SVallish Vaidyeshwara 		(void) printf("\n");
11647c478bd9Sstevel@tonic-gate 	}
11657c478bd9Sstevel@tonic-gate 
1166791dfaa7SVallish Vaidyeshwara 	(void) printf("RPCBIND (version 3) statistics\n");
11677c478bd9Sstevel@tonic-gate 	lp = linebuf;
11687c478bd9Sstevel@tonic-gate 	for (i = 0; i <= rpcb_highproc_3; i++) {
11697c478bd9Sstevel@tonic-gate 		fieldbuf[0] = '\0';
11707c478bd9Sstevel@tonic-gate 		switch (i) {
11717c478bd9Sstevel@tonic-gate 		case RPCBPROC_SET:
1172791dfaa7SVallish Vaidyeshwara 			(void) sprintf(fieldbuf, "%d/",
1173791dfaa7SVallish Vaidyeshwara 				inf[RPCBVERS_3_STAT].setinfo);
11747c478bd9Sstevel@tonic-gate 			break;
11757c478bd9Sstevel@tonic-gate 		case RPCBPROC_UNSET:
1176791dfaa7SVallish Vaidyeshwara 			(void) sprintf(fieldbuf, "%d/",
11777c478bd9Sstevel@tonic-gate 				inf[RPCBVERS_3_STAT].unsetinfo);
11787c478bd9Sstevel@tonic-gate 			break;
11797c478bd9Sstevel@tonic-gate 		case RPCBPROC_GETADDR:
11807c478bd9Sstevel@tonic-gate 			cnt = 0;
11817c478bd9Sstevel@tonic-gate 			for (pa = inf[RPCBVERS_3_STAT].addrinfo; pa;
11827c478bd9Sstevel@tonic-gate 				pa = pa->next)
11837c478bd9Sstevel@tonic-gate 				cnt += pa->success;
1184791dfaa7SVallish Vaidyeshwara 			(void) sprintf(fieldbuf, "%d/", cnt);
11857c478bd9Sstevel@tonic-gate 			break;
11867c478bd9Sstevel@tonic-gate 		case RPCBPROC_CALLIT:
11877c478bd9Sstevel@tonic-gate 			cnt = 0;
11887c478bd9Sstevel@tonic-gate 			for (pr = inf[RPCBVERS_3_STAT].rmtinfo; pr;
11897c478bd9Sstevel@tonic-gate 				pr = pr->next)
11907c478bd9Sstevel@tonic-gate 				cnt += pr->success;
1191791dfaa7SVallish Vaidyeshwara 			(void) sprintf(fieldbuf, "%d/", cnt);
11927c478bd9Sstevel@tonic-gate 			break;
11937c478bd9Sstevel@tonic-gate 		default: break;  /* For the remaining ones */
11947c478bd9Sstevel@tonic-gate 		}
11957c478bd9Sstevel@tonic-gate 		cp = &fieldbuf[0] + strlen(fieldbuf);
1196791dfaa7SVallish Vaidyeshwara 		(void) sprintf(cp, "%d", inf[RPCBVERS_3_STAT].info[i]);
11977c478bd9Sstevel@tonic-gate 		flen = strlen(fieldbuf);
1198791dfaa7SVallish Vaidyeshwara 		(void) printf("%s%s", rpcb3hdr[i],
1199791dfaa7SVallish Vaidyeshwara 			spaces((int)((TABSTOP * (1 + flen / TABSTOP))
1200791dfaa7SVallish Vaidyeshwara 			- strlen(rpcb3hdr[i]))));
1201791dfaa7SVallish Vaidyeshwara 		(void) snprintf(lp, (MAXLINE - (lp - linebuf)), "%s%s",
1202791dfaa7SVallish Vaidyeshwara 			fieldbuf, spaces(cnt = ((TABSTOP * (1 + flen / TABSTOP))
12037c478bd9Sstevel@tonic-gate 			- flen)));
12047c478bd9Sstevel@tonic-gate 		lp += (flen + cnt);
12057c478bd9Sstevel@tonic-gate 	}
1206791dfaa7SVallish Vaidyeshwara 	(void) printf("\n%s\n\n", linebuf);
12077c478bd9Sstevel@tonic-gate 
12087c478bd9Sstevel@tonic-gate 	if (inf[RPCBVERS_3_STAT].info[RPCBPROC_CALLIT]) {
1209791dfaa7SVallish Vaidyeshwara 		(void) printf("RPCB_RMTCALL (version 3) call statistics\n");
12107c478bd9Sstevel@tonic-gate 		print_rmtcallstat(RPCBVERS_3_STAT, &inf[RPCBVERS_3_STAT]);
1211791dfaa7SVallish Vaidyeshwara 		(void) printf("\n");
12127c478bd9Sstevel@tonic-gate 	}
12137c478bd9Sstevel@tonic-gate 
12147c478bd9Sstevel@tonic-gate 	if (inf[RPCBVERS_3_STAT].info[RPCBPROC_GETADDR]) {
1215791dfaa7SVallish Vaidyeshwara 		(void) printf("RPCB_GETADDR (version 3) call statistics\n");
12167c478bd9Sstevel@tonic-gate 		print_getaddrstat(RPCBVERS_3_STAT, &inf[RPCBVERS_3_STAT]);
1217791dfaa7SVallish Vaidyeshwara 		(void) printf("\n");
12187c478bd9Sstevel@tonic-gate 	}
12197c478bd9Sstevel@tonic-gate 
1220791dfaa7SVallish Vaidyeshwara 	(void) printf("RPCBIND (version 4) statistics\n");
12217c478bd9Sstevel@tonic-gate 
12227c478bd9Sstevel@tonic-gate 	for (j = 0; j <= 9; j += 9) { /* Just two iterations for printing */
12237c478bd9Sstevel@tonic-gate 		lp = linebuf;
12247c478bd9Sstevel@tonic-gate 		for (i = j; i <= MAX(8, rpcb_highproc_4 - 9 + j); i++) {
12257c478bd9Sstevel@tonic-gate 			fieldbuf[0] = '\0';
12267c478bd9Sstevel@tonic-gate 			switch (i) {
12277c478bd9Sstevel@tonic-gate 			case RPCBPROC_SET:
1228791dfaa7SVallish Vaidyeshwara 				(void) sprintf(fieldbuf, "%d/",
12297c478bd9Sstevel@tonic-gate 					inf[RPCBVERS_4_STAT].setinfo);
12307c478bd9Sstevel@tonic-gate 				break;
12317c478bd9Sstevel@tonic-gate 			case RPCBPROC_UNSET:
1232791dfaa7SVallish Vaidyeshwara 				(void) sprintf(fieldbuf, "%d/",
12337c478bd9Sstevel@tonic-gate 					inf[RPCBVERS_4_STAT].unsetinfo);
12347c478bd9Sstevel@tonic-gate 				break;
12357c478bd9Sstevel@tonic-gate 			case RPCBPROC_GETADDR:
12367c478bd9Sstevel@tonic-gate 				cnt = 0;
12377c478bd9Sstevel@tonic-gate 				for (pa = inf[RPCBVERS_4_STAT].addrinfo; pa;
12387c478bd9Sstevel@tonic-gate 					pa = pa->next)
12397c478bd9Sstevel@tonic-gate 					cnt += pa->success;
1240791dfaa7SVallish Vaidyeshwara 				(void) sprintf(fieldbuf, "%d/", cnt);
12417c478bd9Sstevel@tonic-gate 				break;
12427c478bd9Sstevel@tonic-gate 			case RPCBPROC_CALLIT:
12437c478bd9Sstevel@tonic-gate 				cnt = 0;
12447c478bd9Sstevel@tonic-gate 				for (pr = inf[RPCBVERS_4_STAT].rmtinfo; pr;
12457c478bd9Sstevel@tonic-gate 					pr = pr->next)
12467c478bd9Sstevel@tonic-gate 					cnt += pr->success;
1247791dfaa7SVallish Vaidyeshwara 				(void) sprintf(fieldbuf, "%d/", cnt);
12487c478bd9Sstevel@tonic-gate 				break;
12497c478bd9Sstevel@tonic-gate 			default: break;  /* For the remaining ones */
12507c478bd9Sstevel@tonic-gate 			}
12517c478bd9Sstevel@tonic-gate 			cp = &fieldbuf[0] + strlen(fieldbuf);
12527c478bd9Sstevel@tonic-gate 			/*
12537c478bd9Sstevel@tonic-gate 			 * XXX: We also add RPCBPROC_GETADDRLIST queries to
12547c478bd9Sstevel@tonic-gate 			 * RPCB_GETADDR because rpcbind includes the
12557c478bd9Sstevel@tonic-gate 			 * RPCB_GETADDRLIST successes in RPCB_GETADDR.
12567c478bd9Sstevel@tonic-gate 			 */
12577c478bd9Sstevel@tonic-gate 			if (i != RPCBPROC_GETADDR)
1258791dfaa7SVallish Vaidyeshwara 			    (void) sprintf(cp, "%d",
1259791dfaa7SVallish Vaidyeshwara 				inf[RPCBVERS_4_STAT].info[i]);
12607c478bd9Sstevel@tonic-gate 			else
1261791dfaa7SVallish Vaidyeshwara 			    (void) sprintf(cp, "%d",
1262791dfaa7SVallish Vaidyeshwara 			    inf[RPCBVERS_4_STAT].info[i] +
12637c478bd9Sstevel@tonic-gate 			    inf[RPCBVERS_4_STAT].info[RPCBPROC_GETADDRLIST]);
12647c478bd9Sstevel@tonic-gate 			flen = strlen(fieldbuf);
1265791dfaa7SVallish Vaidyeshwara 			(void) printf("%s%s", rpcb4hdr[i],
1266791dfaa7SVallish Vaidyeshwara 				spaces((int)((TABSTOP * (1 + flen / TABSTOP))
1267791dfaa7SVallish Vaidyeshwara 				- strlen(rpcb4hdr[i]))));
1268791dfaa7SVallish Vaidyeshwara 			(void) snprintf(lp, MAXLINE - (lp - linebuf), "%s%s",
1269791dfaa7SVallish Vaidyeshwara 				fieldbuf, spaces(cnt =
1270791dfaa7SVallish Vaidyeshwara 				((TABSTOP * (1 + flen / TABSTOP)) - flen)));
12717c478bd9Sstevel@tonic-gate 			lp += (flen + cnt);
12727c478bd9Sstevel@tonic-gate 		}
1273791dfaa7SVallish Vaidyeshwara 		(void) printf("\n%s\n", linebuf);
12747c478bd9Sstevel@tonic-gate 	}
12757c478bd9Sstevel@tonic-gate 
12767c478bd9Sstevel@tonic-gate 	if (inf[RPCBVERS_4_STAT].info[RPCBPROC_CALLIT] ||
12777c478bd9Sstevel@tonic-gate 			    inf[RPCBVERS_4_STAT].info[RPCBPROC_INDIRECT]) {
1278791dfaa7SVallish Vaidyeshwara 		(void) printf("\n");
1279791dfaa7SVallish Vaidyeshwara 		(void) printf("RPCB_RMTCALL (version 4) call statistics\n");
12807c478bd9Sstevel@tonic-gate 		print_rmtcallstat(RPCBVERS_4_STAT, &inf[RPCBVERS_4_STAT]);
12817c478bd9Sstevel@tonic-gate 	}
12827c478bd9Sstevel@tonic-gate 
12837c478bd9Sstevel@tonic-gate 	if (inf[RPCBVERS_4_STAT].info[RPCBPROC_GETADDR]) {
1284791dfaa7SVallish Vaidyeshwara 		(void) printf("\n");
1285791dfaa7SVallish Vaidyeshwara 		(void) printf("RPCB_GETADDR (version 4) call statistics\n");
12867c478bd9Sstevel@tonic-gate 		print_getaddrstat(RPCBVERS_4_STAT, &inf[RPCBVERS_4_STAT]);
12877c478bd9Sstevel@tonic-gate 	}
12887c478bd9Sstevel@tonic-gate 	clnt_destroy(client);
12897c478bd9Sstevel@tonic-gate }
12907c478bd9Sstevel@tonic-gate 
12917c478bd9Sstevel@tonic-gate /*
12927c478bd9Sstevel@tonic-gate  * Delete registeration for this (prog, vers, netid)
12937c478bd9Sstevel@tonic-gate  */
12947c478bd9Sstevel@tonic-gate static void
deletereg(netid,argc,argv)12957c478bd9Sstevel@tonic-gate deletereg(netid, argc, argv)
12967c478bd9Sstevel@tonic-gate 	char *netid;
12977c478bd9Sstevel@tonic-gate 	int argc;
12987c478bd9Sstevel@tonic-gate 	char **argv;
12997c478bd9Sstevel@tonic-gate {
13007c478bd9Sstevel@tonic-gate 	struct netconfig *nconf = NULL;
13017c478bd9Sstevel@tonic-gate 
13027c478bd9Sstevel@tonic-gate 	if (argc != 2) {
13037c478bd9Sstevel@tonic-gate 		usage();
13047c478bd9Sstevel@tonic-gate 		exit(1);
13057c478bd9Sstevel@tonic-gate 	}
13067c478bd9Sstevel@tonic-gate 	if (netid) {
13077c478bd9Sstevel@tonic-gate 		nconf = getnetconfigent(netid);
13087c478bd9Sstevel@tonic-gate 		if (nconf == NULL) {
1309791dfaa7SVallish Vaidyeshwara 			(void) fprintf(stderr,
1310791dfaa7SVallish Vaidyeshwara 				"rpcinfo: netid %s not supported\n", netid);
13117c478bd9Sstevel@tonic-gate 			exit(1);
13127c478bd9Sstevel@tonic-gate 		}
13137c478bd9Sstevel@tonic-gate 	}
13147c478bd9Sstevel@tonic-gate 	if ((rpcb_unset(getprognum(argv[0]), getvers(argv[1]), nconf)) == 0) {
1315791dfaa7SVallish Vaidyeshwara 		(void) fprintf(stderr,
13167c478bd9Sstevel@tonic-gate 	"rpcinfo: Could not delete registration for prog %s version %s\n",
13177c478bd9Sstevel@tonic-gate 			argv[0], argv[1]);
13187c478bd9Sstevel@tonic-gate 		exit(1);
13197c478bd9Sstevel@tonic-gate 	}
13207c478bd9Sstevel@tonic-gate }
13217c478bd9Sstevel@tonic-gate 
13227c478bd9Sstevel@tonic-gate /*
13237c478bd9Sstevel@tonic-gate  * Create and return a handle for the given nconf.
13247c478bd9Sstevel@tonic-gate  * Exit if cannot create handle.
13257c478bd9Sstevel@tonic-gate  */
13267c478bd9Sstevel@tonic-gate static CLIENT *
clnt_addr_create(address,nconf,prog,vers)13277c478bd9Sstevel@tonic-gate clnt_addr_create(address, nconf, prog, vers)
13287c478bd9Sstevel@tonic-gate 	char *address;
13297c478bd9Sstevel@tonic-gate 	struct netconfig *nconf;
13307c478bd9Sstevel@tonic-gate 	ulong_t prog;
13317c478bd9Sstevel@tonic-gate 	ulong_t vers;
13327c478bd9Sstevel@tonic-gate {
13337c478bd9Sstevel@tonic-gate 	CLIENT *client;
13347c478bd9Sstevel@tonic-gate 	static struct netbuf *nbuf;
13357c478bd9Sstevel@tonic-gate 	static int fd = RPC_ANYFD;
13367c478bd9Sstevel@tonic-gate 	struct t_info tinfo;
13377c478bd9Sstevel@tonic-gate 
13387c478bd9Sstevel@tonic-gate 	if (fd == RPC_ANYFD) {
13397c478bd9Sstevel@tonic-gate 		if ((fd = t_open(nconf->nc_device, O_RDWR, &tinfo)) == -1) {
13407c478bd9Sstevel@tonic-gate 			rpc_createerr.cf_stat = RPC_TLIERROR;
13417c478bd9Sstevel@tonic-gate 			rpc_createerr.cf_error.re_terrno = t_errno;
13427c478bd9Sstevel@tonic-gate 			clnt_pcreateerror("rpcinfo");
13437c478bd9Sstevel@tonic-gate 			exit(1);
13447c478bd9Sstevel@tonic-gate 		}
13457c478bd9Sstevel@tonic-gate 		/* Convert the uaddr to taddr */
13467c478bd9Sstevel@tonic-gate 		nbuf = uaddr2taddr(nconf, address);
13477c478bd9Sstevel@tonic-gate 		if (nbuf == NULL) {
13487c478bd9Sstevel@tonic-gate 			netdir_perror("rpcinfo");
13497c478bd9Sstevel@tonic-gate 			exit(1);
13507c478bd9Sstevel@tonic-gate 		}
13517c478bd9Sstevel@tonic-gate 	}
13527c478bd9Sstevel@tonic-gate 	client = clnt_tli_create(fd, nconf, nbuf, prog, vers, 0, 0);
13537c478bd9Sstevel@tonic-gate 	if (client == (CLIENT *)NULL) {
13547c478bd9Sstevel@tonic-gate 		clnt_pcreateerror("rpcinfo");
13557c478bd9Sstevel@tonic-gate 		exit(1);
13567c478bd9Sstevel@tonic-gate 	}
13577c478bd9Sstevel@tonic-gate 	return (client);
13587c478bd9Sstevel@tonic-gate }
13597c478bd9Sstevel@tonic-gate 
13607c478bd9Sstevel@tonic-gate /*
13617c478bd9Sstevel@tonic-gate  * If the version number is given, ping that (prog, vers); else try to find
13627c478bd9Sstevel@tonic-gate  * the version numbers supported for that prog and ping all the versions.
13637c478bd9Sstevel@tonic-gate  * Remote rpcbind is not contacted for this service. The requests are
13647c478bd9Sstevel@tonic-gate  * sent directly to the services themselves.
13657c478bd9Sstevel@tonic-gate  */
13667c478bd9Sstevel@tonic-gate static void
addrping(address,netid,argc,argv)13677c478bd9Sstevel@tonic-gate addrping(address, netid, argc, argv)
13687c478bd9Sstevel@tonic-gate 	char *address;
13697c478bd9Sstevel@tonic-gate 	char *netid;
13707c478bd9Sstevel@tonic-gate 	int argc;
13717c478bd9Sstevel@tonic-gate 	char **argv;
13727c478bd9Sstevel@tonic-gate {
13737c478bd9Sstevel@tonic-gate 	CLIENT *client;
13747c478bd9Sstevel@tonic-gate 	struct timeval to;
13757c478bd9Sstevel@tonic-gate 	enum clnt_stat rpc_stat;
13767c478bd9Sstevel@tonic-gate 	ulong_t prognum, versnum, minvers, maxvers;
13777c478bd9Sstevel@tonic-gate 	struct rpc_err rpcerr;
13787c478bd9Sstevel@tonic-gate 	int failure = 0;
13797c478bd9Sstevel@tonic-gate 	struct netconfig *nconf;
13807c478bd9Sstevel@tonic-gate 	int fd;
13817c478bd9Sstevel@tonic-gate 
13827c478bd9Sstevel@tonic-gate 	if (argc < 1 || argc > 2 || (netid == NULL)) {
13837c478bd9Sstevel@tonic-gate 		usage();
13847c478bd9Sstevel@tonic-gate 		exit(1);
13857c478bd9Sstevel@tonic-gate 	}
13867c478bd9Sstevel@tonic-gate 	nconf = getnetconfigent(netid);
13877c478bd9Sstevel@tonic-gate 	if (nconf == (struct netconfig *)NULL) {
1388791dfaa7SVallish Vaidyeshwara 		(void) fprintf(stderr, "rpcinfo: Could not find %s\n", netid);
13897c478bd9Sstevel@tonic-gate 		exit(1);
13907c478bd9Sstevel@tonic-gate 	}
13917c478bd9Sstevel@tonic-gate 	to.tv_sec = 10;
13927c478bd9Sstevel@tonic-gate 	to.tv_usec = 0;
13937c478bd9Sstevel@tonic-gate 	prognum = getprognum(argv[0]);
13947c478bd9Sstevel@tonic-gate 	if (argc == 1) {	/* Version number not known */
13957c478bd9Sstevel@tonic-gate 		/*
13967c478bd9Sstevel@tonic-gate 		 * A call to version 0 should fail with a program/version
13977c478bd9Sstevel@tonic-gate 		 * mismatch, and give us the range of versions supported.
13987c478bd9Sstevel@tonic-gate 		 */
13997c478bd9Sstevel@tonic-gate 		versnum = MIN_VERS;
14007c478bd9Sstevel@tonic-gate 	} else {
14017c478bd9Sstevel@tonic-gate 		versnum = getvers(argv[1]);
14027c478bd9Sstevel@tonic-gate 	}
14037c478bd9Sstevel@tonic-gate 	client = clnt_addr_create(address, nconf, prognum, versnum);
14047c478bd9Sstevel@tonic-gate 	rpc_stat = CLNT_CALL(client, NULLPROC, (xdrproc_t)xdr_void,
14057c478bd9Sstevel@tonic-gate 			(char *)NULL, (xdrproc_t)xdr_void,
14067c478bd9Sstevel@tonic-gate 			(char *)NULL, to);
14077c478bd9Sstevel@tonic-gate 	if (argc == 2) {
14087c478bd9Sstevel@tonic-gate 		/* Version number was known */
14097c478bd9Sstevel@tonic-gate 		if (pstatus(client, prognum, versnum) < 0)
14107c478bd9Sstevel@tonic-gate 			failure = 1;
14117c478bd9Sstevel@tonic-gate 		(void) CLNT_DESTROY(client);
14127c478bd9Sstevel@tonic-gate 		if (failure)
14137c478bd9Sstevel@tonic-gate 			exit(1);
14147c478bd9Sstevel@tonic-gate 		return;
14157c478bd9Sstevel@tonic-gate 	}
14167c478bd9Sstevel@tonic-gate 	/* Version number not known */
14177c478bd9Sstevel@tonic-gate 	(void) CLNT_CONTROL(client, CLSET_FD_NCLOSE, (char *)NULL);
14187c478bd9Sstevel@tonic-gate 	(void) CLNT_CONTROL(client, CLGET_FD, (char *)&fd);
14197c478bd9Sstevel@tonic-gate 	if (rpc_stat == RPC_PROGVERSMISMATCH) {
14207c478bd9Sstevel@tonic-gate 		clnt_geterr(client, &rpcerr);
14217c478bd9Sstevel@tonic-gate 		minvers = rpcerr.re_vers.low;
14227c478bd9Sstevel@tonic-gate 		maxvers = rpcerr.re_vers.high;
14237c478bd9Sstevel@tonic-gate 	} else if (rpc_stat == RPC_SUCCESS) {
14247c478bd9Sstevel@tonic-gate 		/*
14257c478bd9Sstevel@tonic-gate 		 * Oh dear, it DOES support version 0.
14267c478bd9Sstevel@tonic-gate 		 * Let's try version MAX_VERS.
14277c478bd9Sstevel@tonic-gate 		 */
14287c478bd9Sstevel@tonic-gate 		(void) CLNT_DESTROY(client);
14297c478bd9Sstevel@tonic-gate 		client = clnt_addr_create(address, nconf, prognum, MAX_VERS);
14307c478bd9Sstevel@tonic-gate 		rpc_stat = CLNT_CALL(client, NULLPROC, (xdrproc_t)xdr_void,
14317c478bd9Sstevel@tonic-gate 				(char *)NULL, (xdrproc_t)xdr_void,
14327c478bd9Sstevel@tonic-gate 				(char *)NULL, to);
14337c478bd9Sstevel@tonic-gate 		if (rpc_stat == RPC_PROGVERSMISMATCH) {
14347c478bd9Sstevel@tonic-gate 			clnt_geterr(client, &rpcerr);
14357c478bd9Sstevel@tonic-gate 			minvers = rpcerr.re_vers.low;
14367c478bd9Sstevel@tonic-gate 			maxvers = rpcerr.re_vers.high;
14377c478bd9Sstevel@tonic-gate 		} else if (rpc_stat == RPC_SUCCESS) {
14387c478bd9Sstevel@tonic-gate 			/*
14397c478bd9Sstevel@tonic-gate 			 * It also supports version MAX_VERS.
14407c478bd9Sstevel@tonic-gate 			 * Looks like we have a wise guy.
14417c478bd9Sstevel@tonic-gate 			 * OK, we give them information on all
14427c478bd9Sstevel@tonic-gate 			 * 4 billion versions they support...
14437c478bd9Sstevel@tonic-gate 			 */
14447c478bd9Sstevel@tonic-gate 			minvers = 0;
14457c478bd9Sstevel@tonic-gate 			maxvers = MAX_VERS;
14467c478bd9Sstevel@tonic-gate 		} else {
14477c478bd9Sstevel@tonic-gate 			(void) pstatus(client, prognum, MAX_VERS);
14487c478bd9Sstevel@tonic-gate 			exit(1);
14497c478bd9Sstevel@tonic-gate 		}
14507c478bd9Sstevel@tonic-gate 	} else {
14517c478bd9Sstevel@tonic-gate 		(void) pstatus(client, prognum, (ulong_t)0);
14527c478bd9Sstevel@tonic-gate 		exit(1);
14537c478bd9Sstevel@tonic-gate 	}
14547c478bd9Sstevel@tonic-gate 	(void) CLNT_DESTROY(client);
14557c478bd9Sstevel@tonic-gate 	for (versnum = minvers; versnum <= maxvers; versnum++) {
14567c478bd9Sstevel@tonic-gate 		client = clnt_addr_create(address, nconf, prognum, versnum);
14577c478bd9Sstevel@tonic-gate 		rpc_stat = CLNT_CALL(client, NULLPROC, (xdrproc_t)xdr_void,
14587c478bd9Sstevel@tonic-gate 				(char *)NULL, (xdrproc_t)xdr_void,
14597c478bd9Sstevel@tonic-gate 				(char *)NULL, to);
14607c478bd9Sstevel@tonic-gate 		if (pstatus(client, prognum, versnum) < 0)
14617c478bd9Sstevel@tonic-gate 				failure = 1;
14627c478bd9Sstevel@tonic-gate 		(void) CLNT_DESTROY(client);
14637c478bd9Sstevel@tonic-gate 	}
14647c478bd9Sstevel@tonic-gate 	(void) t_close(fd);
14657c478bd9Sstevel@tonic-gate 	if (failure)
14667c478bd9Sstevel@tonic-gate 		exit(1);
14677c478bd9Sstevel@tonic-gate }
14687c478bd9Sstevel@tonic-gate 
14697c478bd9Sstevel@tonic-gate /*
14707c478bd9Sstevel@tonic-gate  * If the version number is given, ping that (prog, vers); else try to find
14717c478bd9Sstevel@tonic-gate  * the version numbers supported for that prog and ping all the versions.
14727c478bd9Sstevel@tonic-gate  * Remote rpcbind is *contacted* for this service. The requests are
14737c478bd9Sstevel@tonic-gate  * then sent directly to the services themselves.
14747c478bd9Sstevel@tonic-gate  */
14757c478bd9Sstevel@tonic-gate static void
progping(netid,argc,argv)14767c478bd9Sstevel@tonic-gate progping(netid, argc, argv)
14777c478bd9Sstevel@tonic-gate 	char *netid;
14787c478bd9Sstevel@tonic-gate 	int argc;
14797c478bd9Sstevel@tonic-gate 	char **argv;
14807c478bd9Sstevel@tonic-gate {
14817c478bd9Sstevel@tonic-gate 	CLIENT *client;
14827c478bd9Sstevel@tonic-gate 	struct timeval to;
14837c478bd9Sstevel@tonic-gate 	enum clnt_stat rpc_stat;
14847c478bd9Sstevel@tonic-gate 	ulong_t prognum, versnum, minvers, maxvers;
14857c478bd9Sstevel@tonic-gate 	struct rpc_err rpcerr;
14867c478bd9Sstevel@tonic-gate 	int failure = 0;
14877c478bd9Sstevel@tonic-gate 	struct netconfig *nconf;
14887c478bd9Sstevel@tonic-gate 
14897c478bd9Sstevel@tonic-gate 	if (argc < 2 || argc > 3 || (netid == NULL)) {
14907c478bd9Sstevel@tonic-gate 		usage();
14917c478bd9Sstevel@tonic-gate 		exit(1);
14927c478bd9Sstevel@tonic-gate 	}
14937c478bd9Sstevel@tonic-gate 	prognum = getprognum(argv[1]);
14947c478bd9Sstevel@tonic-gate 	if (argc == 2) { /* Version number not known */
14957c478bd9Sstevel@tonic-gate 		/*
14967c478bd9Sstevel@tonic-gate 		 * A call to version 0 should fail with a program/version
14977c478bd9Sstevel@tonic-gate 		 * mismatch, and give us the range of versions supported.
14987c478bd9Sstevel@tonic-gate 		 */
14997c478bd9Sstevel@tonic-gate 		versnum = MIN_VERS;
15007c478bd9Sstevel@tonic-gate 	} else {
15017c478bd9Sstevel@tonic-gate 		versnum = getvers(argv[2]);
15027c478bd9Sstevel@tonic-gate 	}
15037c478bd9Sstevel@tonic-gate 	if (netid) {
15047c478bd9Sstevel@tonic-gate 		nconf = getnetconfigent(netid);
15057c478bd9Sstevel@tonic-gate 		if (nconf == (struct netconfig *)NULL) {
1506791dfaa7SVallish Vaidyeshwara 			(void) fprintf(stderr,
1507791dfaa7SVallish Vaidyeshwara 				"rpcinfo: Could not find %s\n", netid);
15087c478bd9Sstevel@tonic-gate 			exit(1);
15097c478bd9Sstevel@tonic-gate 		}
15107c478bd9Sstevel@tonic-gate 		client = clnt_tp_create(argv[0], prognum, versnum, nconf);
15117c478bd9Sstevel@tonic-gate 	} else {
15127c478bd9Sstevel@tonic-gate 		client = clnt_create(argv[0], prognum, versnum, "NETPATH");
15137c478bd9Sstevel@tonic-gate 	}
15147c478bd9Sstevel@tonic-gate 	if (client == (CLIENT *)NULL) {
15157c478bd9Sstevel@tonic-gate 		clnt_pcreateerror("rpcinfo");
15167c478bd9Sstevel@tonic-gate 		exit(1);
15177c478bd9Sstevel@tonic-gate 	}
15187c478bd9Sstevel@tonic-gate 	to.tv_sec = 10;
15197c478bd9Sstevel@tonic-gate 	to.tv_usec = 0;
15207c478bd9Sstevel@tonic-gate 	rpc_stat = CLNT_CALL(client, NULLPROC, (xdrproc_t)xdr_void,
15217c478bd9Sstevel@tonic-gate 			(char *)NULL, (xdrproc_t)xdr_void,
15227c478bd9Sstevel@tonic-gate 			(char *)NULL, to);
15237c478bd9Sstevel@tonic-gate 	if (argc == 3) {
15247c478bd9Sstevel@tonic-gate 		/* Version number was known */
15257c478bd9Sstevel@tonic-gate 		if (pstatus(client, prognum, versnum) < 0)
15267c478bd9Sstevel@tonic-gate 			failure = 1;
15277c478bd9Sstevel@tonic-gate 		(void) CLNT_DESTROY(client);
15287c478bd9Sstevel@tonic-gate 		if (failure)
15297c478bd9Sstevel@tonic-gate 			exit(1);
15307c478bd9Sstevel@tonic-gate 		return;
15317c478bd9Sstevel@tonic-gate 	}
15327c478bd9Sstevel@tonic-gate 	/* Version number not known */
15337c478bd9Sstevel@tonic-gate 	if (rpc_stat == RPC_PROGVERSMISMATCH) {
15347c478bd9Sstevel@tonic-gate 		clnt_geterr(client, &rpcerr);
15357c478bd9Sstevel@tonic-gate 		minvers = rpcerr.re_vers.low;
15367c478bd9Sstevel@tonic-gate 		maxvers = rpcerr.re_vers.high;
15377c478bd9Sstevel@tonic-gate 	} else if (rpc_stat == RPC_SUCCESS) {
15387c478bd9Sstevel@tonic-gate 		/*
15397c478bd9Sstevel@tonic-gate 		 * Oh dear, it DOES support version 0.
15407c478bd9Sstevel@tonic-gate 		 * Let's try version MAX_VERS.
15417c478bd9Sstevel@tonic-gate 		 */
15427c478bd9Sstevel@tonic-gate 		versnum = MAX_VERS;
15437c478bd9Sstevel@tonic-gate 		(void) CLNT_CONTROL(client, CLSET_VERS, (char *)&versnum);
15447c478bd9Sstevel@tonic-gate 		rpc_stat = CLNT_CALL(client, NULLPROC,
15457c478bd9Sstevel@tonic-gate 				(xdrproc_t)xdr_void, (char *)NULL,
15467c478bd9Sstevel@tonic-gate 				(xdrproc_t)xdr_void, (char *)NULL, to);
15477c478bd9Sstevel@tonic-gate 		if (rpc_stat == RPC_PROGVERSMISMATCH) {
15487c478bd9Sstevel@tonic-gate 			clnt_geterr(client, &rpcerr);
15497c478bd9Sstevel@tonic-gate 			minvers = rpcerr.re_vers.low;
15507c478bd9Sstevel@tonic-gate 			maxvers = rpcerr.re_vers.high;
15517c478bd9Sstevel@tonic-gate 		} else if (rpc_stat == RPC_SUCCESS) {
15527c478bd9Sstevel@tonic-gate 			/*
15537c478bd9Sstevel@tonic-gate 			 * It also supports version MAX_VERS.
15547c478bd9Sstevel@tonic-gate 			 * Looks like we have a wise guy.
15557c478bd9Sstevel@tonic-gate 			 * OK, we give them information on all
15567c478bd9Sstevel@tonic-gate 			 * 4 billion versions they support...
15577c478bd9Sstevel@tonic-gate 			 */
15587c478bd9Sstevel@tonic-gate 			minvers = 0;
15597c478bd9Sstevel@tonic-gate 			maxvers = MAX_VERS;
15607c478bd9Sstevel@tonic-gate 		} else {
15617c478bd9Sstevel@tonic-gate 			(void) pstatus(client, prognum, MAX_VERS);
15627c478bd9Sstevel@tonic-gate 			exit(1);
15637c478bd9Sstevel@tonic-gate 		}
15647c478bd9Sstevel@tonic-gate 	} else {
15657c478bd9Sstevel@tonic-gate 		(void) pstatus(client, prognum, (ulong_t)0);
15667c478bd9Sstevel@tonic-gate 		exit(1);
15677c478bd9Sstevel@tonic-gate 	}
15687c478bd9Sstevel@tonic-gate 	for (versnum = minvers; versnum <= maxvers; versnum++) {
15697c478bd9Sstevel@tonic-gate 		(void) CLNT_CONTROL(client, CLSET_VERS, (char *)&versnum);
15707c478bd9Sstevel@tonic-gate 		rpc_stat = CLNT_CALL(client, NULLPROC, (xdrproc_t)xdr_void,
15717c478bd9Sstevel@tonic-gate 					(char *)NULL, (xdrproc_t)xdr_void,
15727c478bd9Sstevel@tonic-gate 					(char *)NULL, to);
15737c478bd9Sstevel@tonic-gate 		if (pstatus(client, prognum, versnum) < 0)
15747c478bd9Sstevel@tonic-gate 				failure = 1;
15757c478bd9Sstevel@tonic-gate 	}
15767c478bd9Sstevel@tonic-gate 	(void) CLNT_DESTROY(client);
15777c478bd9Sstevel@tonic-gate 	if (failure)
15787c478bd9Sstevel@tonic-gate 		exit(1);
15797c478bd9Sstevel@tonic-gate }
15807c478bd9Sstevel@tonic-gate 
15817c478bd9Sstevel@tonic-gate static void
usage()15827c478bd9Sstevel@tonic-gate usage()
15837c478bd9Sstevel@tonic-gate {
1584*a1cf91d7SMarcel Telka 	(void) fprintf(stderr, "Usage: rpcinfo [-T netid] [-m | -s] [host]\n");
15857c478bd9Sstevel@tonic-gate #ifdef PORTMAP
1586791dfaa7SVallish Vaidyeshwara 	(void) fprintf(stderr, "       rpcinfo -p [host]\n");
15877c478bd9Sstevel@tonic-gate #endif
1588791dfaa7SVallish Vaidyeshwara 	(void) fprintf(stderr,
1589791dfaa7SVallish Vaidyeshwara 	    "       rpcinfo -T netid host prognum [versnum]\n");
1590*a1cf91d7SMarcel Telka 	(void) fprintf(stderr,
1591*a1cf91d7SMarcel Telka 	    "       rpcinfo -l [-T netid] host prognum versnum\n");
15927c478bd9Sstevel@tonic-gate #ifdef PORTMAP
1593791dfaa7SVallish Vaidyeshwara 	(void) fprintf(stderr,
1594*a1cf91d7SMarcel Telka 	    "       rpcinfo [-n portnum] -u | -t host prognum [versnum]\n");
15957c478bd9Sstevel@tonic-gate #endif
1596791dfaa7SVallish Vaidyeshwara 	(void) fprintf(stderr,
1597*a1cf91d7SMarcel Telka 	    "       rpcinfo -a serv_address -T netid prognum [versnum]\n");
1598*a1cf91d7SMarcel Telka 	(void) fprintf(stderr,
1599*a1cf91d7SMarcel Telka 	    "       rpcinfo -b [-T netid] prognum versnum\n");
1600791dfaa7SVallish Vaidyeshwara 	(void) fprintf(stderr,
1601791dfaa7SVallish Vaidyeshwara 	    "       rpcinfo -d [-T netid] prognum versnum\n");
16027c478bd9Sstevel@tonic-gate }
16037c478bd9Sstevel@tonic-gate 
16047c478bd9Sstevel@tonic-gate static ulong_t
getprognum(arg)16057c478bd9Sstevel@tonic-gate getprognum  (arg)
16067c478bd9Sstevel@tonic-gate 	char *arg;
16077c478bd9Sstevel@tonic-gate {
16087c478bd9Sstevel@tonic-gate 	char *strptr;
16097c478bd9Sstevel@tonic-gate 	register struct rpcent *rpc;
16107c478bd9Sstevel@tonic-gate 	register ulong_t prognum;
16117c478bd9Sstevel@tonic-gate 	char *tptr = arg;
16127c478bd9Sstevel@tonic-gate 
16137c478bd9Sstevel@tonic-gate 	while (*tptr && isdigit(*tptr++));
16147c478bd9Sstevel@tonic-gate 	if (*tptr || isalpha(*(tptr - 1))) {
16157c478bd9Sstevel@tonic-gate 		rpc = getrpcbyname(arg);
16167c478bd9Sstevel@tonic-gate 		if (rpc == NULL) {
1617791dfaa7SVallish Vaidyeshwara 			(void) fprintf(stderr,
1618791dfaa7SVallish Vaidyeshwara 				"rpcinfo: %s is unknown service\n", arg);
16197c478bd9Sstevel@tonic-gate 			exit(1);
16207c478bd9Sstevel@tonic-gate 		}
16217c478bd9Sstevel@tonic-gate 		prognum = rpc->r_number;
16227c478bd9Sstevel@tonic-gate 	} else {
16237c478bd9Sstevel@tonic-gate 		prognum = strtol(arg, &strptr, 10);
16247c478bd9Sstevel@tonic-gate 		if (strptr == arg || *strptr != '\0') {
1625791dfaa7SVallish Vaidyeshwara 			(void) fprintf(stderr,
16267c478bd9Sstevel@tonic-gate 		"rpcinfo: %s is illegal program number\n", arg);
16277c478bd9Sstevel@tonic-gate 			exit(1);
16287c478bd9Sstevel@tonic-gate 		}
16297c478bd9Sstevel@tonic-gate 	}
16307c478bd9Sstevel@tonic-gate 	return (prognum);
16317c478bd9Sstevel@tonic-gate }
16327c478bd9Sstevel@tonic-gate 
16337c478bd9Sstevel@tonic-gate static ulong_t
getvers(arg)16347c478bd9Sstevel@tonic-gate getvers(arg)
16357c478bd9Sstevel@tonic-gate 	char *arg;
16367c478bd9Sstevel@tonic-gate {
16377c478bd9Sstevel@tonic-gate 	char *strptr;
16387c478bd9Sstevel@tonic-gate 	register ulong_t vers;
16397c478bd9Sstevel@tonic-gate 
16407c478bd9Sstevel@tonic-gate 	vers = (int)strtol(arg, &strptr, 10);
16417c478bd9Sstevel@tonic-gate 	if (strptr == arg || *strptr != '\0') {
1642791dfaa7SVallish Vaidyeshwara 		(void) fprintf(stderr,
1643791dfaa7SVallish Vaidyeshwara 			"rpcinfo: %s is illegal version number\n", arg);
16447c478bd9Sstevel@tonic-gate 		exit(1);
16457c478bd9Sstevel@tonic-gate 	}
16467c478bd9Sstevel@tonic-gate 	return (vers);
16477c478bd9Sstevel@tonic-gate }
16487c478bd9Sstevel@tonic-gate 
16497c478bd9Sstevel@tonic-gate /*
16507c478bd9Sstevel@tonic-gate  * This routine should take a pointer to an "rpc_err" structure, rather than
16517c478bd9Sstevel@tonic-gate  * a pointer to a CLIENT structure, but "clnt_perror" takes a pointer to
16527c478bd9Sstevel@tonic-gate  * a CLIENT structure rather than a pointer to an "rpc_err" structure.
16537c478bd9Sstevel@tonic-gate  * As such, we have to keep the CLIENT structure around in order to print
16547c478bd9Sstevel@tonic-gate  * a good error message.
16557c478bd9Sstevel@tonic-gate  */
16567c478bd9Sstevel@tonic-gate static int
pstatus(client,prog,vers)16577c478bd9Sstevel@tonic-gate pstatus(client, prog, vers)
16587c478bd9Sstevel@tonic-gate 	register CLIENT *client;
16597c478bd9Sstevel@tonic-gate 	ulong_t prog;
16607c478bd9Sstevel@tonic-gate 	ulong_t vers;
16617c478bd9Sstevel@tonic-gate {
16627c478bd9Sstevel@tonic-gate 	struct rpc_err rpcerr;
16637c478bd9Sstevel@tonic-gate 
16647c478bd9Sstevel@tonic-gate 	clnt_geterr(client, &rpcerr);
16657c478bd9Sstevel@tonic-gate 	if (rpcerr.re_status != RPC_SUCCESS) {
16667c478bd9Sstevel@tonic-gate 		clnt_perror(client, "rpcinfo");
1667791dfaa7SVallish Vaidyeshwara 		(void) printf("program %lu version %lu is not available\n",
16687c478bd9Sstevel@tonic-gate 			prog, vers);
16697c478bd9Sstevel@tonic-gate 		return (-1);
16707c478bd9Sstevel@tonic-gate 	} else {
1671791dfaa7SVallish Vaidyeshwara 		(void) printf("program %lu version %lu ready and waiting\n",
16727c478bd9Sstevel@tonic-gate 			prog, vers);
16737c478bd9Sstevel@tonic-gate 		return (0);
16747c478bd9Sstevel@tonic-gate 	}
16757c478bd9Sstevel@tonic-gate }
16767c478bd9Sstevel@tonic-gate 
16777c478bd9Sstevel@tonic-gate static CLIENT *
clnt_rpcbind_create(host,rpcbversnum,targaddr)16787c478bd9Sstevel@tonic-gate clnt_rpcbind_create(host, rpcbversnum, targaddr)
16797c478bd9Sstevel@tonic-gate 	char *host;
16807c478bd9Sstevel@tonic-gate 	ulong_t rpcbversnum;
16817c478bd9Sstevel@tonic-gate 	struct netbuf **targaddr;
16827c478bd9Sstevel@tonic-gate {
16837c478bd9Sstevel@tonic-gate 	static char *tlist[3] = {
16847c478bd9Sstevel@tonic-gate 		"circuit_n", "circuit_v", "datagram_v"
16857c478bd9Sstevel@tonic-gate 	};
16867c478bd9Sstevel@tonic-gate 	int i;
16877c478bd9Sstevel@tonic-gate 	struct netconfig *nconf;
16887c478bd9Sstevel@tonic-gate 	CLIENT *clnt = NULL;
16897c478bd9Sstevel@tonic-gate 	void *handle;
16907c478bd9Sstevel@tonic-gate 
16917c478bd9Sstevel@tonic-gate 	rpc_createerr.cf_stat = RPC_SUCCESS;
16927c478bd9Sstevel@tonic-gate 	for (i = 0; i < 3; i++) {
16937c478bd9Sstevel@tonic-gate 		if ((handle = __rpc_setconf(tlist[i])) == NULL)
16947c478bd9Sstevel@tonic-gate 			continue;
16957c478bd9Sstevel@tonic-gate 		while (clnt == (CLIENT *)NULL) {
16967c478bd9Sstevel@tonic-gate 			if ((nconf = __rpc_getconf(handle)) == NULL) {
16977c478bd9Sstevel@tonic-gate 				if (rpc_createerr.cf_stat == RPC_SUCCESS)
16987c478bd9Sstevel@tonic-gate 				    rpc_createerr.cf_stat = RPC_UNKNOWNPROTO;
16997c478bd9Sstevel@tonic-gate 				break;
17007c478bd9Sstevel@tonic-gate 			}
17017c478bd9Sstevel@tonic-gate 			clnt = getclnthandle(host, nconf, rpcbversnum,
17027c478bd9Sstevel@tonic-gate 					targaddr);
17037c478bd9Sstevel@tonic-gate 		}
17047c478bd9Sstevel@tonic-gate 		if (clnt)
17057c478bd9Sstevel@tonic-gate 			break;
17067c478bd9Sstevel@tonic-gate 		__rpc_endconf(handle);
17077c478bd9Sstevel@tonic-gate 	}
17087c478bd9Sstevel@tonic-gate 	return (clnt);
17097c478bd9Sstevel@tonic-gate }
17107c478bd9Sstevel@tonic-gate 
17117c478bd9Sstevel@tonic-gate static CLIENT*
getclnthandle(host,nconf,rpcbversnum,targaddr)17127c478bd9Sstevel@tonic-gate getclnthandle(host, nconf, rpcbversnum, targaddr)
17137c478bd9Sstevel@tonic-gate 	char *host;
17147c478bd9Sstevel@tonic-gate 	struct netconfig *nconf;
17157c478bd9Sstevel@tonic-gate 	ulong_t rpcbversnum;
17167c478bd9Sstevel@tonic-gate 	struct netbuf **targaddr;
17177c478bd9Sstevel@tonic-gate {
17187c478bd9Sstevel@tonic-gate 	struct netbuf *addr;
17197c478bd9Sstevel@tonic-gate 	struct nd_addrlist *nas;
17207c478bd9Sstevel@tonic-gate 	struct nd_hostserv rpcbind_hs;
17217c478bd9Sstevel@tonic-gate 	CLIENT *client = NULL;
17227c478bd9Sstevel@tonic-gate 
17237c478bd9Sstevel@tonic-gate 	/* Get the address of the rpcbind */
17247c478bd9Sstevel@tonic-gate 	rpcbind_hs.h_host = host;
17257c478bd9Sstevel@tonic-gate 	rpcbind_hs.h_serv = "rpcbind";
17267c478bd9Sstevel@tonic-gate 	if (netdir_getbyname(nconf, &rpcbind_hs, &nas)) {
17277c478bd9Sstevel@tonic-gate 		rpc_createerr.cf_stat = RPC_N2AXLATEFAILURE;
17287c478bd9Sstevel@tonic-gate 		return (NULL);
17297c478bd9Sstevel@tonic-gate 	}
17307c478bd9Sstevel@tonic-gate 	addr = nas->n_addrs;
17317c478bd9Sstevel@tonic-gate 	client = clnt_tli_create(RPC_ANYFD, nconf, addr, RPCBPROG,
17327c478bd9Sstevel@tonic-gate 			rpcbversnum, 0, 0);
17337c478bd9Sstevel@tonic-gate 	if (client) {
17347c478bd9Sstevel@tonic-gate 		if (targaddr != NULL) {
17357c478bd9Sstevel@tonic-gate 			*targaddr =
17367c478bd9Sstevel@tonic-gate 			    (struct netbuf *)malloc(sizeof (struct netbuf));
17377c478bd9Sstevel@tonic-gate 			if (*targaddr != NULL) {
17387c478bd9Sstevel@tonic-gate 				(*targaddr)->maxlen = addr->maxlen;
17397c478bd9Sstevel@tonic-gate 				(*targaddr)->len = addr->len;
17407c478bd9Sstevel@tonic-gate 				(*targaddr)->buf = (char *)malloc(addr->len);
17417c478bd9Sstevel@tonic-gate 				if ((*targaddr)->buf != NULL) {
1742791dfaa7SVallish Vaidyeshwara 					(void) memcpy((*targaddr)->buf,
1743791dfaa7SVallish Vaidyeshwara 						addr->buf, addr->len);
17447c478bd9Sstevel@tonic-gate 				}
17457c478bd9Sstevel@tonic-gate 			}
17467c478bd9Sstevel@tonic-gate 		}
17477c478bd9Sstevel@tonic-gate 	} else {
17487c478bd9Sstevel@tonic-gate 		if (rpc_createerr.cf_stat == RPC_TLIERROR) {
17497c478bd9Sstevel@tonic-gate 			/*
17507c478bd9Sstevel@tonic-gate 			 * Assume that the other system is dead; this is a
17517c478bd9Sstevel@tonic-gate 			 * better error to display to the user.
17527c478bd9Sstevel@tonic-gate 			 */
17537c478bd9Sstevel@tonic-gate 			rpc_createerr.cf_stat = RPC_RPCBFAILURE;
17547c478bd9Sstevel@tonic-gate 			rpc_createerr.cf_error.re_status = RPC_FAILED;
17557c478bd9Sstevel@tonic-gate 		}
17567c478bd9Sstevel@tonic-gate 	}
17577c478bd9Sstevel@tonic-gate 	netdir_free((char *)nas, ND_ADDRLIST);
17587c478bd9Sstevel@tonic-gate 	return (client);
17597c478bd9Sstevel@tonic-gate }
17607c478bd9Sstevel@tonic-gate 
17617c478bd9Sstevel@tonic-gate static void
print_rmtcallstat(rtype,infp)17627c478bd9Sstevel@tonic-gate print_rmtcallstat(rtype, infp)
17637c478bd9Sstevel@tonic-gate 	int rtype;
17647c478bd9Sstevel@tonic-gate 	rpcb_stat *infp;
17657c478bd9Sstevel@tonic-gate {
17667c478bd9Sstevel@tonic-gate 	register rpcbs_rmtcalllist_ptr pr;
17677c478bd9Sstevel@tonic-gate 	struct rpcent *rpc;
17687c478bd9Sstevel@tonic-gate 
17697c478bd9Sstevel@tonic-gate 	if (rtype == RPCBVERS_4_STAT)
1770791dfaa7SVallish Vaidyeshwara 		(void) printf(
17717c478bd9Sstevel@tonic-gate 		"prog\t\tvers\tproc\tnetid\tindirect success failure\n");
17727c478bd9Sstevel@tonic-gate 	else
1773791dfaa7SVallish Vaidyeshwara 		(void) printf("prog\t\tvers\tproc\tnetid\tsuccess\tfailure\n");
17747c478bd9Sstevel@tonic-gate 	for (pr = infp->rmtinfo; pr; pr = pr->next) {
17757c478bd9Sstevel@tonic-gate 		rpc = getrpcbynumber(pr->prog);
17767c478bd9Sstevel@tonic-gate 		if (rpc)
1777791dfaa7SVallish Vaidyeshwara 			(void) printf("%-16s", rpc->r_name);
17787c478bd9Sstevel@tonic-gate 		else
1779791dfaa7SVallish Vaidyeshwara #if defined(_LP64) || defined(_I32LPx)
1780791dfaa7SVallish Vaidyeshwara 			(void) printf("%-16u", pr->prog);
1781791dfaa7SVallish Vaidyeshwara 		(void) printf("%u\t%u\t%-7s ",
1782791dfaa7SVallish Vaidyeshwara #else
1783791dfaa7SVallish Vaidyeshwara 			(void) printf("%-16lu", pr->prog);
1784791dfaa7SVallish Vaidyeshwara 		(void) printf("%lu\t%lu\t%-7s ",
1785791dfaa7SVallish Vaidyeshwara #endif
17867c478bd9Sstevel@tonic-gate 			pr->vers, pr->proc, pr->netid);
17877c478bd9Sstevel@tonic-gate 		if (rtype == RPCBVERS_4_STAT)
1788791dfaa7SVallish Vaidyeshwara 			(void) printf("%d\t ", pr->indirect);
1789791dfaa7SVallish Vaidyeshwara 		(void) printf("%d\t%d\n", pr->success, pr->failure);
17907c478bd9Sstevel@tonic-gate 	}
17917c478bd9Sstevel@tonic-gate }
17927c478bd9Sstevel@tonic-gate 
17937c478bd9Sstevel@tonic-gate static void
1794791dfaa7SVallish Vaidyeshwara /* LINTED E_FUNC_ARG_UNUSED for 1st arg rtype */
print_getaddrstat(rtype,infp)17957c478bd9Sstevel@tonic-gate print_getaddrstat(rtype, infp)
17967c478bd9Sstevel@tonic-gate 	int rtype;
17977c478bd9Sstevel@tonic-gate 	rpcb_stat *infp;
17987c478bd9Sstevel@tonic-gate {
17997c478bd9Sstevel@tonic-gate 	rpcbs_addrlist_ptr al;
18007c478bd9Sstevel@tonic-gate 	register struct rpcent *rpc;
18017c478bd9Sstevel@tonic-gate 
1802791dfaa7SVallish Vaidyeshwara 	(void) printf("prog\t\tvers\tnetid\t  success\tfailure\n");
18037c478bd9Sstevel@tonic-gate 	for (al = infp->addrinfo; al; al = al->next) {
18047c478bd9Sstevel@tonic-gate 		rpc = getrpcbynumber(al->prog);
18057c478bd9Sstevel@tonic-gate 		if (rpc)
1806791dfaa7SVallish Vaidyeshwara 			(void) printf("%-16s", rpc->r_name);
18077c478bd9Sstevel@tonic-gate 		else
1808791dfaa7SVallish Vaidyeshwara #if defined(_LP64) || defined(_I32LPx)
1809791dfaa7SVallish Vaidyeshwara 			(void) printf("%-16u", al->prog);
1810791dfaa7SVallish Vaidyeshwara 		(void) printf("%u\t%-9s %-12d\t%d\n",
1811791dfaa7SVallish Vaidyeshwara #else
1812791dfaa7SVallish Vaidyeshwara 			(void) printf("%-16lu", al->prog);
1813791dfaa7SVallish Vaidyeshwara 		(void) printf("%lu\t%-9s %-12d\t%d\n",
1814791dfaa7SVallish Vaidyeshwara #endif
18157c478bd9Sstevel@tonic-gate 			al->vers, al->netid,
18167c478bd9Sstevel@tonic-gate 			al->success, al->failure);
18177c478bd9Sstevel@tonic-gate 	}
18187c478bd9Sstevel@tonic-gate }
18197c478bd9Sstevel@tonic-gate 
18207c478bd9Sstevel@tonic-gate static char *
spaces(howmany)18217c478bd9Sstevel@tonic-gate spaces(howmany)
18227c478bd9Sstevel@tonic-gate int howmany;
18237c478bd9Sstevel@tonic-gate {
18247c478bd9Sstevel@tonic-gate 	static char space_array[] =		/* 64 spaces */
18257c478bd9Sstevel@tonic-gate 	"                                                                ";
18267c478bd9Sstevel@tonic-gate 
18277c478bd9Sstevel@tonic-gate 	if (howmany <= 0 || howmany > sizeof (space_array)) {
18287c478bd9Sstevel@tonic-gate 		return ("");
18297c478bd9Sstevel@tonic-gate 	}
18307c478bd9Sstevel@tonic-gate 	return (&space_array[sizeof (space_array) - howmany - 1]);
18317c478bd9Sstevel@tonic-gate }
1832