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 5*791dfaa7SVallish Vaidyeshwara * Common Development and Distribution License (the "License"). 6*791dfaa7SVallish 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 207c478bd9Sstevel@tonic-gate * 21*791dfaa7SVallish Vaidyeshwara * Copyright 2010 Sun Microsystems, Inc. All rights reserved. 227c478bd9Sstevel@tonic-gate * Use is subject to license terms. 237c478bd9Sstevel@tonic-gate */ 247c478bd9Sstevel@tonic-gate /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */ 257c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 267c478bd9Sstevel@tonic-gate /* 277c478bd9Sstevel@tonic-gate * University Copyright- Copyright (c) 1982, 1986, 1988 287c478bd9Sstevel@tonic-gate * The Regents of the University of California 297c478bd9Sstevel@tonic-gate * All Rights Reserved 307c478bd9Sstevel@tonic-gate * 317c478bd9Sstevel@tonic-gate * University Acknowledgment- Portions of this document are derived from 327c478bd9Sstevel@tonic-gate * software developed by the University of California, Berkeley, and its 337c478bd9Sstevel@tonic-gate * contributors. 347c478bd9Sstevel@tonic-gate */ 357c478bd9Sstevel@tonic-gate 367c478bd9Sstevel@tonic-gate /* 377c478bd9Sstevel@tonic-gate * rpcinfo: ping a particular rpc program 387c478bd9Sstevel@tonic-gate * or dump the the registered programs on the remote machine. 397c478bd9Sstevel@tonic-gate */ 407c478bd9Sstevel@tonic-gate 417c478bd9Sstevel@tonic-gate /* 427c478bd9Sstevel@tonic-gate * We are for now defining PORTMAP here. It doesnt even compile 437c478bd9Sstevel@tonic-gate * unless it is defined. 447c478bd9Sstevel@tonic-gate */ 457c478bd9Sstevel@tonic-gate #ifndef PORTMAP 467c478bd9Sstevel@tonic-gate #define PORTMAP 477c478bd9Sstevel@tonic-gate #endif 487c478bd9Sstevel@tonic-gate 497c478bd9Sstevel@tonic-gate /* 507c478bd9Sstevel@tonic-gate * If PORTMAP is defined, rpcinfo will talk to both portmapper and 517c478bd9Sstevel@tonic-gate * rpcbind programs; else it talks only to rpcbind. In the latter case 527c478bd9Sstevel@tonic-gate * all the portmapper specific options such as -u, -t, -p become void. 537c478bd9Sstevel@tonic-gate */ 547c478bd9Sstevel@tonic-gate #include <rpc/rpc.h> 557c478bd9Sstevel@tonic-gate #include <stdio.h> 567c478bd9Sstevel@tonic-gate #include <rpc/rpcb_prot.h> 577c478bd9Sstevel@tonic-gate #include <rpc/nettype.h> 587c478bd9Sstevel@tonic-gate #include <netdir.h> 597c478bd9Sstevel@tonic-gate #include <rpc/rpcent.h> 607c478bd9Sstevel@tonic-gate #include <sys/utsname.h> 617c478bd9Sstevel@tonic-gate #include <stdlib.h> 627c478bd9Sstevel@tonic-gate #include <string.h> 63*791dfaa7SVallish Vaidyeshwara #include <ctype.h> 647c478bd9Sstevel@tonic-gate 657c478bd9Sstevel@tonic-gate #ifdef PORTMAP /* Support for version 2 portmapper */ 667c478bd9Sstevel@tonic-gate #include <netinet/in.h> 677c478bd9Sstevel@tonic-gate #include <sys/socket.h> 687c478bd9Sstevel@tonic-gate #include <netdb.h> 697c478bd9Sstevel@tonic-gate #include <arpa/inet.h> 707c478bd9Sstevel@tonic-gate #include <rpc/pmap_prot.h> 717c478bd9Sstevel@tonic-gate #include <rpc/pmap_clnt.h> 727c478bd9Sstevel@tonic-gate #endif 737c478bd9Sstevel@tonic-gate 747c478bd9Sstevel@tonic-gate #define MAXHOSTLEN 256 757c478bd9Sstevel@tonic-gate #define MIN_VERS ((ulong_t)0) 76653c780cSssdevi #define MAX_VERS (4294967295UL) 777c478bd9Sstevel@tonic-gate #define UNKNOWN "unknown" 787c478bd9Sstevel@tonic-gate 797c478bd9Sstevel@tonic-gate #define MAX(a, b) (((a) > (b)) ? (a) : (b)) 807c478bd9Sstevel@tonic-gate 817c478bd9Sstevel@tonic-gate extern int t_errno; 827c478bd9Sstevel@tonic-gate extern long strtol(); 837c478bd9Sstevel@tonic-gate static char *spaces(); 847c478bd9Sstevel@tonic-gate 857c478bd9Sstevel@tonic-gate #ifdef PORTMAP 867c478bd9Sstevel@tonic-gate static void ip_ping(/*ushort_t portflag, char *trans, 877c478bd9Sstevel@tonic-gate int argc, char **argv*/); 887c478bd9Sstevel@tonic-gate static CLIENT *clnt_com_create(/* struct sockaddr_in *addr, long prog, 897c478bd9Sstevel@tonic-gate long vers, int *fd, char *trans*/); 907c478bd9Sstevel@tonic-gate static void pmapdump(/*int argc, char **argv*/); 917c478bd9Sstevel@tonic-gate static void get_inet_address(/*struct sockaddr_in *addr, char *host*/); 927c478bd9Sstevel@tonic-gate #endif 937c478bd9Sstevel@tonic-gate 947c478bd9Sstevel@tonic-gate static bool_t reply_proc(/*void *res, struct netbuf *who*, 957c478bd9Sstevel@tonic-gate struct netconfig *nconf*/); 967c478bd9Sstevel@tonic-gate static void brdcst(/*int argc, char **argv*/); 977c478bd9Sstevel@tonic-gate static void addrping(/*char *address, char *netid, 987c478bd9Sstevel@tonic-gate int argc, char **argv*/); 997c478bd9Sstevel@tonic-gate static void progping(/* char *netid, int argc, char **argv*/); 1007c478bd9Sstevel@tonic-gate static CLIENT *clnt_addr_create(/* char *addr, struct netconfig *nconf, 1017c478bd9Sstevel@tonic-gate long prog, long vers*/); 1027c478bd9Sstevel@tonic-gate static CLIENT *clnt_rpcbind_create(/* char *host, int vers */); 1037c478bd9Sstevel@tonic-gate static CLIENT *getclnthandle(/* host, nconf, rpcbversnum */); 1047c478bd9Sstevel@tonic-gate static int pstatus(/*CLIENT *client, ulong_t prognum, ulong_t vers*/); 1057c478bd9Sstevel@tonic-gate static void rpcbdump(/*char *netid, int argc, char **argv*/); 1067c478bd9Sstevel@tonic-gate static void rpcbgetstat(/* int argc, char **argv*/); 1077c478bd9Sstevel@tonic-gate static void rpcbaddrlist(/*char *netid, int argc, char **argv*/); 1087c478bd9Sstevel@tonic-gate static void deletereg(/*char *netid, int argc, char **argv */); 1097c478bd9Sstevel@tonic-gate static void print_rmtcallstat(/* rtype, infp */); 1107c478bd9Sstevel@tonic-gate static void print_getaddrstat(/* rtype, infp */); 1117c478bd9Sstevel@tonic-gate static void usage(/*void*/); 1127c478bd9Sstevel@tonic-gate static ulong_t getprognum(/*char *arg*/); 1137c478bd9Sstevel@tonic-gate static ulong_t getvers(/*char *arg*/); 1147c478bd9Sstevel@tonic-gate 1157c478bd9Sstevel@tonic-gate /* 1167c478bd9Sstevel@tonic-gate * Functions to be performed. 1177c478bd9Sstevel@tonic-gate */ 1187c478bd9Sstevel@tonic-gate #define NONE 0 /* no function */ 1197c478bd9Sstevel@tonic-gate #define PMAPDUMP 1 /* dump portmapper registrations */ 1207c478bd9Sstevel@tonic-gate #define TCPPING 2 /* ping TCP service */ 1217c478bd9Sstevel@tonic-gate #define UDPPING 3 /* ping UDP service */ 1227c478bd9Sstevel@tonic-gate #define BROADCAST 4 /* ping broadcast service */ 1237c478bd9Sstevel@tonic-gate #define DELETES 5 /* delete registration for the service */ 1247c478bd9Sstevel@tonic-gate #define ADDRPING 6 /* pings at the given address */ 1257c478bd9Sstevel@tonic-gate #define PROGPING 7 /* pings a program on a given host */ 1267c478bd9Sstevel@tonic-gate #define RPCBDUMP 8 /* dump rpcbind registrations */ 1277c478bd9Sstevel@tonic-gate #define RPCBDUMP_SHORT 9 /* dump rpcbind registrations - short version */ 1287c478bd9Sstevel@tonic-gate #define RPCBADDRLIST 10 /* dump addr list about one prog */ 1297c478bd9Sstevel@tonic-gate #define RPCBGETSTAT 11 /* Get statistics */ 1307c478bd9Sstevel@tonic-gate 1317c478bd9Sstevel@tonic-gate struct netidlist { 1327c478bd9Sstevel@tonic-gate char *netid; 1337c478bd9Sstevel@tonic-gate struct netidlist *next; 1347c478bd9Sstevel@tonic-gate }; 1357c478bd9Sstevel@tonic-gate 1367c478bd9Sstevel@tonic-gate struct verslist { 1377c478bd9Sstevel@tonic-gate int vers; 1387c478bd9Sstevel@tonic-gate struct verslist *next; 1397c478bd9Sstevel@tonic-gate }; 1407c478bd9Sstevel@tonic-gate 1417c478bd9Sstevel@tonic-gate struct rpcbdump_short { 1427c478bd9Sstevel@tonic-gate ulong_t prog; 1437c478bd9Sstevel@tonic-gate struct verslist *vlist; 1447c478bd9Sstevel@tonic-gate struct netidlist *nlist; 1457c478bd9Sstevel@tonic-gate struct rpcbdump_short *next; 1467c478bd9Sstevel@tonic-gate char *owner; 1477c478bd9Sstevel@tonic-gate }; 1487c478bd9Sstevel@tonic-gate 1497c478bd9Sstevel@tonic-gate 1507c478bd9Sstevel@tonic-gate char *loopback_netid = NULL; 1517c478bd9Sstevel@tonic-gate struct netconfig *loopback_nconf; 1527c478bd9Sstevel@tonic-gate 1537c478bd9Sstevel@tonic-gate int 1547c478bd9Sstevel@tonic-gate main(argc, argv) 1557c478bd9Sstevel@tonic-gate int argc; 1567c478bd9Sstevel@tonic-gate char **argv; 1577c478bd9Sstevel@tonic-gate { 1587c478bd9Sstevel@tonic-gate register int c; 1597c478bd9Sstevel@tonic-gate extern char *optarg; 1607c478bd9Sstevel@tonic-gate extern int optind; 1617c478bd9Sstevel@tonic-gate int errflg; 1627c478bd9Sstevel@tonic-gate int function; 1637c478bd9Sstevel@tonic-gate char *netid = NULL; 1647c478bd9Sstevel@tonic-gate char *address = NULL; 1657c478bd9Sstevel@tonic-gate void *handle; 1667c478bd9Sstevel@tonic-gate #ifdef PORTMAP 1677c478bd9Sstevel@tonic-gate char *strptr; 1687c478bd9Sstevel@tonic-gate ushort_t portnum = 0; 1697c478bd9Sstevel@tonic-gate #endif 1707c478bd9Sstevel@tonic-gate 1717c478bd9Sstevel@tonic-gate function = NONE; 1727c478bd9Sstevel@tonic-gate errflg = 0; 1737c478bd9Sstevel@tonic-gate #ifdef PORTMAP 1747c478bd9Sstevel@tonic-gate while ((c = getopt(argc, argv, "a:bdlmn:pstT:u")) != EOF) { 1757c478bd9Sstevel@tonic-gate #else 1767c478bd9Sstevel@tonic-gate while ((c = getopt(argc, argv, "a:bdlmn:sT:")) != EOF) { 1777c478bd9Sstevel@tonic-gate #endif 1787c478bd9Sstevel@tonic-gate switch (c) { 1797c478bd9Sstevel@tonic-gate #ifdef PORTMAP 1807c478bd9Sstevel@tonic-gate case 'p': 1817c478bd9Sstevel@tonic-gate if (function != NONE) 1827c478bd9Sstevel@tonic-gate errflg = 1; 1837c478bd9Sstevel@tonic-gate else 1847c478bd9Sstevel@tonic-gate function = PMAPDUMP; 1857c478bd9Sstevel@tonic-gate break; 1867c478bd9Sstevel@tonic-gate 1877c478bd9Sstevel@tonic-gate case 't': 1887c478bd9Sstevel@tonic-gate if (function != NONE) 1897c478bd9Sstevel@tonic-gate errflg = 1; 1907c478bd9Sstevel@tonic-gate else 1917c478bd9Sstevel@tonic-gate function = TCPPING; 1927c478bd9Sstevel@tonic-gate break; 1937c478bd9Sstevel@tonic-gate 1947c478bd9Sstevel@tonic-gate case 'u': 1957c478bd9Sstevel@tonic-gate if (function != NONE) 1967c478bd9Sstevel@tonic-gate errflg = 1; 1977c478bd9Sstevel@tonic-gate else 1987c478bd9Sstevel@tonic-gate function = UDPPING; 1997c478bd9Sstevel@tonic-gate break; 2007c478bd9Sstevel@tonic-gate 2017c478bd9Sstevel@tonic-gate case 'n': 2027c478bd9Sstevel@tonic-gate portnum = (ushort_t)strtol(optarg, &strptr, 10); 2037c478bd9Sstevel@tonic-gate if (strptr == optarg || *strptr != '\0') { 204*791dfaa7SVallish Vaidyeshwara (void) fprintf(stderr, 2057c478bd9Sstevel@tonic-gate "rpcinfo: %s is illegal port number\n", 2067c478bd9Sstevel@tonic-gate optarg); 2077c478bd9Sstevel@tonic-gate exit(1); 2087c478bd9Sstevel@tonic-gate } 2097c478bd9Sstevel@tonic-gate break; 2107c478bd9Sstevel@tonic-gate #endif 2117c478bd9Sstevel@tonic-gate case 'a': 2127c478bd9Sstevel@tonic-gate address = optarg; 2137c478bd9Sstevel@tonic-gate if (function != NONE) 2147c478bd9Sstevel@tonic-gate errflg = 1; 2157c478bd9Sstevel@tonic-gate else 2167c478bd9Sstevel@tonic-gate function = ADDRPING; 2177c478bd9Sstevel@tonic-gate break; 2187c478bd9Sstevel@tonic-gate case 'b': 2197c478bd9Sstevel@tonic-gate if (function != NONE) 2207c478bd9Sstevel@tonic-gate errflg = 1; 2217c478bd9Sstevel@tonic-gate else 2227c478bd9Sstevel@tonic-gate function = BROADCAST; 2237c478bd9Sstevel@tonic-gate break; 2247c478bd9Sstevel@tonic-gate 2257c478bd9Sstevel@tonic-gate case 'd': 2267c478bd9Sstevel@tonic-gate if (function != NONE) 2277c478bd9Sstevel@tonic-gate errflg = 1; 2287c478bd9Sstevel@tonic-gate else 2297c478bd9Sstevel@tonic-gate function = DELETES; 2307c478bd9Sstevel@tonic-gate break; 2317c478bd9Sstevel@tonic-gate 2327c478bd9Sstevel@tonic-gate case 'l': 2337c478bd9Sstevel@tonic-gate if (function != NONE) 2347c478bd9Sstevel@tonic-gate errflg = 1; 2357c478bd9Sstevel@tonic-gate else 2367c478bd9Sstevel@tonic-gate function = RPCBADDRLIST; 2377c478bd9Sstevel@tonic-gate break; 2387c478bd9Sstevel@tonic-gate 2397c478bd9Sstevel@tonic-gate case 'm': 2407c478bd9Sstevel@tonic-gate if (function != NONE) 2417c478bd9Sstevel@tonic-gate errflg = 1; 2427c478bd9Sstevel@tonic-gate else 2437c478bd9Sstevel@tonic-gate function = RPCBGETSTAT; 2447c478bd9Sstevel@tonic-gate break; 2457c478bd9Sstevel@tonic-gate 2467c478bd9Sstevel@tonic-gate case 's': 2477c478bd9Sstevel@tonic-gate if (function != NONE) 2487c478bd9Sstevel@tonic-gate errflg = 1; 2497c478bd9Sstevel@tonic-gate else 2507c478bd9Sstevel@tonic-gate function = RPCBDUMP_SHORT; 2517c478bd9Sstevel@tonic-gate break; 2527c478bd9Sstevel@tonic-gate 2537c478bd9Sstevel@tonic-gate case 'T': 2547c478bd9Sstevel@tonic-gate netid = optarg; 2557c478bd9Sstevel@tonic-gate break; 2567c478bd9Sstevel@tonic-gate case '?': 2577c478bd9Sstevel@tonic-gate errflg = 1; 2587c478bd9Sstevel@tonic-gate break; 2597c478bd9Sstevel@tonic-gate } 2607c478bd9Sstevel@tonic-gate } 2617c478bd9Sstevel@tonic-gate 2627c478bd9Sstevel@tonic-gate if (errflg || ((function == ADDRPING) && !netid)) { 2637c478bd9Sstevel@tonic-gate usage(); 2647c478bd9Sstevel@tonic-gate return (1); 2657c478bd9Sstevel@tonic-gate } 2667c478bd9Sstevel@tonic-gate if (netid == NULL) { /* user has not selected transport to use */ 2677c478bd9Sstevel@tonic-gate /* 2687c478bd9Sstevel@tonic-gate * See if a COTS loopback transport is available, in case we 2697c478bd9Sstevel@tonic-gate * will be talking to the local system. 2707c478bd9Sstevel@tonic-gate */ 2717c478bd9Sstevel@tonic-gate handle = setnetconfig(); 2727c478bd9Sstevel@tonic-gate while ((loopback_nconf = getnetconfig(handle)) != NULL) { 2737c478bd9Sstevel@tonic-gate if (strcmp(loopback_nconf->nc_protofmly, 2747c478bd9Sstevel@tonic-gate NC_LOOPBACK) == 0 && 2757c478bd9Sstevel@tonic-gate (loopback_nconf->nc_semantics == NC_TPI_COTS || 2767c478bd9Sstevel@tonic-gate loopback_nconf->nc_semantics == NC_TPI_COTS_ORD)) { 2777c478bd9Sstevel@tonic-gate loopback_netid = loopback_nconf->nc_netid; 2787c478bd9Sstevel@tonic-gate break; 2797c478bd9Sstevel@tonic-gate } 2807c478bd9Sstevel@tonic-gate } 2817c478bd9Sstevel@tonic-gate if (loopback_netid == NULL) { 282*791dfaa7SVallish Vaidyeshwara (void) endnetconfig(handle); 2837c478bd9Sstevel@tonic-gate } 2847c478bd9Sstevel@tonic-gate } 2857c478bd9Sstevel@tonic-gate if (function == NONE) { 2867c478bd9Sstevel@tonic-gate if (argc - optind > 1) 2877c478bd9Sstevel@tonic-gate function = PROGPING; 2887c478bd9Sstevel@tonic-gate else 2897c478bd9Sstevel@tonic-gate function = RPCBDUMP; 2907c478bd9Sstevel@tonic-gate } 2917c478bd9Sstevel@tonic-gate 2927c478bd9Sstevel@tonic-gate switch (function) { 2937c478bd9Sstevel@tonic-gate #ifdef PORTMAP 2947c478bd9Sstevel@tonic-gate case PMAPDUMP: 2957c478bd9Sstevel@tonic-gate if (portnum != 0) { 2967c478bd9Sstevel@tonic-gate usage(); 2977c478bd9Sstevel@tonic-gate return (1); 2987c478bd9Sstevel@tonic-gate } 2997c478bd9Sstevel@tonic-gate pmapdump(argc - optind, argv + optind); 3007c478bd9Sstevel@tonic-gate break; 3017c478bd9Sstevel@tonic-gate 3027c478bd9Sstevel@tonic-gate case UDPPING: 3037c478bd9Sstevel@tonic-gate ip_ping(portnum, "udp", argc - optind, argv + optind); 3047c478bd9Sstevel@tonic-gate break; 3057c478bd9Sstevel@tonic-gate 3067c478bd9Sstevel@tonic-gate case TCPPING: 3077c478bd9Sstevel@tonic-gate ip_ping(portnum, "tcp", argc - optind, argv + optind); 3087c478bd9Sstevel@tonic-gate break; 3097c478bd9Sstevel@tonic-gate #endif 3107c478bd9Sstevel@tonic-gate case BROADCAST: 3117c478bd9Sstevel@tonic-gate brdcst(argc - optind, argv + optind); 3127c478bd9Sstevel@tonic-gate break; 3137c478bd9Sstevel@tonic-gate case DELETES: 3147c478bd9Sstevel@tonic-gate deletereg(netid, argc - optind, argv + optind); 3157c478bd9Sstevel@tonic-gate break; 3167c478bd9Sstevel@tonic-gate case ADDRPING: 3177c478bd9Sstevel@tonic-gate addrping(address, netid, argc - optind, argv + optind); 3187c478bd9Sstevel@tonic-gate break; 3197c478bd9Sstevel@tonic-gate case PROGPING: 3207c478bd9Sstevel@tonic-gate progping(netid, argc - optind, argv + optind); 3217c478bd9Sstevel@tonic-gate break; 3227c478bd9Sstevel@tonic-gate case RPCBDUMP: 3237c478bd9Sstevel@tonic-gate case RPCBDUMP_SHORT: 3247c478bd9Sstevel@tonic-gate rpcbdump(function, netid, argc - optind, argv + optind); 3257c478bd9Sstevel@tonic-gate break; 3267c478bd9Sstevel@tonic-gate case RPCBGETSTAT: 3277c478bd9Sstevel@tonic-gate rpcbgetstat(argc - optind, argv + optind); 3287c478bd9Sstevel@tonic-gate break; 3297c478bd9Sstevel@tonic-gate case RPCBADDRLIST: 3307c478bd9Sstevel@tonic-gate rpcbaddrlist(netid, argc - optind, argv + optind); 3317c478bd9Sstevel@tonic-gate break; 3327c478bd9Sstevel@tonic-gate } 3337c478bd9Sstevel@tonic-gate return (0); 3347c478bd9Sstevel@tonic-gate } 3357c478bd9Sstevel@tonic-gate 3367c478bd9Sstevel@tonic-gate #ifdef PORTMAP 3377c478bd9Sstevel@tonic-gate static CLIENT * 3387c478bd9Sstevel@tonic-gate clnt_com_create(addr, prog, vers, fdp, trans) 3397c478bd9Sstevel@tonic-gate struct sockaddr_in *addr; 3407c478bd9Sstevel@tonic-gate ulong_t prog; 3417c478bd9Sstevel@tonic-gate ulong_t vers; 3427c478bd9Sstevel@tonic-gate int *fdp; 3437c478bd9Sstevel@tonic-gate char *trans; 3447c478bd9Sstevel@tonic-gate { 3457c478bd9Sstevel@tonic-gate CLIENT *clnt; 3467c478bd9Sstevel@tonic-gate 3477c478bd9Sstevel@tonic-gate if (strcmp(trans, "tcp") == 0) { 3487c478bd9Sstevel@tonic-gate clnt = clnttcp_create(addr, prog, vers, fdp, 0, 0); 3497c478bd9Sstevel@tonic-gate } else { 3507c478bd9Sstevel@tonic-gate struct timeval to; 3517c478bd9Sstevel@tonic-gate 3527c478bd9Sstevel@tonic-gate to.tv_sec = 5; 3537c478bd9Sstevel@tonic-gate to.tv_usec = 0; 3547c478bd9Sstevel@tonic-gate clnt = clntudp_create(addr, prog, vers, to, fdp); 3557c478bd9Sstevel@tonic-gate } 3567c478bd9Sstevel@tonic-gate if (clnt == (CLIENT *)NULL) { 3577c478bd9Sstevel@tonic-gate clnt_pcreateerror("rpcinfo"); 3587c478bd9Sstevel@tonic-gate if (vers == MIN_VERS) 359*791dfaa7SVallish Vaidyeshwara (void) printf("program %lu is not available\n", prog); 3607c478bd9Sstevel@tonic-gate else 361*791dfaa7SVallish Vaidyeshwara (void) printf( 362*791dfaa7SVallish Vaidyeshwara "program %lu version %lu is not available\n", 3637c478bd9Sstevel@tonic-gate prog, vers); 3647c478bd9Sstevel@tonic-gate exit(1); 3657c478bd9Sstevel@tonic-gate } 3667c478bd9Sstevel@tonic-gate return (clnt); 3677c478bd9Sstevel@tonic-gate } 3687c478bd9Sstevel@tonic-gate 3697c478bd9Sstevel@tonic-gate /* 3707c478bd9Sstevel@tonic-gate * If portnum is 0, then go and get the address from portmapper, which happens 3717c478bd9Sstevel@tonic-gate * transparently through clnt*_create(); If version number is not given, it 3727c478bd9Sstevel@tonic-gate * tries to find out the version number by making a call to version 0 and if 3737c478bd9Sstevel@tonic-gate * that fails, it obtains the high order and the low order version number. If 3747c478bd9Sstevel@tonic-gate * version 0 calls succeeds, it tries for MAXVERS call and repeats the same. 3757c478bd9Sstevel@tonic-gate */ 3767c478bd9Sstevel@tonic-gate static void 3777c478bd9Sstevel@tonic-gate ip_ping(portnum, trans, argc, argv) 3787c478bd9Sstevel@tonic-gate ushort_t portnum; 3797c478bd9Sstevel@tonic-gate char *trans; 3807c478bd9Sstevel@tonic-gate int argc; 3817c478bd9Sstevel@tonic-gate char **argv; 3827c478bd9Sstevel@tonic-gate { 3837c478bd9Sstevel@tonic-gate CLIENT *client; 3847c478bd9Sstevel@tonic-gate int fd = RPC_ANYFD; 3857c478bd9Sstevel@tonic-gate struct timeval to; 3867c478bd9Sstevel@tonic-gate struct sockaddr_in addr; 3877c478bd9Sstevel@tonic-gate enum clnt_stat rpc_stat; 3887c478bd9Sstevel@tonic-gate ulong_t prognum, vers, minvers, maxvers; 3897c478bd9Sstevel@tonic-gate struct rpc_err rpcerr; 3907c478bd9Sstevel@tonic-gate int failure = 0; 3917c478bd9Sstevel@tonic-gate 3927c478bd9Sstevel@tonic-gate if (argc < 2 || argc > 3) { 3937c478bd9Sstevel@tonic-gate usage(); 3947c478bd9Sstevel@tonic-gate exit(1); 3957c478bd9Sstevel@tonic-gate } 3967c478bd9Sstevel@tonic-gate to.tv_sec = 10; 3977c478bd9Sstevel@tonic-gate to.tv_usec = 0; 3987c478bd9Sstevel@tonic-gate prognum = getprognum(argv[1]); 3997c478bd9Sstevel@tonic-gate get_inet_address(&addr, argv[0]); 4007c478bd9Sstevel@tonic-gate if (argc == 2) { /* Version number not known */ 4017c478bd9Sstevel@tonic-gate /* 4027c478bd9Sstevel@tonic-gate * A call to version 0 should fail with a program/version 4037c478bd9Sstevel@tonic-gate * mismatch, and give us the range of versions supported. 4047c478bd9Sstevel@tonic-gate */ 4057c478bd9Sstevel@tonic-gate vers = MIN_VERS; 4067c478bd9Sstevel@tonic-gate } else { 4077c478bd9Sstevel@tonic-gate vers = getvers(argv[2]); 4087c478bd9Sstevel@tonic-gate } 4097c478bd9Sstevel@tonic-gate addr.sin_port = htons(portnum); 4107c478bd9Sstevel@tonic-gate client = clnt_com_create(&addr, prognum, vers, &fd, trans); 4117c478bd9Sstevel@tonic-gate rpc_stat = CLNT_CALL(client, NULLPROC, (xdrproc_t)xdr_void, 4127c478bd9Sstevel@tonic-gate (char *)NULL, (xdrproc_t)xdr_void, (char *)NULL, 4137c478bd9Sstevel@tonic-gate to); 4147c478bd9Sstevel@tonic-gate if (argc != 2) { 4157c478bd9Sstevel@tonic-gate /* Version number was known */ 4167c478bd9Sstevel@tonic-gate if (pstatus(client, prognum, vers) < 0) 4177c478bd9Sstevel@tonic-gate exit(1); 4187c478bd9Sstevel@tonic-gate (void) CLNT_DESTROY(client); 4197c478bd9Sstevel@tonic-gate return; 4207c478bd9Sstevel@tonic-gate } 4217c478bd9Sstevel@tonic-gate /* Version number not known */ 4227c478bd9Sstevel@tonic-gate (void) CLNT_CONTROL(client, CLSET_FD_NCLOSE, (char *)NULL); 4237c478bd9Sstevel@tonic-gate if (rpc_stat == RPC_PROGVERSMISMATCH) { 4247c478bd9Sstevel@tonic-gate clnt_geterr(client, &rpcerr); 4257c478bd9Sstevel@tonic-gate minvers = rpcerr.re_vers.low; 4267c478bd9Sstevel@tonic-gate maxvers = rpcerr.re_vers.high; 4277c478bd9Sstevel@tonic-gate } else if (rpc_stat == RPC_SUCCESS) { 4287c478bd9Sstevel@tonic-gate /* 4297c478bd9Sstevel@tonic-gate * Oh dear, it DOES support version 0. 4307c478bd9Sstevel@tonic-gate * Let's try version MAX_VERS. 4317c478bd9Sstevel@tonic-gate */ 4327c478bd9Sstevel@tonic-gate (void) CLNT_DESTROY(client); 4337c478bd9Sstevel@tonic-gate addr.sin_port = htons(portnum); 4347c478bd9Sstevel@tonic-gate client = clnt_com_create(&addr, prognum, MAX_VERS, &fd, trans); 4357c478bd9Sstevel@tonic-gate rpc_stat = CLNT_CALL(client, NULLPROC, (xdrproc_t)xdr_void, 4367c478bd9Sstevel@tonic-gate (char *)NULL, (xdrproc_t)xdr_void, 4377c478bd9Sstevel@tonic-gate (char *)NULL, to); 4387c478bd9Sstevel@tonic-gate if (rpc_stat == RPC_PROGVERSMISMATCH) { 4397c478bd9Sstevel@tonic-gate clnt_geterr(client, &rpcerr); 4407c478bd9Sstevel@tonic-gate minvers = rpcerr.re_vers.low; 4417c478bd9Sstevel@tonic-gate maxvers = rpcerr.re_vers.high; 4427c478bd9Sstevel@tonic-gate } else if (rpc_stat == RPC_SUCCESS) { 4437c478bd9Sstevel@tonic-gate /* 4447c478bd9Sstevel@tonic-gate * It also supports version MAX_VERS. 4457c478bd9Sstevel@tonic-gate * Looks like we have a wise guy. 4467c478bd9Sstevel@tonic-gate * OK, we give them information on all 4477c478bd9Sstevel@tonic-gate * 4 billion versions they support... 4487c478bd9Sstevel@tonic-gate */ 4497c478bd9Sstevel@tonic-gate minvers = 0; 4507c478bd9Sstevel@tonic-gate maxvers = MAX_VERS; 4517c478bd9Sstevel@tonic-gate } else { 4527c478bd9Sstevel@tonic-gate (void) pstatus(client, prognum, MAX_VERS); 4537c478bd9Sstevel@tonic-gate exit(1); 4547c478bd9Sstevel@tonic-gate } 4557c478bd9Sstevel@tonic-gate } else { 4567c478bd9Sstevel@tonic-gate (void) pstatus(client, prognum, (ulong_t)0); 4577c478bd9Sstevel@tonic-gate exit(1); 4587c478bd9Sstevel@tonic-gate } 4597c478bd9Sstevel@tonic-gate (void) CLNT_DESTROY(client); 4607c478bd9Sstevel@tonic-gate for (vers = minvers; vers <= maxvers; vers++) { 4617c478bd9Sstevel@tonic-gate addr.sin_port = htons(portnum); 4627c478bd9Sstevel@tonic-gate client = clnt_com_create(&addr, prognum, vers, &fd, trans); 4637c478bd9Sstevel@tonic-gate rpc_stat = CLNT_CALL(client, NULLPROC, (xdrproc_t)xdr_void, 4647c478bd9Sstevel@tonic-gate (char *)NULL, (xdrproc_t)xdr_void, 4657c478bd9Sstevel@tonic-gate (char *)NULL, to); 4667c478bd9Sstevel@tonic-gate if (pstatus(client, prognum, vers) < 0) 4677c478bd9Sstevel@tonic-gate failure = 1; 4687c478bd9Sstevel@tonic-gate (void) CLNT_DESTROY(client); 4697c478bd9Sstevel@tonic-gate } 4707c478bd9Sstevel@tonic-gate if (failure) 4717c478bd9Sstevel@tonic-gate exit(1); 4727c478bd9Sstevel@tonic-gate (void) t_close(fd); 4737c478bd9Sstevel@tonic-gate } 4747c478bd9Sstevel@tonic-gate 4757c478bd9Sstevel@tonic-gate /* 4767c478bd9Sstevel@tonic-gate * Dump all the portmapper registerations 4777c478bd9Sstevel@tonic-gate */ 4787c478bd9Sstevel@tonic-gate static void 4797c478bd9Sstevel@tonic-gate pmapdump(argc, argv) 4807c478bd9Sstevel@tonic-gate int argc; 4817c478bd9Sstevel@tonic-gate char **argv; 4827c478bd9Sstevel@tonic-gate { 4837c478bd9Sstevel@tonic-gate struct sockaddr_in server_addr; 4847c478bd9Sstevel@tonic-gate pmaplist_ptr head = NULL; 4857c478bd9Sstevel@tonic-gate int socket = RPC_ANYSOCK; 4867c478bd9Sstevel@tonic-gate struct timeval minutetimeout; 4877c478bd9Sstevel@tonic-gate register CLIENT *client; 4887c478bd9Sstevel@tonic-gate struct rpcent *rpc; 4897c478bd9Sstevel@tonic-gate enum clnt_stat clnt_st; 4907c478bd9Sstevel@tonic-gate struct rpc_err err; 4917c478bd9Sstevel@tonic-gate struct utsname utsname; 4927c478bd9Sstevel@tonic-gate char *host; 4937c478bd9Sstevel@tonic-gate 4947c478bd9Sstevel@tonic-gate if (argc > 1) { 4957c478bd9Sstevel@tonic-gate usage(); 4967c478bd9Sstevel@tonic-gate exit(1); 4977c478bd9Sstevel@tonic-gate } 4987c478bd9Sstevel@tonic-gate if (argc == 1) { 4997c478bd9Sstevel@tonic-gate host = argv[0]; 5007c478bd9Sstevel@tonic-gate get_inet_address(&server_addr, host); 5017c478bd9Sstevel@tonic-gate } else { 502*791dfaa7SVallish Vaidyeshwara (void) uname(&utsname); 5037c478bd9Sstevel@tonic-gate host = utsname.nodename; 5047c478bd9Sstevel@tonic-gate get_inet_address(&server_addr, host); 5057c478bd9Sstevel@tonic-gate } 5067c478bd9Sstevel@tonic-gate minutetimeout.tv_sec = 60; 5077c478bd9Sstevel@tonic-gate minutetimeout.tv_usec = 0; 5087c478bd9Sstevel@tonic-gate server_addr.sin_port = htons(PMAPPORT); 5097c478bd9Sstevel@tonic-gate if ((client = clnttcp_create(&server_addr, PMAPPROG, 5107c478bd9Sstevel@tonic-gate PMAPVERS, &socket, 50, 500)) == NULL) { 5117c478bd9Sstevel@tonic-gate if (rpc_createerr.cf_stat == RPC_TLIERROR) { 5127c478bd9Sstevel@tonic-gate /* 5137c478bd9Sstevel@tonic-gate * "Misc. TLI error" is not too helpful. Most likely 5147c478bd9Sstevel@tonic-gate * the connection to the remote server timed out, so 5157c478bd9Sstevel@tonic-gate * this error is at least less perplexing. 5167c478bd9Sstevel@tonic-gate */ 5177c478bd9Sstevel@tonic-gate rpc_createerr.cf_stat = RPC_PMAPFAILURE; 5187c478bd9Sstevel@tonic-gate rpc_createerr.cf_error.re_status = RPC_FAILED; 5197c478bd9Sstevel@tonic-gate } 5207c478bd9Sstevel@tonic-gate clnt_pcreateerror("rpcinfo: can't contact portmapper"); 5217c478bd9Sstevel@tonic-gate exit(1); 5227c478bd9Sstevel@tonic-gate } 5237c478bd9Sstevel@tonic-gate clnt_st = CLNT_CALL(client, PMAPPROC_DUMP, (xdrproc_t)xdr_void, 5247c478bd9Sstevel@tonic-gate NULL, (xdrproc_t)xdr_pmaplist_ptr, (char *)&head, 5257c478bd9Sstevel@tonic-gate minutetimeout); 5267c478bd9Sstevel@tonic-gate if (clnt_st != RPC_SUCCESS) { 5277c478bd9Sstevel@tonic-gate if ((clnt_st == RPC_PROGVERSMISMATCH) || 5287c478bd9Sstevel@tonic-gate (clnt_st == RPC_PROGUNAVAIL)) { 5297c478bd9Sstevel@tonic-gate CLNT_GETERR(client, &err); 5307c478bd9Sstevel@tonic-gate if (err.re_vers.low > PMAPVERS) 531*791dfaa7SVallish Vaidyeshwara (void) fprintf(stderr, 5327c478bd9Sstevel@tonic-gate "%s does not support portmapper. Try rpcinfo %s instead\n", 5337c478bd9Sstevel@tonic-gate host, host); 5347c478bd9Sstevel@tonic-gate exit(1); 5357c478bd9Sstevel@tonic-gate } 5367c478bd9Sstevel@tonic-gate clnt_perror(client, "rpcinfo: can't contact portmapper"); 5377c478bd9Sstevel@tonic-gate exit(1); 5387c478bd9Sstevel@tonic-gate } 5397c478bd9Sstevel@tonic-gate if (head == NULL) { 540*791dfaa7SVallish Vaidyeshwara (void) printf("No remote programs registered.\n"); 5417c478bd9Sstevel@tonic-gate } else { 542*791dfaa7SVallish Vaidyeshwara (void) printf(" program vers proto port service\n"); 5437c478bd9Sstevel@tonic-gate for (; head != NULL; head = head->pml_next) { 544*791dfaa7SVallish Vaidyeshwara (void) printf("%10ld%5ld", 5457c478bd9Sstevel@tonic-gate head->pml_map.pm_prog, 5467c478bd9Sstevel@tonic-gate head->pml_map.pm_vers); 5477c478bd9Sstevel@tonic-gate if (head->pml_map.pm_prot == IPPROTO_UDP) 548*791dfaa7SVallish Vaidyeshwara (void) printf("%6s", "udp"); 5497c478bd9Sstevel@tonic-gate else if (head->pml_map.pm_prot == IPPROTO_TCP) 550*791dfaa7SVallish Vaidyeshwara (void) printf("%6s", "tcp"); 5517c478bd9Sstevel@tonic-gate else 552*791dfaa7SVallish Vaidyeshwara (void) printf("%6ld", head->pml_map.pm_prot); 553*791dfaa7SVallish Vaidyeshwara (void) printf("%7ld", head->pml_map.pm_port); 5547c478bd9Sstevel@tonic-gate rpc = getrpcbynumber(head->pml_map.pm_prog); 5557c478bd9Sstevel@tonic-gate if (rpc) 556*791dfaa7SVallish Vaidyeshwara (void) printf(" %s\n", rpc->r_name); 5577c478bd9Sstevel@tonic-gate else 558*791dfaa7SVallish Vaidyeshwara (void) printf("\n"); 5597c478bd9Sstevel@tonic-gate } 5607c478bd9Sstevel@tonic-gate } 5617c478bd9Sstevel@tonic-gate } 5627c478bd9Sstevel@tonic-gate 5637c478bd9Sstevel@tonic-gate static void 5647c478bd9Sstevel@tonic-gate get_inet_address(addr, host) 5657c478bd9Sstevel@tonic-gate struct sockaddr_in *addr; 5667c478bd9Sstevel@tonic-gate char *host; 5677c478bd9Sstevel@tonic-gate { 5687c478bd9Sstevel@tonic-gate struct netconfig *nconf; 5697c478bd9Sstevel@tonic-gate struct nd_hostserv service; 5707c478bd9Sstevel@tonic-gate struct nd_addrlist *naddrs; 5717c478bd9Sstevel@tonic-gate 5727c478bd9Sstevel@tonic-gate (void) memset((char *)addr, 0, sizeof (*addr)); 5737c478bd9Sstevel@tonic-gate addr->sin_addr.s_addr = inet_addr(host); 574*791dfaa7SVallish Vaidyeshwara if (addr->sin_addr.s_addr == (uint32_t)-1 || 575*791dfaa7SVallish Vaidyeshwara addr->sin_addr.s_addr == 0) { 5767c478bd9Sstevel@tonic-gate if ((nconf = __rpc_getconfip("udp")) == NULL && 5777c478bd9Sstevel@tonic-gate (nconf = __rpc_getconfip("tcp")) == NULL) { 578*791dfaa7SVallish Vaidyeshwara (void) fprintf(stderr, 5797c478bd9Sstevel@tonic-gate "rpcinfo: couldn't find a suitable transport\n"); 5807c478bd9Sstevel@tonic-gate exit(1); 5817c478bd9Sstevel@tonic-gate } else { 5827c478bd9Sstevel@tonic-gate service.h_host = host; 5837c478bd9Sstevel@tonic-gate service.h_serv = "rpcbind"; 5847c478bd9Sstevel@tonic-gate if (netdir_getbyname(nconf, &service, &naddrs)) { 585*791dfaa7SVallish Vaidyeshwara (void) fprintf(stderr, "rpcinfo: %s: %s\n", 5867c478bd9Sstevel@tonic-gate host, netdir_sperror()); 5877c478bd9Sstevel@tonic-gate exit(1); 5887c478bd9Sstevel@tonic-gate } else { 5897c478bd9Sstevel@tonic-gate (void) memcpy((caddr_t)addr, 5907c478bd9Sstevel@tonic-gate naddrs->n_addrs->buf, naddrs->n_addrs->len); 5917c478bd9Sstevel@tonic-gate (void) netdir_free((char *)naddrs, ND_ADDRLIST); 5927c478bd9Sstevel@tonic-gate } 5937c478bd9Sstevel@tonic-gate (void) freenetconfigent(nconf); 5947c478bd9Sstevel@tonic-gate } 5957c478bd9Sstevel@tonic-gate } else { 5967c478bd9Sstevel@tonic-gate addr->sin_family = AF_INET; 5977c478bd9Sstevel@tonic-gate } 5987c478bd9Sstevel@tonic-gate } 5997c478bd9Sstevel@tonic-gate #endif /* PORTMAP */ 6007c478bd9Sstevel@tonic-gate 6017c478bd9Sstevel@tonic-gate /* 6027c478bd9Sstevel@tonic-gate * reply_proc collects replies from the broadcast. 6037c478bd9Sstevel@tonic-gate * to get a unique list of responses the output of rpcinfo should 6047c478bd9Sstevel@tonic-gate * be piped through sort(1) and then uniq(1). 6057c478bd9Sstevel@tonic-gate */ 6067c478bd9Sstevel@tonic-gate 6077c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 6087c478bd9Sstevel@tonic-gate static bool_t 6097c478bd9Sstevel@tonic-gate reply_proc(res, who, nconf) 6107c478bd9Sstevel@tonic-gate void *res; /* Nothing comes back */ 6117c478bd9Sstevel@tonic-gate struct netbuf *who; /* Who sent us the reply */ 6127c478bd9Sstevel@tonic-gate struct netconfig *nconf; /* On which transport the reply came */ 6137c478bd9Sstevel@tonic-gate { 6147c478bd9Sstevel@tonic-gate struct nd_hostservlist *serv; 6157c478bd9Sstevel@tonic-gate char *uaddr; 6167c478bd9Sstevel@tonic-gate char *hostname; 6177c478bd9Sstevel@tonic-gate 6187c478bd9Sstevel@tonic-gate if (netdir_getbyaddr(nconf, &serv, who)) { 6197c478bd9Sstevel@tonic-gate hostname = UNKNOWN; 6207c478bd9Sstevel@tonic-gate } else { 6217c478bd9Sstevel@tonic-gate hostname = serv->h_hostservs->h_host; 6227c478bd9Sstevel@tonic-gate } 6237c478bd9Sstevel@tonic-gate if (!(uaddr = taddr2uaddr(nconf, who))) { 6247c478bd9Sstevel@tonic-gate uaddr = UNKNOWN; 6257c478bd9Sstevel@tonic-gate } 626*791dfaa7SVallish Vaidyeshwara (void) printf("%s\t%s\n", uaddr, hostname); 6277c478bd9Sstevel@tonic-gate if (strcmp(hostname, UNKNOWN)) 6287c478bd9Sstevel@tonic-gate netdir_free((char *)serv, ND_HOSTSERVLIST); 6297c478bd9Sstevel@tonic-gate if (strcmp(uaddr, UNKNOWN)) 6307c478bd9Sstevel@tonic-gate free((char *)uaddr); 6317c478bd9Sstevel@tonic-gate return (FALSE); 6327c478bd9Sstevel@tonic-gate } 6337c478bd9Sstevel@tonic-gate 6347c478bd9Sstevel@tonic-gate static void 6357c478bd9Sstevel@tonic-gate brdcst(argc, argv) 6367c478bd9Sstevel@tonic-gate int argc; 6377c478bd9Sstevel@tonic-gate char **argv; 6387c478bd9Sstevel@tonic-gate { 6397c478bd9Sstevel@tonic-gate enum clnt_stat rpc_stat; 6407c478bd9Sstevel@tonic-gate ulong_t prognum, vers; 6417c478bd9Sstevel@tonic-gate 6427c478bd9Sstevel@tonic-gate if (argc != 2) { 6437c478bd9Sstevel@tonic-gate usage(); 6447c478bd9Sstevel@tonic-gate exit(1); 6457c478bd9Sstevel@tonic-gate } 6467c478bd9Sstevel@tonic-gate prognum = getprognum(argv[0]); 6477c478bd9Sstevel@tonic-gate vers = getvers(argv[1]); 6487c478bd9Sstevel@tonic-gate rpc_stat = rpc_broadcast(prognum, vers, NULLPROC, 6497c478bd9Sstevel@tonic-gate (xdrproc_t)xdr_void, (char *)NULL, (xdrproc_t)xdr_void, 6507c478bd9Sstevel@tonic-gate (char *)NULL, (resultproc_t)reply_proc, NULL); 6517c478bd9Sstevel@tonic-gate if ((rpc_stat != RPC_SUCCESS) && (rpc_stat != RPC_TIMEDOUT)) { 652*791dfaa7SVallish Vaidyeshwara (void) fprintf(stderr, "rpcinfo: broadcast failed: %s\n", 6537c478bd9Sstevel@tonic-gate clnt_sperrno(rpc_stat)); 6547c478bd9Sstevel@tonic-gate exit(1); 6557c478bd9Sstevel@tonic-gate } 6567c478bd9Sstevel@tonic-gate exit(0); 6577c478bd9Sstevel@tonic-gate } 6587c478bd9Sstevel@tonic-gate 6597c478bd9Sstevel@tonic-gate static bool_t 6607c478bd9Sstevel@tonic-gate add_version(rs, vers) 6617c478bd9Sstevel@tonic-gate struct rpcbdump_short *rs; 6627c478bd9Sstevel@tonic-gate ulong_t vers; 6637c478bd9Sstevel@tonic-gate { 6647c478bd9Sstevel@tonic-gate struct verslist *vl; 6657c478bd9Sstevel@tonic-gate 6667c478bd9Sstevel@tonic-gate for (vl = rs->vlist; vl; vl = vl->next) 6677c478bd9Sstevel@tonic-gate if (vl->vers == vers) 6687c478bd9Sstevel@tonic-gate break; 6697c478bd9Sstevel@tonic-gate if (vl) 6707c478bd9Sstevel@tonic-gate return (TRUE); 6717c478bd9Sstevel@tonic-gate vl = (struct verslist *)malloc(sizeof (struct verslist)); 6727c478bd9Sstevel@tonic-gate if (vl == NULL) 6737c478bd9Sstevel@tonic-gate return (FALSE); 6747c478bd9Sstevel@tonic-gate vl->vers = vers; 6757c478bd9Sstevel@tonic-gate vl->next = rs->vlist; 6767c478bd9Sstevel@tonic-gate rs->vlist = vl; 6777c478bd9Sstevel@tonic-gate return (TRUE); 6787c478bd9Sstevel@tonic-gate } 6797c478bd9Sstevel@tonic-gate 6807c478bd9Sstevel@tonic-gate static bool_t 6817c478bd9Sstevel@tonic-gate add_netid(rs, netid) 6827c478bd9Sstevel@tonic-gate struct rpcbdump_short *rs; 6837c478bd9Sstevel@tonic-gate char *netid; 6847c478bd9Sstevel@tonic-gate { 6857c478bd9Sstevel@tonic-gate struct netidlist *nl; 6867c478bd9Sstevel@tonic-gate 6877c478bd9Sstevel@tonic-gate for (nl = rs->nlist; nl; nl = nl->next) 6887c478bd9Sstevel@tonic-gate if (strcmp(nl->netid, netid) == 0) 6897c478bd9Sstevel@tonic-gate break; 6907c478bd9Sstevel@tonic-gate if (nl) 6917c478bd9Sstevel@tonic-gate return (TRUE); 6927c478bd9Sstevel@tonic-gate nl = (struct netidlist *)malloc(sizeof (struct netidlist)); 6937c478bd9Sstevel@tonic-gate if (nl == NULL) 6947c478bd9Sstevel@tonic-gate return (FALSE); 6957c478bd9Sstevel@tonic-gate nl->netid = netid; 6967c478bd9Sstevel@tonic-gate nl->next = rs->nlist; 6977c478bd9Sstevel@tonic-gate rs->nlist = nl; 6987c478bd9Sstevel@tonic-gate return (TRUE); 6997c478bd9Sstevel@tonic-gate } 7007c478bd9Sstevel@tonic-gate 7017c478bd9Sstevel@tonic-gate static void 7027c478bd9Sstevel@tonic-gate rpcbdump(dumptype, netid, argc, argv) 7037c478bd9Sstevel@tonic-gate int dumptype; 7047c478bd9Sstevel@tonic-gate char *netid; 7057c478bd9Sstevel@tonic-gate int argc; 7067c478bd9Sstevel@tonic-gate char **argv; 7077c478bd9Sstevel@tonic-gate { 7087c478bd9Sstevel@tonic-gate rpcblist_ptr head = NULL; 7097c478bd9Sstevel@tonic-gate struct timeval minutetimeout; 7107c478bd9Sstevel@tonic-gate register CLIENT *client; 7117c478bd9Sstevel@tonic-gate struct rpcent *rpc; 7127c478bd9Sstevel@tonic-gate char *host; 7137c478bd9Sstevel@tonic-gate struct netidlist *nl; 7147c478bd9Sstevel@tonic-gate struct verslist *vl; 7157c478bd9Sstevel@tonic-gate struct rpcbdump_short *rs, *rs_tail; 7167c478bd9Sstevel@tonic-gate enum clnt_stat clnt_st; 7177c478bd9Sstevel@tonic-gate struct rpc_err err; 7187c478bd9Sstevel@tonic-gate struct utsname utsname; 7197c478bd9Sstevel@tonic-gate struct rpcbdump_short *rs_head = NULL; 7207c478bd9Sstevel@tonic-gate 7217c478bd9Sstevel@tonic-gate if (argc > 1) { 7227c478bd9Sstevel@tonic-gate usage(); 7237c478bd9Sstevel@tonic-gate exit(1); 7247c478bd9Sstevel@tonic-gate } 7257c478bd9Sstevel@tonic-gate if (argc == 1) { 7267c478bd9Sstevel@tonic-gate host = argv[0]; 7277c478bd9Sstevel@tonic-gate } else { 728*791dfaa7SVallish Vaidyeshwara (void) uname(&utsname); 7297c478bd9Sstevel@tonic-gate host = utsname.nodename; 7307c478bd9Sstevel@tonic-gate } 7317c478bd9Sstevel@tonic-gate if (netid == NULL) { 7327c478bd9Sstevel@tonic-gate if (loopback_netid == NULL) { 7337c478bd9Sstevel@tonic-gate client = clnt_rpcbind_create(host, RPCBVERS, NULL); 7347c478bd9Sstevel@tonic-gate } else { 7357c478bd9Sstevel@tonic-gate client = getclnthandle(host, loopback_nconf, RPCBVERS, NULL); 7367c478bd9Sstevel@tonic-gate if (client == NULL && rpc_createerr.cf_stat == 7377c478bd9Sstevel@tonic-gate RPC_N2AXLATEFAILURE) { 7387c478bd9Sstevel@tonic-gate client = clnt_rpcbind_create(host, RPCBVERS, NULL); 7397c478bd9Sstevel@tonic-gate } 7407c478bd9Sstevel@tonic-gate } 7417c478bd9Sstevel@tonic-gate } else { 7427c478bd9Sstevel@tonic-gate struct netconfig *nconf; 7437c478bd9Sstevel@tonic-gate 7447c478bd9Sstevel@tonic-gate nconf = getnetconfigent(netid); 7457c478bd9Sstevel@tonic-gate if (nconf == NULL) { 7467c478bd9Sstevel@tonic-gate nc_perror("rpcinfo: invalid transport"); 7477c478bd9Sstevel@tonic-gate exit(1); 7487c478bd9Sstevel@tonic-gate } 7497c478bd9Sstevel@tonic-gate client = getclnthandle(host, nconf, RPCBVERS, NULL); 7507c478bd9Sstevel@tonic-gate if (nconf) 7517c478bd9Sstevel@tonic-gate (void) freenetconfigent(nconf); 7527c478bd9Sstevel@tonic-gate } 7537c478bd9Sstevel@tonic-gate if (client == (CLIENT *)NULL) { 7547c478bd9Sstevel@tonic-gate clnt_pcreateerror("rpcinfo: can't contact rpcbind"); 7557c478bd9Sstevel@tonic-gate exit(1); 7567c478bd9Sstevel@tonic-gate } 7577c478bd9Sstevel@tonic-gate minutetimeout.tv_sec = 60; 7587c478bd9Sstevel@tonic-gate minutetimeout.tv_usec = 0; 7597c478bd9Sstevel@tonic-gate clnt_st = CLNT_CALL(client, RPCBPROC_DUMP, (xdrproc_t)xdr_void, 7607c478bd9Sstevel@tonic-gate NULL, (xdrproc_t)xdr_rpcblist_ptr, (char *)&head, 7617c478bd9Sstevel@tonic-gate minutetimeout); 7627c478bd9Sstevel@tonic-gate if (clnt_st != RPC_SUCCESS) { 7637c478bd9Sstevel@tonic-gate if ((clnt_st == RPC_PROGVERSMISMATCH) || 7647c478bd9Sstevel@tonic-gate (clnt_st == RPC_PROGUNAVAIL)) { 7657c478bd9Sstevel@tonic-gate int vers; 7667c478bd9Sstevel@tonic-gate 7677c478bd9Sstevel@tonic-gate CLNT_GETERR(client, &err); 7687c478bd9Sstevel@tonic-gate if (err.re_vers.low == RPCBVERS4) { 7697c478bd9Sstevel@tonic-gate vers = RPCBVERS4; 7707c478bd9Sstevel@tonic-gate clnt_control(client, CLSET_VERS, (char *)&vers); 7717c478bd9Sstevel@tonic-gate clnt_st = CLNT_CALL(client, RPCBPROC_DUMP, 7727c478bd9Sstevel@tonic-gate (xdrproc_t)xdr_void, NULL, 7737c478bd9Sstevel@tonic-gate (xdrproc_t)xdr_rpcblist_ptr, (char *)&head, 7747c478bd9Sstevel@tonic-gate minutetimeout); 7757c478bd9Sstevel@tonic-gate if (clnt_st != RPC_SUCCESS) 7767c478bd9Sstevel@tonic-gate goto failed; 7777c478bd9Sstevel@tonic-gate } else { 7787c478bd9Sstevel@tonic-gate if (err.re_vers.high == PMAPVERS) { 7797c478bd9Sstevel@tonic-gate int high, low; 7807c478bd9Sstevel@tonic-gate pmaplist_ptr pmaphead = NULL; 781*791dfaa7SVallish Vaidyeshwara rpcblist_ptr list, prev = NULL; 7827c478bd9Sstevel@tonic-gate 7837c478bd9Sstevel@tonic-gate vers = PMAPVERS; 7847c478bd9Sstevel@tonic-gate clnt_control(client, CLSET_VERS, (char *)&vers); 7857c478bd9Sstevel@tonic-gate clnt_st = CLNT_CALL(client, PMAPPROC_DUMP, 7867c478bd9Sstevel@tonic-gate (xdrproc_t)xdr_void, NULL, 7877c478bd9Sstevel@tonic-gate (xdrproc_t)xdr_pmaplist_ptr, 7887c478bd9Sstevel@tonic-gate (char *)&pmaphead, minutetimeout); 7897c478bd9Sstevel@tonic-gate if (clnt_st != RPC_SUCCESS) 7907c478bd9Sstevel@tonic-gate goto failed; 7917c478bd9Sstevel@tonic-gate /* 7927c478bd9Sstevel@tonic-gate * convert to rpcblist_ptr format 7937c478bd9Sstevel@tonic-gate */ 7947c478bd9Sstevel@tonic-gate for (head = NULL; pmaphead != NULL; 7957c478bd9Sstevel@tonic-gate pmaphead = pmaphead->pml_next) { 7967c478bd9Sstevel@tonic-gate list = (rpcblist *)malloc(sizeof (rpcblist)); 7977c478bd9Sstevel@tonic-gate if (list == NULL) 7987c478bd9Sstevel@tonic-gate goto error; 7997c478bd9Sstevel@tonic-gate if (head == NULL) 8007c478bd9Sstevel@tonic-gate head = list; 8017c478bd9Sstevel@tonic-gate else 8027c478bd9Sstevel@tonic-gate prev->rpcb_next = (rpcblist_ptr) list; 8037c478bd9Sstevel@tonic-gate 8047c478bd9Sstevel@tonic-gate list->rpcb_next = NULL; 8057c478bd9Sstevel@tonic-gate list->rpcb_map.r_prog = pmaphead->pml_map.pm_prog; 8067c478bd9Sstevel@tonic-gate list->rpcb_map.r_vers = pmaphead->pml_map.pm_vers; 8077c478bd9Sstevel@tonic-gate if (pmaphead->pml_map.pm_prot == IPPROTO_UDP) 8087c478bd9Sstevel@tonic-gate list->rpcb_map.r_netid = "udp"; 8097c478bd9Sstevel@tonic-gate else if (pmaphead->pml_map.pm_prot == IPPROTO_TCP) 8107c478bd9Sstevel@tonic-gate list->rpcb_map.r_netid = "tcp"; 8117c478bd9Sstevel@tonic-gate else { 8127c478bd9Sstevel@tonic-gate #define MAXLONG_AS_STRING "2147483648" 8137c478bd9Sstevel@tonic-gate list->rpcb_map.r_netid = 8147c478bd9Sstevel@tonic-gate malloc(strlen(MAXLONG_AS_STRING) + 1); 8157c478bd9Sstevel@tonic-gate if (list->rpcb_map.r_netid == NULL) 8167c478bd9Sstevel@tonic-gate goto error; 817*791dfaa7SVallish Vaidyeshwara (void) sprintf(list->rpcb_map.r_netid, "%6ld", 8187c478bd9Sstevel@tonic-gate pmaphead->pml_map.pm_prot); 8197c478bd9Sstevel@tonic-gate } 8207c478bd9Sstevel@tonic-gate list->rpcb_map.r_owner = UNKNOWN; 8217c478bd9Sstevel@tonic-gate low = pmaphead->pml_map.pm_port & 0xff; 8227c478bd9Sstevel@tonic-gate high = (pmaphead->pml_map.pm_port >> 8) & 0xff; 8237c478bd9Sstevel@tonic-gate list->rpcb_map.r_addr = strdup("0.0.0.0.XXX.XXX"); 824*791dfaa7SVallish Vaidyeshwara (void) sprintf(&list->rpcb_map.r_addr[8], "%d.%d", 8257c478bd9Sstevel@tonic-gate high, low); 8267c478bd9Sstevel@tonic-gate prev = list; 8277c478bd9Sstevel@tonic-gate } 8287c478bd9Sstevel@tonic-gate } 8297c478bd9Sstevel@tonic-gate } 8307c478bd9Sstevel@tonic-gate } else { /* any other error */ 8317c478bd9Sstevel@tonic-gate failed: 8327c478bd9Sstevel@tonic-gate clnt_perror(client, "rpcinfo: can't contact rpcbind: "); 8337c478bd9Sstevel@tonic-gate exit(1); 8347c478bd9Sstevel@tonic-gate } 8357c478bd9Sstevel@tonic-gate } 8367c478bd9Sstevel@tonic-gate if (head == NULL) { 837*791dfaa7SVallish Vaidyeshwara (void) printf("No remote programs registered.\n"); 8387c478bd9Sstevel@tonic-gate } else if (dumptype == RPCBDUMP) { 839*791dfaa7SVallish Vaidyeshwara (void) printf( 8407c478bd9Sstevel@tonic-gate " program version netid address service owner\n"); 8417c478bd9Sstevel@tonic-gate for (; head != NULL; head = head->rpcb_next) { 842*791dfaa7SVallish Vaidyeshwara (void) printf("%10ld%5ld ", 8437c478bd9Sstevel@tonic-gate head->rpcb_map.r_prog, head->rpcb_map.r_vers); 844*791dfaa7SVallish Vaidyeshwara (void) printf("%-9s ", head->rpcb_map.r_netid); 845*791dfaa7SVallish Vaidyeshwara (void) printf("%-19s", head->rpcb_map.r_addr); 8467c478bd9Sstevel@tonic-gate rpc = getrpcbynumber(head->rpcb_map.r_prog); 8477c478bd9Sstevel@tonic-gate if (rpc) 848*791dfaa7SVallish Vaidyeshwara (void) printf(" %-10s", rpc->r_name); 8497c478bd9Sstevel@tonic-gate else 850*791dfaa7SVallish Vaidyeshwara (void) printf(" %-10s", "-"); 851*791dfaa7SVallish Vaidyeshwara (void) printf(" %s\n", head->rpcb_map.r_owner); 8527c478bd9Sstevel@tonic-gate } 8537c478bd9Sstevel@tonic-gate } else if (dumptype == RPCBDUMP_SHORT) { 8547c478bd9Sstevel@tonic-gate for (; head != NULL; head = head->rpcb_next) { 8557c478bd9Sstevel@tonic-gate for (rs = rs_head; rs; rs = rs->next) 8567c478bd9Sstevel@tonic-gate if (head->rpcb_map.r_prog == rs->prog) 8577c478bd9Sstevel@tonic-gate break; 8587c478bd9Sstevel@tonic-gate if (rs == NULL) { 8597c478bd9Sstevel@tonic-gate rs = (struct rpcbdump_short *) 8607c478bd9Sstevel@tonic-gate malloc(sizeof (struct rpcbdump_short)); 8617c478bd9Sstevel@tonic-gate if (rs == NULL) 8627c478bd9Sstevel@tonic-gate goto error; 8637c478bd9Sstevel@tonic-gate rs->next = NULL; 8647c478bd9Sstevel@tonic-gate if (rs_head == NULL) { 8657c478bd9Sstevel@tonic-gate rs_head = rs; 8667c478bd9Sstevel@tonic-gate rs_tail = rs; 8677c478bd9Sstevel@tonic-gate } else { 8687c478bd9Sstevel@tonic-gate rs_tail->next = rs; 8697c478bd9Sstevel@tonic-gate rs_tail = rs; 8707c478bd9Sstevel@tonic-gate } 8717c478bd9Sstevel@tonic-gate rs->prog = head->rpcb_map.r_prog; 8727c478bd9Sstevel@tonic-gate rs->owner = head->rpcb_map.r_owner; 8737c478bd9Sstevel@tonic-gate rs->nlist = NULL; 8747c478bd9Sstevel@tonic-gate rs->vlist = NULL; 8757c478bd9Sstevel@tonic-gate } 8767c478bd9Sstevel@tonic-gate if (add_version(rs, head->rpcb_map.r_vers) == FALSE) 8777c478bd9Sstevel@tonic-gate goto error; 8787c478bd9Sstevel@tonic-gate if (add_netid(rs, head->rpcb_map.r_netid) == FALSE) 8797c478bd9Sstevel@tonic-gate goto error; 8807c478bd9Sstevel@tonic-gate } 881*791dfaa7SVallish Vaidyeshwara (void) printf( 8827c478bd9Sstevel@tonic-gate " program version(s) netid(s) service owner\n"); 8837c478bd9Sstevel@tonic-gate for (rs = rs_head; rs; rs = rs->next) { 884*791dfaa7SVallish Vaidyeshwara int bytes_trans = 0; 885*791dfaa7SVallish Vaidyeshwara int len; 8867c478bd9Sstevel@tonic-gate 887*791dfaa7SVallish Vaidyeshwara (void) printf("%10ld ", rs->prog); 8887c478bd9Sstevel@tonic-gate for (vl = rs->vlist; vl; vl = vl->next) { 889*791dfaa7SVallish Vaidyeshwara bytes_trans += (len = printf("%d", vl->vers)) 890*791dfaa7SVallish Vaidyeshwara < 0 ? 0 : len; 8917c478bd9Sstevel@tonic-gate if (vl->next) 892*791dfaa7SVallish Vaidyeshwara bytes_trans += (len = printf(",")) < 0 893*791dfaa7SVallish Vaidyeshwara ? 0 : len; 8947c478bd9Sstevel@tonic-gate } 895*791dfaa7SVallish Vaidyeshwara /* 896*791dfaa7SVallish Vaidyeshwara * If number of bytes transferred is less than 10, 897*791dfaa7SVallish Vaidyeshwara * align 10 bytes for version(s) column. If bytes 898*791dfaa7SVallish Vaidyeshwara * transferred is more than 10, add a trailing white 899*791dfaa7SVallish Vaidyeshwara * space. 900*791dfaa7SVallish Vaidyeshwara */ 901*791dfaa7SVallish Vaidyeshwara if (bytes_trans < 10) 902*791dfaa7SVallish Vaidyeshwara (void) printf("%*s", (bytes_trans - 10), " "); 903*791dfaa7SVallish Vaidyeshwara else 904*791dfaa7SVallish Vaidyeshwara (void) printf(" "); 905*791dfaa7SVallish Vaidyeshwara 906*791dfaa7SVallish Vaidyeshwara bytes_trans = 0; 9077c478bd9Sstevel@tonic-gate for (nl = rs->nlist; nl; nl = nl->next) { 908*791dfaa7SVallish Vaidyeshwara bytes_trans += (len = printf("%s", nl->netid)) 909*791dfaa7SVallish Vaidyeshwara < 0 ? 0 : len; 9107c478bd9Sstevel@tonic-gate if (nl->next) 911*791dfaa7SVallish Vaidyeshwara bytes_trans += (len = printf(",")) < 0 912*791dfaa7SVallish Vaidyeshwara ? 0 : len; 9137c478bd9Sstevel@tonic-gate } 914*791dfaa7SVallish Vaidyeshwara /* 915*791dfaa7SVallish Vaidyeshwara * Align netid(s) column output for 32 bytes. 916*791dfaa7SVallish Vaidyeshwara */ 917*791dfaa7SVallish Vaidyeshwara if (bytes_trans < 32) 918*791dfaa7SVallish Vaidyeshwara (void) printf("%*s", (bytes_trans - 32), " "); 919*791dfaa7SVallish Vaidyeshwara 9207c478bd9Sstevel@tonic-gate rpc = getrpcbynumber(rs->prog); 9217c478bd9Sstevel@tonic-gate if (rpc) 922*791dfaa7SVallish Vaidyeshwara (void) printf(" %-11s", rpc->r_name); 9237c478bd9Sstevel@tonic-gate else 924*791dfaa7SVallish Vaidyeshwara (void) printf(" %-11s", "-"); 925*791dfaa7SVallish Vaidyeshwara (void) printf(" %s\n", rs->owner); 9267c478bd9Sstevel@tonic-gate } 9277c478bd9Sstevel@tonic-gate } 9287c478bd9Sstevel@tonic-gate clnt_destroy(client); 9297c478bd9Sstevel@tonic-gate return; 9307c478bd9Sstevel@tonic-gate 931*791dfaa7SVallish Vaidyeshwara error: (void) fprintf(stderr, "rpcinfo: no memory\n"); 9327c478bd9Sstevel@tonic-gate } 9337c478bd9Sstevel@tonic-gate 9347c478bd9Sstevel@tonic-gate static char nullstring[] = "\000"; 9357c478bd9Sstevel@tonic-gate 9367c478bd9Sstevel@tonic-gate static void 9377c478bd9Sstevel@tonic-gate rpcbaddrlist(netid, argc, argv) 9387c478bd9Sstevel@tonic-gate char *netid; 9397c478bd9Sstevel@tonic-gate int argc; 9407c478bd9Sstevel@tonic-gate char **argv; 9417c478bd9Sstevel@tonic-gate { 9427c478bd9Sstevel@tonic-gate rpcb_entry_list_ptr head = NULL; 9437c478bd9Sstevel@tonic-gate struct timeval minutetimeout; 9447c478bd9Sstevel@tonic-gate register CLIENT *client; 9457c478bd9Sstevel@tonic-gate struct rpcent *rpc; 9467c478bd9Sstevel@tonic-gate char *host; 9477c478bd9Sstevel@tonic-gate RPCB parms; 9487c478bd9Sstevel@tonic-gate struct netbuf *targaddr; 9497c478bd9Sstevel@tonic-gate 9507c478bd9Sstevel@tonic-gate if (argc != 3) { 9517c478bd9Sstevel@tonic-gate usage(); 9527c478bd9Sstevel@tonic-gate exit(1); 9537c478bd9Sstevel@tonic-gate } 9547c478bd9Sstevel@tonic-gate host = argv[0]; 9557c478bd9Sstevel@tonic-gate if (netid == NULL) { 9567c478bd9Sstevel@tonic-gate if (loopback_netid == NULL) { 9577c478bd9Sstevel@tonic-gate client = clnt_rpcbind_create(host, RPCBVERS4, &targaddr); 9587c478bd9Sstevel@tonic-gate } else { 9597c478bd9Sstevel@tonic-gate client = getclnthandle(host, loopback_nconf, RPCBVERS4, 9607c478bd9Sstevel@tonic-gate &targaddr); 9617c478bd9Sstevel@tonic-gate if (client == NULL && rpc_createerr.cf_stat == 9627c478bd9Sstevel@tonic-gate RPC_N2AXLATEFAILURE) { 9637c478bd9Sstevel@tonic-gate client = clnt_rpcbind_create(host, RPCBVERS4, &targaddr); 9647c478bd9Sstevel@tonic-gate } 9657c478bd9Sstevel@tonic-gate } 9667c478bd9Sstevel@tonic-gate } else { 9677c478bd9Sstevel@tonic-gate struct netconfig *nconf; 9687c478bd9Sstevel@tonic-gate 9697c478bd9Sstevel@tonic-gate nconf = getnetconfigent(netid); 9707c478bd9Sstevel@tonic-gate if (nconf == NULL) { 9717c478bd9Sstevel@tonic-gate nc_perror("rpcinfo: invalid transport"); 9727c478bd9Sstevel@tonic-gate exit(1); 9737c478bd9Sstevel@tonic-gate } 9747c478bd9Sstevel@tonic-gate client = getclnthandle(host, nconf, RPCBVERS4, &targaddr); 9757c478bd9Sstevel@tonic-gate if (nconf) 9767c478bd9Sstevel@tonic-gate (void) freenetconfigent(nconf); 9777c478bd9Sstevel@tonic-gate } 9787c478bd9Sstevel@tonic-gate if (client == (CLIENT *)NULL) { 9797c478bd9Sstevel@tonic-gate clnt_pcreateerror("rpcinfo: can't contact rpcbind"); 9807c478bd9Sstevel@tonic-gate exit(1); 9817c478bd9Sstevel@tonic-gate } 9827c478bd9Sstevel@tonic-gate minutetimeout.tv_sec = 60; 9837c478bd9Sstevel@tonic-gate minutetimeout.tv_usec = 0; 9847c478bd9Sstevel@tonic-gate 9857c478bd9Sstevel@tonic-gate parms.r_prog = getprognum(argv[1]); 9867c478bd9Sstevel@tonic-gate parms.r_vers = getvers(argv[2]); 9877c478bd9Sstevel@tonic-gate parms.r_netid = client->cl_netid; 9887c478bd9Sstevel@tonic-gate if (targaddr == NULL) { 9897c478bd9Sstevel@tonic-gate parms.r_addr = nullstring; /* for XDRing */ 9907c478bd9Sstevel@tonic-gate } else { 9917c478bd9Sstevel@tonic-gate /* 9927c478bd9Sstevel@tonic-gate * We also send the remote system the address we 9937c478bd9Sstevel@tonic-gate * used to contact it in case it can help it 9947c478bd9Sstevel@tonic-gate * connect back with us 9957c478bd9Sstevel@tonic-gate */ 9967c478bd9Sstevel@tonic-gate struct netconfig *nconf; 9977c478bd9Sstevel@tonic-gate 9987c478bd9Sstevel@tonic-gate nconf = getnetconfigent(client->cl_netid); 9997c478bd9Sstevel@tonic-gate if (nconf != NULL) { 10007c478bd9Sstevel@tonic-gate parms.r_addr = taddr2uaddr(nconf, targaddr); 10017c478bd9Sstevel@tonic-gate if (parms.r_addr == NULL) 10027c478bd9Sstevel@tonic-gate parms.r_addr = nullstring; 10037c478bd9Sstevel@tonic-gate freenetconfigent(nconf); 10047c478bd9Sstevel@tonic-gate } else { 10057c478bd9Sstevel@tonic-gate parms.r_addr = nullstring; /* for XDRing */ 10067c478bd9Sstevel@tonic-gate } 10077c478bd9Sstevel@tonic-gate free(targaddr->buf); 10087c478bd9Sstevel@tonic-gate free(targaddr); 10097c478bd9Sstevel@tonic-gate } 10107c478bd9Sstevel@tonic-gate parms.r_owner = nullstring; 10117c478bd9Sstevel@tonic-gate 10127c478bd9Sstevel@tonic-gate if (CLNT_CALL(client, RPCBPROC_GETADDRLIST, (xdrproc_t)xdr_rpcb, 10137c478bd9Sstevel@tonic-gate (char *)&parms, (xdrproc_t)xdr_rpcb_entry_list_ptr, 10147c478bd9Sstevel@tonic-gate (char *)&head, minutetimeout) != RPC_SUCCESS) { 10157c478bd9Sstevel@tonic-gate clnt_perror(client, "rpcinfo: can't contact rpcbind: "); 10167c478bd9Sstevel@tonic-gate exit(1); 10177c478bd9Sstevel@tonic-gate } 10187c478bd9Sstevel@tonic-gate if (head == NULL) { 1019*791dfaa7SVallish Vaidyeshwara (void) printf("No remote programs registered.\n"); 10207c478bd9Sstevel@tonic-gate } else { 1021*791dfaa7SVallish Vaidyeshwara (void) printf( 10227c478bd9Sstevel@tonic-gate " program vers tp_family/name/class address\t\t service\n"); 10237c478bd9Sstevel@tonic-gate for (; head != NULL; head = head->rpcb_entry_next) { 10247c478bd9Sstevel@tonic-gate rpcb_entry *re; 10257c478bd9Sstevel@tonic-gate char buf[128]; 10267c478bd9Sstevel@tonic-gate 10277c478bd9Sstevel@tonic-gate re = &head->rpcb_entry_map; 1028*791dfaa7SVallish Vaidyeshwara (void) printf("%10ld%3ld ", 10297c478bd9Sstevel@tonic-gate parms.r_prog, parms.r_vers); 1030*791dfaa7SVallish Vaidyeshwara (void) snprintf(buf, sizeof (buf), "%s/%s/%s ", 10317c478bd9Sstevel@tonic-gate re->r_nc_protofmly, re->r_nc_proto, 10327c478bd9Sstevel@tonic-gate re->r_nc_semantics == NC_TPI_CLTS ? "clts" : 10337c478bd9Sstevel@tonic-gate re->r_nc_semantics == NC_TPI_COTS ? "cots" : 10347c478bd9Sstevel@tonic-gate "cots_ord"); 1035*791dfaa7SVallish Vaidyeshwara (void) printf("%-24s", buf); 1036*791dfaa7SVallish Vaidyeshwara (void) printf("%-24s", re->r_maddr); 10377c478bd9Sstevel@tonic-gate rpc = getrpcbynumber(parms.r_prog); 10387c478bd9Sstevel@tonic-gate if (rpc) 1039*791dfaa7SVallish Vaidyeshwara (void) printf(" %-13s", rpc->r_name); 10407c478bd9Sstevel@tonic-gate else 1041*791dfaa7SVallish Vaidyeshwara (void) printf(" %-13s", "-"); 1042*791dfaa7SVallish Vaidyeshwara (void) printf("\n"); 10437c478bd9Sstevel@tonic-gate } 10447c478bd9Sstevel@tonic-gate } 10457c478bd9Sstevel@tonic-gate clnt_destroy(client); 10467c478bd9Sstevel@tonic-gate } 10477c478bd9Sstevel@tonic-gate 10487c478bd9Sstevel@tonic-gate /* 10497c478bd9Sstevel@tonic-gate * monitor rpcbind 10507c478bd9Sstevel@tonic-gate */ 10517c478bd9Sstevel@tonic-gate static void 10527c478bd9Sstevel@tonic-gate rpcbgetstat(argc, argv) 10537c478bd9Sstevel@tonic-gate int argc; 10547c478bd9Sstevel@tonic-gate char **argv; 10557c478bd9Sstevel@tonic-gate { 10567c478bd9Sstevel@tonic-gate rpcb_stat_byvers inf; 10577c478bd9Sstevel@tonic-gate struct timeval minutetimeout; 10587c478bd9Sstevel@tonic-gate register CLIENT *client; 10597c478bd9Sstevel@tonic-gate char *host; 10607c478bd9Sstevel@tonic-gate int i, j; 10617c478bd9Sstevel@tonic-gate rpcbs_addrlist *pa; 10627c478bd9Sstevel@tonic-gate rpcbs_rmtcalllist *pr; 10637c478bd9Sstevel@tonic-gate int cnt, flen; 10647c478bd9Sstevel@tonic-gate struct utsname utsname; 10657c478bd9Sstevel@tonic-gate #define MAXFIELD 64 10667c478bd9Sstevel@tonic-gate char fieldbuf[MAXFIELD]; 10677c478bd9Sstevel@tonic-gate #define MAXLINE 256 10687c478bd9Sstevel@tonic-gate char linebuf[MAXLINE]; 1069*791dfaa7SVallish 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 { 1088*791dfaa7SVallish Vaidyeshwara (void) uname(&utsname); 10897c478bd9Sstevel@tonic-gate host = utsname.nodename; 10907c478bd9Sstevel@tonic-gate } 10917c478bd9Sstevel@tonic-gate if (loopback_netid != NULL) { 10927c478bd9Sstevel@tonic-gate client = getclnthandle(host, loopback_nconf, RPCBVERS4, NULL); 10937c478bd9Sstevel@tonic-gate if (client == NULL && rpc_createerr.cf_stat == 10947c478bd9Sstevel@tonic-gate RPC_N2AXLATEFAILURE) { 10957c478bd9Sstevel@tonic-gate client = clnt_rpcbind_create(host, RPCBVERS4, NULL); 10967c478bd9Sstevel@tonic-gate } 10977c478bd9Sstevel@tonic-gate } else { 10987c478bd9Sstevel@tonic-gate client = clnt_rpcbind_create(host, RPCBVERS4, NULL); 10997c478bd9Sstevel@tonic-gate } 11007c478bd9Sstevel@tonic-gate if (client == (CLIENT *)NULL) { 11017c478bd9Sstevel@tonic-gate clnt_pcreateerror("rpcinfo: can't contact rpcbind"); 11027c478bd9Sstevel@tonic-gate exit(1); 11037c478bd9Sstevel@tonic-gate } 11047c478bd9Sstevel@tonic-gate minutetimeout.tv_sec = 60; 11057c478bd9Sstevel@tonic-gate minutetimeout.tv_usec = 0; 1106*791dfaa7SVallish Vaidyeshwara (void) memset((char *)&inf, 0, sizeof (rpcb_stat_byvers)); 11077c478bd9Sstevel@tonic-gate if (CLNT_CALL(client, RPCBPROC_GETSTAT, (xdrproc_t)xdr_void, NULL, 11087c478bd9Sstevel@tonic-gate (xdrproc_t)xdr_rpcb_stat_byvers, (char *)&inf, minutetimeout) 11097c478bd9Sstevel@tonic-gate != RPC_SUCCESS) { 11107c478bd9Sstevel@tonic-gate clnt_perror(client, "rpcinfo: can't contact rpcbind: "); 11117c478bd9Sstevel@tonic-gate exit(1); 11127c478bd9Sstevel@tonic-gate } 1113*791dfaa7SVallish Vaidyeshwara (void) printf("PORTMAP (version 2) statistics\n"); 11147c478bd9Sstevel@tonic-gate lp = linebuf; 11157c478bd9Sstevel@tonic-gate for (i = 0; i <= rpcb_highproc_2; i++) { 11167c478bd9Sstevel@tonic-gate fieldbuf[0] = '\0'; 11177c478bd9Sstevel@tonic-gate switch (i) { 11187c478bd9Sstevel@tonic-gate case PMAPPROC_SET: 1119*791dfaa7SVallish Vaidyeshwara (void) sprintf(fieldbuf, "%d/", 1120*791dfaa7SVallish Vaidyeshwara inf[RPCBVERS_2_STAT].setinfo); 11217c478bd9Sstevel@tonic-gate break; 11227c478bd9Sstevel@tonic-gate case PMAPPROC_UNSET: 1123*791dfaa7SVallish Vaidyeshwara (void) sprintf(fieldbuf, "%d/", 11247c478bd9Sstevel@tonic-gate inf[RPCBVERS_2_STAT].unsetinfo); 11257c478bd9Sstevel@tonic-gate break; 11267c478bd9Sstevel@tonic-gate case PMAPPROC_GETPORT: 11277c478bd9Sstevel@tonic-gate cnt = 0; 11287c478bd9Sstevel@tonic-gate for (pa = inf[RPCBVERS_2_STAT].addrinfo; pa; 11297c478bd9Sstevel@tonic-gate pa = pa->next) 11307c478bd9Sstevel@tonic-gate cnt += pa->success; 1131*791dfaa7SVallish Vaidyeshwara (void) sprintf(fieldbuf, "%d/", cnt); 11327c478bd9Sstevel@tonic-gate break; 11337c478bd9Sstevel@tonic-gate case PMAPPROC_CALLIT: 11347c478bd9Sstevel@tonic-gate cnt = 0; 11357c478bd9Sstevel@tonic-gate for (pr = inf[RPCBVERS_2_STAT].rmtinfo; pr; 11367c478bd9Sstevel@tonic-gate pr = pr->next) 11377c478bd9Sstevel@tonic-gate cnt += pr->success; 1138*791dfaa7SVallish Vaidyeshwara (void) sprintf(fieldbuf, "%d/", cnt); 11397c478bd9Sstevel@tonic-gate break; 11407c478bd9Sstevel@tonic-gate default: break; /* For the remaining ones */ 11417c478bd9Sstevel@tonic-gate } 11427c478bd9Sstevel@tonic-gate cp = &fieldbuf[0] + strlen(fieldbuf); 1143*791dfaa7SVallish Vaidyeshwara (void) sprintf(cp, "%d", inf[RPCBVERS_2_STAT].info[i]); 11447c478bd9Sstevel@tonic-gate flen = strlen(fieldbuf); 1145*791dfaa7SVallish Vaidyeshwara (void) printf("%s%s", pmaphdr[i], 1146*791dfaa7SVallish Vaidyeshwara spaces((int)((TABSTOP * (1 + flen / TABSTOP)) 1147*791dfaa7SVallish Vaidyeshwara - strlen(pmaphdr[i])))); 1148*791dfaa7SVallish Vaidyeshwara (void) snprintf(lp, (MAXLINE - (lp - linebuf)), "%s%s", 1149*791dfaa7SVallish Vaidyeshwara fieldbuf, spaces(cnt = ((TABSTOP * (1 + flen / TABSTOP)) 11507c478bd9Sstevel@tonic-gate - flen))); 11517c478bd9Sstevel@tonic-gate lp += (flen + cnt); 11527c478bd9Sstevel@tonic-gate } 1153*791dfaa7SVallish Vaidyeshwara (void) printf("\n%s\n\n", linebuf); 11547c478bd9Sstevel@tonic-gate 11557c478bd9Sstevel@tonic-gate if (inf[RPCBVERS_2_STAT].info[PMAPPROC_CALLIT]) { 1156*791dfaa7SVallish Vaidyeshwara (void) printf("PMAP_RMTCALL call statistics\n"); 11577c478bd9Sstevel@tonic-gate print_rmtcallstat(RPCBVERS_2_STAT, &inf[RPCBVERS_2_STAT]); 1158*791dfaa7SVallish Vaidyeshwara (void) printf("\n"); 11597c478bd9Sstevel@tonic-gate } 11607c478bd9Sstevel@tonic-gate 11617c478bd9Sstevel@tonic-gate if (inf[RPCBVERS_2_STAT].info[PMAPPROC_GETPORT]) { 1162*791dfaa7SVallish Vaidyeshwara (void) printf("PMAP_GETPORT call statistics\n"); 11637c478bd9Sstevel@tonic-gate print_getaddrstat(RPCBVERS_2_STAT, &inf[RPCBVERS_2_STAT]); 1164*791dfaa7SVallish Vaidyeshwara (void) printf("\n"); 11657c478bd9Sstevel@tonic-gate } 11667c478bd9Sstevel@tonic-gate 1167*791dfaa7SVallish Vaidyeshwara (void) printf("RPCBIND (version 3) statistics\n"); 11687c478bd9Sstevel@tonic-gate lp = linebuf; 11697c478bd9Sstevel@tonic-gate for (i = 0; i <= rpcb_highproc_3; i++) { 11707c478bd9Sstevel@tonic-gate fieldbuf[0] = '\0'; 11717c478bd9Sstevel@tonic-gate switch (i) { 11727c478bd9Sstevel@tonic-gate case RPCBPROC_SET: 1173*791dfaa7SVallish Vaidyeshwara (void) sprintf(fieldbuf, "%d/", 1174*791dfaa7SVallish Vaidyeshwara inf[RPCBVERS_3_STAT].setinfo); 11757c478bd9Sstevel@tonic-gate break; 11767c478bd9Sstevel@tonic-gate case RPCBPROC_UNSET: 1177*791dfaa7SVallish Vaidyeshwara (void) sprintf(fieldbuf, "%d/", 11787c478bd9Sstevel@tonic-gate inf[RPCBVERS_3_STAT].unsetinfo); 11797c478bd9Sstevel@tonic-gate break; 11807c478bd9Sstevel@tonic-gate case RPCBPROC_GETADDR: 11817c478bd9Sstevel@tonic-gate cnt = 0; 11827c478bd9Sstevel@tonic-gate for (pa = inf[RPCBVERS_3_STAT].addrinfo; pa; 11837c478bd9Sstevel@tonic-gate pa = pa->next) 11847c478bd9Sstevel@tonic-gate cnt += pa->success; 1185*791dfaa7SVallish Vaidyeshwara (void) sprintf(fieldbuf, "%d/", cnt); 11867c478bd9Sstevel@tonic-gate break; 11877c478bd9Sstevel@tonic-gate case RPCBPROC_CALLIT: 11887c478bd9Sstevel@tonic-gate cnt = 0; 11897c478bd9Sstevel@tonic-gate for (pr = inf[RPCBVERS_3_STAT].rmtinfo; pr; 11907c478bd9Sstevel@tonic-gate pr = pr->next) 11917c478bd9Sstevel@tonic-gate cnt += pr->success; 1192*791dfaa7SVallish Vaidyeshwara (void) sprintf(fieldbuf, "%d/", cnt); 11937c478bd9Sstevel@tonic-gate break; 11947c478bd9Sstevel@tonic-gate default: break; /* For the remaining ones */ 11957c478bd9Sstevel@tonic-gate } 11967c478bd9Sstevel@tonic-gate cp = &fieldbuf[0] + strlen(fieldbuf); 1197*791dfaa7SVallish Vaidyeshwara (void) sprintf(cp, "%d", inf[RPCBVERS_3_STAT].info[i]); 11987c478bd9Sstevel@tonic-gate flen = strlen(fieldbuf); 1199*791dfaa7SVallish Vaidyeshwara (void) printf("%s%s", rpcb3hdr[i], 1200*791dfaa7SVallish Vaidyeshwara spaces((int)((TABSTOP * (1 + flen / TABSTOP)) 1201*791dfaa7SVallish Vaidyeshwara - strlen(rpcb3hdr[i])))); 1202*791dfaa7SVallish Vaidyeshwara (void) snprintf(lp, (MAXLINE - (lp - linebuf)), "%s%s", 1203*791dfaa7SVallish Vaidyeshwara fieldbuf, spaces(cnt = ((TABSTOP * (1 + flen / TABSTOP)) 12047c478bd9Sstevel@tonic-gate - flen))); 12057c478bd9Sstevel@tonic-gate lp += (flen + cnt); 12067c478bd9Sstevel@tonic-gate } 1207*791dfaa7SVallish Vaidyeshwara (void) printf("\n%s\n\n", linebuf); 12087c478bd9Sstevel@tonic-gate 12097c478bd9Sstevel@tonic-gate if (inf[RPCBVERS_3_STAT].info[RPCBPROC_CALLIT]) { 1210*791dfaa7SVallish Vaidyeshwara (void) printf("RPCB_RMTCALL (version 3) call statistics\n"); 12117c478bd9Sstevel@tonic-gate print_rmtcallstat(RPCBVERS_3_STAT, &inf[RPCBVERS_3_STAT]); 1212*791dfaa7SVallish Vaidyeshwara (void) printf("\n"); 12137c478bd9Sstevel@tonic-gate } 12147c478bd9Sstevel@tonic-gate 12157c478bd9Sstevel@tonic-gate if (inf[RPCBVERS_3_STAT].info[RPCBPROC_GETADDR]) { 1216*791dfaa7SVallish Vaidyeshwara (void) printf("RPCB_GETADDR (version 3) call statistics\n"); 12177c478bd9Sstevel@tonic-gate print_getaddrstat(RPCBVERS_3_STAT, &inf[RPCBVERS_3_STAT]); 1218*791dfaa7SVallish Vaidyeshwara (void) printf("\n"); 12197c478bd9Sstevel@tonic-gate } 12207c478bd9Sstevel@tonic-gate 1221*791dfaa7SVallish Vaidyeshwara (void) printf("RPCBIND (version 4) statistics\n"); 12227c478bd9Sstevel@tonic-gate 12237c478bd9Sstevel@tonic-gate for (j = 0; j <= 9; j += 9) { /* Just two iterations for printing */ 12247c478bd9Sstevel@tonic-gate lp = linebuf; 12257c478bd9Sstevel@tonic-gate for (i = j; i <= MAX(8, rpcb_highproc_4 - 9 + j); i++) { 12267c478bd9Sstevel@tonic-gate fieldbuf[0] = '\0'; 12277c478bd9Sstevel@tonic-gate switch (i) { 12287c478bd9Sstevel@tonic-gate case RPCBPROC_SET: 1229*791dfaa7SVallish Vaidyeshwara (void) sprintf(fieldbuf, "%d/", 12307c478bd9Sstevel@tonic-gate inf[RPCBVERS_4_STAT].setinfo); 12317c478bd9Sstevel@tonic-gate break; 12327c478bd9Sstevel@tonic-gate case RPCBPROC_UNSET: 1233*791dfaa7SVallish Vaidyeshwara (void) sprintf(fieldbuf, "%d/", 12347c478bd9Sstevel@tonic-gate inf[RPCBVERS_4_STAT].unsetinfo); 12357c478bd9Sstevel@tonic-gate break; 12367c478bd9Sstevel@tonic-gate case RPCBPROC_GETADDR: 12377c478bd9Sstevel@tonic-gate cnt = 0; 12387c478bd9Sstevel@tonic-gate for (pa = inf[RPCBVERS_4_STAT].addrinfo; pa; 12397c478bd9Sstevel@tonic-gate pa = pa->next) 12407c478bd9Sstevel@tonic-gate cnt += pa->success; 1241*791dfaa7SVallish Vaidyeshwara (void) sprintf(fieldbuf, "%d/", cnt); 12427c478bd9Sstevel@tonic-gate break; 12437c478bd9Sstevel@tonic-gate case RPCBPROC_CALLIT: 12447c478bd9Sstevel@tonic-gate cnt = 0; 12457c478bd9Sstevel@tonic-gate for (pr = inf[RPCBVERS_4_STAT].rmtinfo; pr; 12467c478bd9Sstevel@tonic-gate pr = pr->next) 12477c478bd9Sstevel@tonic-gate cnt += pr->success; 1248*791dfaa7SVallish Vaidyeshwara (void) sprintf(fieldbuf, "%d/", cnt); 12497c478bd9Sstevel@tonic-gate break; 12507c478bd9Sstevel@tonic-gate default: break; /* For the remaining ones */ 12517c478bd9Sstevel@tonic-gate } 12527c478bd9Sstevel@tonic-gate cp = &fieldbuf[0] + strlen(fieldbuf); 12537c478bd9Sstevel@tonic-gate /* 12547c478bd9Sstevel@tonic-gate * XXX: We also add RPCBPROC_GETADDRLIST queries to 12557c478bd9Sstevel@tonic-gate * RPCB_GETADDR because rpcbind includes the 12567c478bd9Sstevel@tonic-gate * RPCB_GETADDRLIST successes in RPCB_GETADDR. 12577c478bd9Sstevel@tonic-gate */ 12587c478bd9Sstevel@tonic-gate if (i != RPCBPROC_GETADDR) 1259*791dfaa7SVallish Vaidyeshwara (void) sprintf(cp, "%d", 1260*791dfaa7SVallish Vaidyeshwara inf[RPCBVERS_4_STAT].info[i]); 12617c478bd9Sstevel@tonic-gate else 1262*791dfaa7SVallish Vaidyeshwara (void) sprintf(cp, "%d", 1263*791dfaa7SVallish Vaidyeshwara inf[RPCBVERS_4_STAT].info[i] + 12647c478bd9Sstevel@tonic-gate inf[RPCBVERS_4_STAT].info[RPCBPROC_GETADDRLIST]); 12657c478bd9Sstevel@tonic-gate flen = strlen(fieldbuf); 1266*791dfaa7SVallish Vaidyeshwara (void) printf("%s%s", rpcb4hdr[i], 1267*791dfaa7SVallish Vaidyeshwara spaces((int)((TABSTOP * (1 + flen / TABSTOP)) 1268*791dfaa7SVallish Vaidyeshwara - strlen(rpcb4hdr[i])))); 1269*791dfaa7SVallish Vaidyeshwara (void) snprintf(lp, MAXLINE - (lp - linebuf), "%s%s", 1270*791dfaa7SVallish Vaidyeshwara fieldbuf, spaces(cnt = 1271*791dfaa7SVallish Vaidyeshwara ((TABSTOP * (1 + flen / TABSTOP)) - flen))); 12727c478bd9Sstevel@tonic-gate lp += (flen + cnt); 12737c478bd9Sstevel@tonic-gate } 1274*791dfaa7SVallish Vaidyeshwara (void) printf("\n%s\n", linebuf); 12757c478bd9Sstevel@tonic-gate } 12767c478bd9Sstevel@tonic-gate 12777c478bd9Sstevel@tonic-gate if (inf[RPCBVERS_4_STAT].info[RPCBPROC_CALLIT] || 12787c478bd9Sstevel@tonic-gate inf[RPCBVERS_4_STAT].info[RPCBPROC_INDIRECT]) { 1279*791dfaa7SVallish Vaidyeshwara (void) printf("\n"); 1280*791dfaa7SVallish Vaidyeshwara (void) printf("RPCB_RMTCALL (version 4) call statistics\n"); 12817c478bd9Sstevel@tonic-gate print_rmtcallstat(RPCBVERS_4_STAT, &inf[RPCBVERS_4_STAT]); 12827c478bd9Sstevel@tonic-gate } 12837c478bd9Sstevel@tonic-gate 12847c478bd9Sstevel@tonic-gate if (inf[RPCBVERS_4_STAT].info[RPCBPROC_GETADDR]) { 1285*791dfaa7SVallish Vaidyeshwara (void) printf("\n"); 1286*791dfaa7SVallish Vaidyeshwara (void) printf("RPCB_GETADDR (version 4) call statistics\n"); 12877c478bd9Sstevel@tonic-gate print_getaddrstat(RPCBVERS_4_STAT, &inf[RPCBVERS_4_STAT]); 12887c478bd9Sstevel@tonic-gate } 12897c478bd9Sstevel@tonic-gate clnt_destroy(client); 12907c478bd9Sstevel@tonic-gate } 12917c478bd9Sstevel@tonic-gate 12927c478bd9Sstevel@tonic-gate /* 12937c478bd9Sstevel@tonic-gate * Delete registeration for this (prog, vers, netid) 12947c478bd9Sstevel@tonic-gate */ 12957c478bd9Sstevel@tonic-gate static void 12967c478bd9Sstevel@tonic-gate deletereg(netid, argc, argv) 12977c478bd9Sstevel@tonic-gate char *netid; 12987c478bd9Sstevel@tonic-gate int argc; 12997c478bd9Sstevel@tonic-gate char **argv; 13007c478bd9Sstevel@tonic-gate { 13017c478bd9Sstevel@tonic-gate struct netconfig *nconf = NULL; 13027c478bd9Sstevel@tonic-gate 13037c478bd9Sstevel@tonic-gate if (argc != 2) { 13047c478bd9Sstevel@tonic-gate usage(); 13057c478bd9Sstevel@tonic-gate exit(1); 13067c478bd9Sstevel@tonic-gate } 13077c478bd9Sstevel@tonic-gate if (netid) { 13087c478bd9Sstevel@tonic-gate nconf = getnetconfigent(netid); 13097c478bd9Sstevel@tonic-gate if (nconf == NULL) { 1310*791dfaa7SVallish Vaidyeshwara (void) fprintf(stderr, 1311*791dfaa7SVallish Vaidyeshwara "rpcinfo: netid %s not supported\n", netid); 13127c478bd9Sstevel@tonic-gate exit(1); 13137c478bd9Sstevel@tonic-gate } 13147c478bd9Sstevel@tonic-gate } 13157c478bd9Sstevel@tonic-gate if ((rpcb_unset(getprognum(argv[0]), getvers(argv[1]), nconf)) == 0) { 1316*791dfaa7SVallish Vaidyeshwara (void) fprintf(stderr, 13177c478bd9Sstevel@tonic-gate "rpcinfo: Could not delete registration for prog %s version %s\n", 13187c478bd9Sstevel@tonic-gate argv[0], argv[1]); 13197c478bd9Sstevel@tonic-gate exit(1); 13207c478bd9Sstevel@tonic-gate } 13217c478bd9Sstevel@tonic-gate } 13227c478bd9Sstevel@tonic-gate 13237c478bd9Sstevel@tonic-gate /* 13247c478bd9Sstevel@tonic-gate * Create and return a handle for the given nconf. 13257c478bd9Sstevel@tonic-gate * Exit if cannot create handle. 13267c478bd9Sstevel@tonic-gate */ 13277c478bd9Sstevel@tonic-gate static CLIENT * 13287c478bd9Sstevel@tonic-gate clnt_addr_create(address, nconf, prog, vers) 13297c478bd9Sstevel@tonic-gate char *address; 13307c478bd9Sstevel@tonic-gate struct netconfig *nconf; 13317c478bd9Sstevel@tonic-gate ulong_t prog; 13327c478bd9Sstevel@tonic-gate ulong_t vers; 13337c478bd9Sstevel@tonic-gate { 13347c478bd9Sstevel@tonic-gate CLIENT *client; 13357c478bd9Sstevel@tonic-gate static struct netbuf *nbuf; 13367c478bd9Sstevel@tonic-gate static int fd = RPC_ANYFD; 13377c478bd9Sstevel@tonic-gate struct t_info tinfo; 13387c478bd9Sstevel@tonic-gate 13397c478bd9Sstevel@tonic-gate if (fd == RPC_ANYFD) { 13407c478bd9Sstevel@tonic-gate if ((fd = t_open(nconf->nc_device, O_RDWR, &tinfo)) == -1) { 13417c478bd9Sstevel@tonic-gate rpc_createerr.cf_stat = RPC_TLIERROR; 13427c478bd9Sstevel@tonic-gate rpc_createerr.cf_error.re_terrno = t_errno; 13437c478bd9Sstevel@tonic-gate clnt_pcreateerror("rpcinfo"); 13447c478bd9Sstevel@tonic-gate exit(1); 13457c478bd9Sstevel@tonic-gate } 13467c478bd9Sstevel@tonic-gate /* Convert the uaddr to taddr */ 13477c478bd9Sstevel@tonic-gate nbuf = uaddr2taddr(nconf, address); 13487c478bd9Sstevel@tonic-gate if (nbuf == NULL) { 13497c478bd9Sstevel@tonic-gate netdir_perror("rpcinfo"); 13507c478bd9Sstevel@tonic-gate exit(1); 13517c478bd9Sstevel@tonic-gate } 13527c478bd9Sstevel@tonic-gate } 13537c478bd9Sstevel@tonic-gate client = clnt_tli_create(fd, nconf, nbuf, prog, vers, 0, 0); 13547c478bd9Sstevel@tonic-gate if (client == (CLIENT *)NULL) { 13557c478bd9Sstevel@tonic-gate clnt_pcreateerror("rpcinfo"); 13567c478bd9Sstevel@tonic-gate exit(1); 13577c478bd9Sstevel@tonic-gate } 13587c478bd9Sstevel@tonic-gate return (client); 13597c478bd9Sstevel@tonic-gate } 13607c478bd9Sstevel@tonic-gate 13617c478bd9Sstevel@tonic-gate /* 13627c478bd9Sstevel@tonic-gate * If the version number is given, ping that (prog, vers); else try to find 13637c478bd9Sstevel@tonic-gate * the version numbers supported for that prog and ping all the versions. 13647c478bd9Sstevel@tonic-gate * Remote rpcbind is not contacted for this service. The requests are 13657c478bd9Sstevel@tonic-gate * sent directly to the services themselves. 13667c478bd9Sstevel@tonic-gate */ 13677c478bd9Sstevel@tonic-gate static void 13687c478bd9Sstevel@tonic-gate addrping(address, netid, argc, argv) 13697c478bd9Sstevel@tonic-gate char *address; 13707c478bd9Sstevel@tonic-gate char *netid; 13717c478bd9Sstevel@tonic-gate int argc; 13727c478bd9Sstevel@tonic-gate char **argv; 13737c478bd9Sstevel@tonic-gate { 13747c478bd9Sstevel@tonic-gate CLIENT *client; 13757c478bd9Sstevel@tonic-gate struct timeval to; 13767c478bd9Sstevel@tonic-gate enum clnt_stat rpc_stat; 13777c478bd9Sstevel@tonic-gate ulong_t prognum, versnum, minvers, maxvers; 13787c478bd9Sstevel@tonic-gate struct rpc_err rpcerr; 13797c478bd9Sstevel@tonic-gate int failure = 0; 13807c478bd9Sstevel@tonic-gate struct netconfig *nconf; 13817c478bd9Sstevel@tonic-gate int fd; 13827c478bd9Sstevel@tonic-gate 13837c478bd9Sstevel@tonic-gate if (argc < 1 || argc > 2 || (netid == NULL)) { 13847c478bd9Sstevel@tonic-gate usage(); 13857c478bd9Sstevel@tonic-gate exit(1); 13867c478bd9Sstevel@tonic-gate } 13877c478bd9Sstevel@tonic-gate nconf = getnetconfigent(netid); 13887c478bd9Sstevel@tonic-gate if (nconf == (struct netconfig *)NULL) { 1389*791dfaa7SVallish Vaidyeshwara (void) fprintf(stderr, "rpcinfo: Could not find %s\n", netid); 13907c478bd9Sstevel@tonic-gate exit(1); 13917c478bd9Sstevel@tonic-gate } 13927c478bd9Sstevel@tonic-gate to.tv_sec = 10; 13937c478bd9Sstevel@tonic-gate to.tv_usec = 0; 13947c478bd9Sstevel@tonic-gate prognum = getprognum(argv[0]); 13957c478bd9Sstevel@tonic-gate if (argc == 1) { /* Version number not known */ 13967c478bd9Sstevel@tonic-gate /* 13977c478bd9Sstevel@tonic-gate * A call to version 0 should fail with a program/version 13987c478bd9Sstevel@tonic-gate * mismatch, and give us the range of versions supported. 13997c478bd9Sstevel@tonic-gate */ 14007c478bd9Sstevel@tonic-gate versnum = MIN_VERS; 14017c478bd9Sstevel@tonic-gate } else { 14027c478bd9Sstevel@tonic-gate versnum = getvers(argv[1]); 14037c478bd9Sstevel@tonic-gate } 14047c478bd9Sstevel@tonic-gate client = clnt_addr_create(address, nconf, prognum, versnum); 14057c478bd9Sstevel@tonic-gate rpc_stat = CLNT_CALL(client, NULLPROC, (xdrproc_t)xdr_void, 14067c478bd9Sstevel@tonic-gate (char *)NULL, (xdrproc_t)xdr_void, 14077c478bd9Sstevel@tonic-gate (char *)NULL, to); 14087c478bd9Sstevel@tonic-gate if (argc == 2) { 14097c478bd9Sstevel@tonic-gate /* Version number was known */ 14107c478bd9Sstevel@tonic-gate if (pstatus(client, prognum, versnum) < 0) 14117c478bd9Sstevel@tonic-gate failure = 1; 14127c478bd9Sstevel@tonic-gate (void) CLNT_DESTROY(client); 14137c478bd9Sstevel@tonic-gate if (failure) 14147c478bd9Sstevel@tonic-gate exit(1); 14157c478bd9Sstevel@tonic-gate return; 14167c478bd9Sstevel@tonic-gate } 14177c478bd9Sstevel@tonic-gate /* Version number not known */ 14187c478bd9Sstevel@tonic-gate (void) CLNT_CONTROL(client, CLSET_FD_NCLOSE, (char *)NULL); 14197c478bd9Sstevel@tonic-gate (void) CLNT_CONTROL(client, CLGET_FD, (char *)&fd); 14207c478bd9Sstevel@tonic-gate if (rpc_stat == RPC_PROGVERSMISMATCH) { 14217c478bd9Sstevel@tonic-gate clnt_geterr(client, &rpcerr); 14227c478bd9Sstevel@tonic-gate minvers = rpcerr.re_vers.low; 14237c478bd9Sstevel@tonic-gate maxvers = rpcerr.re_vers.high; 14247c478bd9Sstevel@tonic-gate } else if (rpc_stat == RPC_SUCCESS) { 14257c478bd9Sstevel@tonic-gate /* 14267c478bd9Sstevel@tonic-gate * Oh dear, it DOES support version 0. 14277c478bd9Sstevel@tonic-gate * Let's try version MAX_VERS. 14287c478bd9Sstevel@tonic-gate */ 14297c478bd9Sstevel@tonic-gate (void) CLNT_DESTROY(client); 14307c478bd9Sstevel@tonic-gate client = clnt_addr_create(address, nconf, prognum, MAX_VERS); 14317c478bd9Sstevel@tonic-gate rpc_stat = CLNT_CALL(client, NULLPROC, (xdrproc_t)xdr_void, 14327c478bd9Sstevel@tonic-gate (char *)NULL, (xdrproc_t)xdr_void, 14337c478bd9Sstevel@tonic-gate (char *)NULL, to); 14347c478bd9Sstevel@tonic-gate if (rpc_stat == RPC_PROGVERSMISMATCH) { 14357c478bd9Sstevel@tonic-gate clnt_geterr(client, &rpcerr); 14367c478bd9Sstevel@tonic-gate minvers = rpcerr.re_vers.low; 14377c478bd9Sstevel@tonic-gate maxvers = rpcerr.re_vers.high; 14387c478bd9Sstevel@tonic-gate } else if (rpc_stat == RPC_SUCCESS) { 14397c478bd9Sstevel@tonic-gate /* 14407c478bd9Sstevel@tonic-gate * It also supports version MAX_VERS. 14417c478bd9Sstevel@tonic-gate * Looks like we have a wise guy. 14427c478bd9Sstevel@tonic-gate * OK, we give them information on all 14437c478bd9Sstevel@tonic-gate * 4 billion versions they support... 14447c478bd9Sstevel@tonic-gate */ 14457c478bd9Sstevel@tonic-gate minvers = 0; 14467c478bd9Sstevel@tonic-gate maxvers = MAX_VERS; 14477c478bd9Sstevel@tonic-gate } else { 14487c478bd9Sstevel@tonic-gate (void) pstatus(client, prognum, MAX_VERS); 14497c478bd9Sstevel@tonic-gate exit(1); 14507c478bd9Sstevel@tonic-gate } 14517c478bd9Sstevel@tonic-gate } else { 14527c478bd9Sstevel@tonic-gate (void) pstatus(client, prognum, (ulong_t)0); 14537c478bd9Sstevel@tonic-gate exit(1); 14547c478bd9Sstevel@tonic-gate } 14557c478bd9Sstevel@tonic-gate (void) CLNT_DESTROY(client); 14567c478bd9Sstevel@tonic-gate for (versnum = minvers; versnum <= maxvers; versnum++) { 14577c478bd9Sstevel@tonic-gate client = clnt_addr_create(address, nconf, prognum, versnum); 14587c478bd9Sstevel@tonic-gate rpc_stat = CLNT_CALL(client, NULLPROC, (xdrproc_t)xdr_void, 14597c478bd9Sstevel@tonic-gate (char *)NULL, (xdrproc_t)xdr_void, 14607c478bd9Sstevel@tonic-gate (char *)NULL, to); 14617c478bd9Sstevel@tonic-gate if (pstatus(client, prognum, versnum) < 0) 14627c478bd9Sstevel@tonic-gate failure = 1; 14637c478bd9Sstevel@tonic-gate (void) CLNT_DESTROY(client); 14647c478bd9Sstevel@tonic-gate } 14657c478bd9Sstevel@tonic-gate (void) t_close(fd); 14667c478bd9Sstevel@tonic-gate if (failure) 14677c478bd9Sstevel@tonic-gate exit(1); 14687c478bd9Sstevel@tonic-gate } 14697c478bd9Sstevel@tonic-gate 14707c478bd9Sstevel@tonic-gate /* 14717c478bd9Sstevel@tonic-gate * If the version number is given, ping that (prog, vers); else try to find 14727c478bd9Sstevel@tonic-gate * the version numbers supported for that prog and ping all the versions. 14737c478bd9Sstevel@tonic-gate * Remote rpcbind is *contacted* for this service. The requests are 14747c478bd9Sstevel@tonic-gate * then sent directly to the services themselves. 14757c478bd9Sstevel@tonic-gate */ 14767c478bd9Sstevel@tonic-gate static void 14777c478bd9Sstevel@tonic-gate progping(netid, argc, argv) 14787c478bd9Sstevel@tonic-gate char *netid; 14797c478bd9Sstevel@tonic-gate int argc; 14807c478bd9Sstevel@tonic-gate char **argv; 14817c478bd9Sstevel@tonic-gate { 14827c478bd9Sstevel@tonic-gate CLIENT *client; 14837c478bd9Sstevel@tonic-gate struct timeval to; 14847c478bd9Sstevel@tonic-gate enum clnt_stat rpc_stat; 14857c478bd9Sstevel@tonic-gate ulong_t prognum, versnum, minvers, maxvers; 14867c478bd9Sstevel@tonic-gate struct rpc_err rpcerr; 14877c478bd9Sstevel@tonic-gate int failure = 0; 14887c478bd9Sstevel@tonic-gate struct netconfig *nconf; 14897c478bd9Sstevel@tonic-gate 14907c478bd9Sstevel@tonic-gate if (argc < 2 || argc > 3 || (netid == NULL)) { 14917c478bd9Sstevel@tonic-gate usage(); 14927c478bd9Sstevel@tonic-gate exit(1); 14937c478bd9Sstevel@tonic-gate } 14947c478bd9Sstevel@tonic-gate prognum = getprognum(argv[1]); 14957c478bd9Sstevel@tonic-gate if (argc == 2) { /* Version number not known */ 14967c478bd9Sstevel@tonic-gate /* 14977c478bd9Sstevel@tonic-gate * A call to version 0 should fail with a program/version 14987c478bd9Sstevel@tonic-gate * mismatch, and give us the range of versions supported. 14997c478bd9Sstevel@tonic-gate */ 15007c478bd9Sstevel@tonic-gate versnum = MIN_VERS; 15017c478bd9Sstevel@tonic-gate } else { 15027c478bd9Sstevel@tonic-gate versnum = getvers(argv[2]); 15037c478bd9Sstevel@tonic-gate } 15047c478bd9Sstevel@tonic-gate if (netid) { 15057c478bd9Sstevel@tonic-gate nconf = getnetconfigent(netid); 15067c478bd9Sstevel@tonic-gate if (nconf == (struct netconfig *)NULL) { 1507*791dfaa7SVallish Vaidyeshwara (void) fprintf(stderr, 1508*791dfaa7SVallish Vaidyeshwara "rpcinfo: Could not find %s\n", netid); 15097c478bd9Sstevel@tonic-gate exit(1); 15107c478bd9Sstevel@tonic-gate } 15117c478bd9Sstevel@tonic-gate client = clnt_tp_create(argv[0], prognum, versnum, nconf); 15127c478bd9Sstevel@tonic-gate } else { 15137c478bd9Sstevel@tonic-gate client = clnt_create(argv[0], prognum, versnum, "NETPATH"); 15147c478bd9Sstevel@tonic-gate } 15157c478bd9Sstevel@tonic-gate if (client == (CLIENT *)NULL) { 15167c478bd9Sstevel@tonic-gate clnt_pcreateerror("rpcinfo"); 15177c478bd9Sstevel@tonic-gate exit(1); 15187c478bd9Sstevel@tonic-gate } 15197c478bd9Sstevel@tonic-gate to.tv_sec = 10; 15207c478bd9Sstevel@tonic-gate to.tv_usec = 0; 15217c478bd9Sstevel@tonic-gate rpc_stat = CLNT_CALL(client, NULLPROC, (xdrproc_t)xdr_void, 15227c478bd9Sstevel@tonic-gate (char *)NULL, (xdrproc_t)xdr_void, 15237c478bd9Sstevel@tonic-gate (char *)NULL, to); 15247c478bd9Sstevel@tonic-gate if (argc == 3) { 15257c478bd9Sstevel@tonic-gate /* Version number was known */ 15267c478bd9Sstevel@tonic-gate if (pstatus(client, prognum, versnum) < 0) 15277c478bd9Sstevel@tonic-gate failure = 1; 15287c478bd9Sstevel@tonic-gate (void) CLNT_DESTROY(client); 15297c478bd9Sstevel@tonic-gate if (failure) 15307c478bd9Sstevel@tonic-gate exit(1); 15317c478bd9Sstevel@tonic-gate return; 15327c478bd9Sstevel@tonic-gate } 15337c478bd9Sstevel@tonic-gate /* Version number not known */ 15347c478bd9Sstevel@tonic-gate if (rpc_stat == RPC_PROGVERSMISMATCH) { 15357c478bd9Sstevel@tonic-gate clnt_geterr(client, &rpcerr); 15367c478bd9Sstevel@tonic-gate minvers = rpcerr.re_vers.low; 15377c478bd9Sstevel@tonic-gate maxvers = rpcerr.re_vers.high; 15387c478bd9Sstevel@tonic-gate } else if (rpc_stat == RPC_SUCCESS) { 15397c478bd9Sstevel@tonic-gate /* 15407c478bd9Sstevel@tonic-gate * Oh dear, it DOES support version 0. 15417c478bd9Sstevel@tonic-gate * Let's try version MAX_VERS. 15427c478bd9Sstevel@tonic-gate */ 15437c478bd9Sstevel@tonic-gate versnum = MAX_VERS; 15447c478bd9Sstevel@tonic-gate (void) CLNT_CONTROL(client, CLSET_VERS, (char *)&versnum); 15457c478bd9Sstevel@tonic-gate rpc_stat = CLNT_CALL(client, NULLPROC, 15467c478bd9Sstevel@tonic-gate (xdrproc_t)xdr_void, (char *)NULL, 15477c478bd9Sstevel@tonic-gate (xdrproc_t)xdr_void, (char *)NULL, to); 15487c478bd9Sstevel@tonic-gate if (rpc_stat == RPC_PROGVERSMISMATCH) { 15497c478bd9Sstevel@tonic-gate clnt_geterr(client, &rpcerr); 15507c478bd9Sstevel@tonic-gate minvers = rpcerr.re_vers.low; 15517c478bd9Sstevel@tonic-gate maxvers = rpcerr.re_vers.high; 15527c478bd9Sstevel@tonic-gate } else if (rpc_stat == RPC_SUCCESS) { 15537c478bd9Sstevel@tonic-gate /* 15547c478bd9Sstevel@tonic-gate * It also supports version MAX_VERS. 15557c478bd9Sstevel@tonic-gate * Looks like we have a wise guy. 15567c478bd9Sstevel@tonic-gate * OK, we give them information on all 15577c478bd9Sstevel@tonic-gate * 4 billion versions they support... 15587c478bd9Sstevel@tonic-gate */ 15597c478bd9Sstevel@tonic-gate minvers = 0; 15607c478bd9Sstevel@tonic-gate maxvers = MAX_VERS; 15617c478bd9Sstevel@tonic-gate } else { 15627c478bd9Sstevel@tonic-gate (void) pstatus(client, prognum, MAX_VERS); 15637c478bd9Sstevel@tonic-gate exit(1); 15647c478bd9Sstevel@tonic-gate } 15657c478bd9Sstevel@tonic-gate } else { 15667c478bd9Sstevel@tonic-gate (void) pstatus(client, prognum, (ulong_t)0); 15677c478bd9Sstevel@tonic-gate exit(1); 15687c478bd9Sstevel@tonic-gate } 15697c478bd9Sstevel@tonic-gate for (versnum = minvers; versnum <= maxvers; versnum++) { 15707c478bd9Sstevel@tonic-gate (void) CLNT_CONTROL(client, CLSET_VERS, (char *)&versnum); 15717c478bd9Sstevel@tonic-gate rpc_stat = CLNT_CALL(client, NULLPROC, (xdrproc_t)xdr_void, 15727c478bd9Sstevel@tonic-gate (char *)NULL, (xdrproc_t)xdr_void, 15737c478bd9Sstevel@tonic-gate (char *)NULL, to); 15747c478bd9Sstevel@tonic-gate if (pstatus(client, prognum, versnum) < 0) 15757c478bd9Sstevel@tonic-gate failure = 1; 15767c478bd9Sstevel@tonic-gate } 15777c478bd9Sstevel@tonic-gate (void) CLNT_DESTROY(client); 15787c478bd9Sstevel@tonic-gate if (failure) 15797c478bd9Sstevel@tonic-gate exit(1); 15807c478bd9Sstevel@tonic-gate } 15817c478bd9Sstevel@tonic-gate 15827c478bd9Sstevel@tonic-gate static void 15837c478bd9Sstevel@tonic-gate usage() 15847c478bd9Sstevel@tonic-gate { 1585*791dfaa7SVallish Vaidyeshwara (void) fprintf(stderr, "Usage: rpcinfo [-m | -s] [host]\n"); 15867c478bd9Sstevel@tonic-gate #ifdef PORTMAP 1587*791dfaa7SVallish Vaidyeshwara (void) fprintf(stderr, " rpcinfo -p [host]\n"); 15887c478bd9Sstevel@tonic-gate #endif 1589*791dfaa7SVallish Vaidyeshwara (void) fprintf(stderr, 1590*791dfaa7SVallish Vaidyeshwara " rpcinfo -T netid host prognum [versnum]\n"); 1591*791dfaa7SVallish Vaidyeshwara (void) fprintf(stderr, " rpcinfo -l host prognum versnum\n"); 15927c478bd9Sstevel@tonic-gate #ifdef PORTMAP 1593*791dfaa7SVallish Vaidyeshwara (void) fprintf(stderr, 15947c478bd9Sstevel@tonic-gate " rpcinfo [-n portnum] -u | -t host prognum [versnum]\n"); 15957c478bd9Sstevel@tonic-gate #endif 1596*791dfaa7SVallish Vaidyeshwara (void) fprintf(stderr, 15977c478bd9Sstevel@tonic-gate " rpcinfo -a serv_address -T netid prognum [version]\n"); 1598*791dfaa7SVallish Vaidyeshwara (void) fprintf(stderr, " rpcinfo -b prognum versnum\n"); 1599*791dfaa7SVallish Vaidyeshwara (void) fprintf(stderr, 1600*791dfaa7SVallish Vaidyeshwara " rpcinfo -d [-T netid] prognum versnum\n"); 16017c478bd9Sstevel@tonic-gate } 16027c478bd9Sstevel@tonic-gate 16037c478bd9Sstevel@tonic-gate static ulong_t 16047c478bd9Sstevel@tonic-gate getprognum (arg) 16057c478bd9Sstevel@tonic-gate char *arg; 16067c478bd9Sstevel@tonic-gate { 16077c478bd9Sstevel@tonic-gate char *strptr; 16087c478bd9Sstevel@tonic-gate register struct rpcent *rpc; 16097c478bd9Sstevel@tonic-gate register ulong_t prognum; 16107c478bd9Sstevel@tonic-gate char *tptr = arg; 16117c478bd9Sstevel@tonic-gate 16127c478bd9Sstevel@tonic-gate while (*tptr && isdigit(*tptr++)); 16137c478bd9Sstevel@tonic-gate if (*tptr || isalpha(*(tptr - 1))) { 16147c478bd9Sstevel@tonic-gate rpc = getrpcbyname(arg); 16157c478bd9Sstevel@tonic-gate if (rpc == NULL) { 1616*791dfaa7SVallish Vaidyeshwara (void) fprintf(stderr, 1617*791dfaa7SVallish Vaidyeshwara "rpcinfo: %s is unknown service\n", arg); 16187c478bd9Sstevel@tonic-gate exit(1); 16197c478bd9Sstevel@tonic-gate } 16207c478bd9Sstevel@tonic-gate prognum = rpc->r_number; 16217c478bd9Sstevel@tonic-gate } else { 16227c478bd9Sstevel@tonic-gate prognum = strtol(arg, &strptr, 10); 16237c478bd9Sstevel@tonic-gate if (strptr == arg || *strptr != '\0') { 1624*791dfaa7SVallish Vaidyeshwara (void) fprintf(stderr, 16257c478bd9Sstevel@tonic-gate "rpcinfo: %s is illegal program number\n", arg); 16267c478bd9Sstevel@tonic-gate exit(1); 16277c478bd9Sstevel@tonic-gate } 16287c478bd9Sstevel@tonic-gate } 16297c478bd9Sstevel@tonic-gate return (prognum); 16307c478bd9Sstevel@tonic-gate } 16317c478bd9Sstevel@tonic-gate 16327c478bd9Sstevel@tonic-gate static ulong_t 16337c478bd9Sstevel@tonic-gate getvers(arg) 16347c478bd9Sstevel@tonic-gate char *arg; 16357c478bd9Sstevel@tonic-gate { 16367c478bd9Sstevel@tonic-gate char *strptr; 16377c478bd9Sstevel@tonic-gate register ulong_t vers; 16387c478bd9Sstevel@tonic-gate 16397c478bd9Sstevel@tonic-gate vers = (int)strtol(arg, &strptr, 10); 16407c478bd9Sstevel@tonic-gate if (strptr == arg || *strptr != '\0') { 1641*791dfaa7SVallish Vaidyeshwara (void) fprintf(stderr, 1642*791dfaa7SVallish Vaidyeshwara "rpcinfo: %s is illegal version number\n", arg); 16437c478bd9Sstevel@tonic-gate exit(1); 16447c478bd9Sstevel@tonic-gate } 16457c478bd9Sstevel@tonic-gate return (vers); 16467c478bd9Sstevel@tonic-gate } 16477c478bd9Sstevel@tonic-gate 16487c478bd9Sstevel@tonic-gate /* 16497c478bd9Sstevel@tonic-gate * This routine should take a pointer to an "rpc_err" structure, rather than 16507c478bd9Sstevel@tonic-gate * a pointer to a CLIENT structure, but "clnt_perror" takes a pointer to 16517c478bd9Sstevel@tonic-gate * a CLIENT structure rather than a pointer to an "rpc_err" structure. 16527c478bd9Sstevel@tonic-gate * As such, we have to keep the CLIENT structure around in order to print 16537c478bd9Sstevel@tonic-gate * a good error message. 16547c478bd9Sstevel@tonic-gate */ 16557c478bd9Sstevel@tonic-gate static int 16567c478bd9Sstevel@tonic-gate pstatus(client, prog, vers) 16577c478bd9Sstevel@tonic-gate register CLIENT *client; 16587c478bd9Sstevel@tonic-gate ulong_t prog; 16597c478bd9Sstevel@tonic-gate ulong_t vers; 16607c478bd9Sstevel@tonic-gate { 16617c478bd9Sstevel@tonic-gate struct rpc_err rpcerr; 16627c478bd9Sstevel@tonic-gate 16637c478bd9Sstevel@tonic-gate clnt_geterr(client, &rpcerr); 16647c478bd9Sstevel@tonic-gate if (rpcerr.re_status != RPC_SUCCESS) { 16657c478bd9Sstevel@tonic-gate clnt_perror(client, "rpcinfo"); 1666*791dfaa7SVallish Vaidyeshwara (void) printf("program %lu version %lu is not available\n", 16677c478bd9Sstevel@tonic-gate prog, vers); 16687c478bd9Sstevel@tonic-gate return (-1); 16697c478bd9Sstevel@tonic-gate } else { 1670*791dfaa7SVallish Vaidyeshwara (void) printf("program %lu version %lu ready and waiting\n", 16717c478bd9Sstevel@tonic-gate prog, vers); 16727c478bd9Sstevel@tonic-gate return (0); 16737c478bd9Sstevel@tonic-gate } 16747c478bd9Sstevel@tonic-gate } 16757c478bd9Sstevel@tonic-gate 16767c478bd9Sstevel@tonic-gate static CLIENT * 16777c478bd9Sstevel@tonic-gate clnt_rpcbind_create(host, rpcbversnum, targaddr) 16787c478bd9Sstevel@tonic-gate char *host; 16797c478bd9Sstevel@tonic-gate ulong_t rpcbversnum; 16807c478bd9Sstevel@tonic-gate struct netbuf **targaddr; 16817c478bd9Sstevel@tonic-gate { 16827c478bd9Sstevel@tonic-gate static char *tlist[3] = { 16837c478bd9Sstevel@tonic-gate "circuit_n", "circuit_v", "datagram_v" 16847c478bd9Sstevel@tonic-gate }; 16857c478bd9Sstevel@tonic-gate int i; 16867c478bd9Sstevel@tonic-gate struct netconfig *nconf; 16877c478bd9Sstevel@tonic-gate CLIENT *clnt = NULL; 16887c478bd9Sstevel@tonic-gate void *handle; 16897c478bd9Sstevel@tonic-gate 16907c478bd9Sstevel@tonic-gate rpc_createerr.cf_stat = RPC_SUCCESS; 16917c478bd9Sstevel@tonic-gate for (i = 0; i < 3; i++) { 16927c478bd9Sstevel@tonic-gate if ((handle = __rpc_setconf(tlist[i])) == NULL) 16937c478bd9Sstevel@tonic-gate continue; 16947c478bd9Sstevel@tonic-gate while (clnt == (CLIENT *)NULL) { 16957c478bd9Sstevel@tonic-gate if ((nconf = __rpc_getconf(handle)) == NULL) { 16967c478bd9Sstevel@tonic-gate if (rpc_createerr.cf_stat == RPC_SUCCESS) 16977c478bd9Sstevel@tonic-gate rpc_createerr.cf_stat = RPC_UNKNOWNPROTO; 16987c478bd9Sstevel@tonic-gate break; 16997c478bd9Sstevel@tonic-gate } 17007c478bd9Sstevel@tonic-gate clnt = getclnthandle(host, nconf, rpcbversnum, 17017c478bd9Sstevel@tonic-gate targaddr); 17027c478bd9Sstevel@tonic-gate } 17037c478bd9Sstevel@tonic-gate if (clnt) 17047c478bd9Sstevel@tonic-gate break; 17057c478bd9Sstevel@tonic-gate __rpc_endconf(handle); 17067c478bd9Sstevel@tonic-gate } 17077c478bd9Sstevel@tonic-gate return (clnt); 17087c478bd9Sstevel@tonic-gate } 17097c478bd9Sstevel@tonic-gate 17107c478bd9Sstevel@tonic-gate static CLIENT* 17117c478bd9Sstevel@tonic-gate getclnthandle(host, nconf, rpcbversnum, targaddr) 17127c478bd9Sstevel@tonic-gate char *host; 17137c478bd9Sstevel@tonic-gate struct netconfig *nconf; 17147c478bd9Sstevel@tonic-gate ulong_t rpcbversnum; 17157c478bd9Sstevel@tonic-gate struct netbuf **targaddr; 17167c478bd9Sstevel@tonic-gate { 17177c478bd9Sstevel@tonic-gate struct netbuf *addr; 17187c478bd9Sstevel@tonic-gate struct nd_addrlist *nas; 17197c478bd9Sstevel@tonic-gate struct nd_hostserv rpcbind_hs; 17207c478bd9Sstevel@tonic-gate CLIENT *client = NULL; 17217c478bd9Sstevel@tonic-gate 17227c478bd9Sstevel@tonic-gate /* Get the address of the rpcbind */ 17237c478bd9Sstevel@tonic-gate rpcbind_hs.h_host = host; 17247c478bd9Sstevel@tonic-gate rpcbind_hs.h_serv = "rpcbind"; 17257c478bd9Sstevel@tonic-gate if (netdir_getbyname(nconf, &rpcbind_hs, &nas)) { 17267c478bd9Sstevel@tonic-gate rpc_createerr.cf_stat = RPC_N2AXLATEFAILURE; 17277c478bd9Sstevel@tonic-gate return (NULL); 17287c478bd9Sstevel@tonic-gate } 17297c478bd9Sstevel@tonic-gate addr = nas->n_addrs; 17307c478bd9Sstevel@tonic-gate client = clnt_tli_create(RPC_ANYFD, nconf, addr, RPCBPROG, 17317c478bd9Sstevel@tonic-gate rpcbversnum, 0, 0); 17327c478bd9Sstevel@tonic-gate if (client) { 17337c478bd9Sstevel@tonic-gate if (targaddr != NULL) { 17347c478bd9Sstevel@tonic-gate *targaddr = 17357c478bd9Sstevel@tonic-gate (struct netbuf *)malloc(sizeof (struct netbuf)); 17367c478bd9Sstevel@tonic-gate if (*targaddr != NULL) { 17377c478bd9Sstevel@tonic-gate (*targaddr)->maxlen = addr->maxlen; 17387c478bd9Sstevel@tonic-gate (*targaddr)->len = addr->len; 17397c478bd9Sstevel@tonic-gate (*targaddr)->buf = (char *)malloc(addr->len); 17407c478bd9Sstevel@tonic-gate if ((*targaddr)->buf != NULL) { 1741*791dfaa7SVallish Vaidyeshwara (void) memcpy((*targaddr)->buf, 1742*791dfaa7SVallish Vaidyeshwara addr->buf, addr->len); 17437c478bd9Sstevel@tonic-gate } 17447c478bd9Sstevel@tonic-gate } 17457c478bd9Sstevel@tonic-gate } 17467c478bd9Sstevel@tonic-gate } else { 17477c478bd9Sstevel@tonic-gate if (rpc_createerr.cf_stat == RPC_TLIERROR) { 17487c478bd9Sstevel@tonic-gate /* 17497c478bd9Sstevel@tonic-gate * Assume that the other system is dead; this is a 17507c478bd9Sstevel@tonic-gate * better error to display to the user. 17517c478bd9Sstevel@tonic-gate */ 17527c478bd9Sstevel@tonic-gate rpc_createerr.cf_stat = RPC_RPCBFAILURE; 17537c478bd9Sstevel@tonic-gate rpc_createerr.cf_error.re_status = RPC_FAILED; 17547c478bd9Sstevel@tonic-gate } 17557c478bd9Sstevel@tonic-gate } 17567c478bd9Sstevel@tonic-gate netdir_free((char *)nas, ND_ADDRLIST); 17577c478bd9Sstevel@tonic-gate return (client); 17587c478bd9Sstevel@tonic-gate } 17597c478bd9Sstevel@tonic-gate 17607c478bd9Sstevel@tonic-gate static void 17617c478bd9Sstevel@tonic-gate print_rmtcallstat(rtype, infp) 17627c478bd9Sstevel@tonic-gate int rtype; 17637c478bd9Sstevel@tonic-gate rpcb_stat *infp; 17647c478bd9Sstevel@tonic-gate { 17657c478bd9Sstevel@tonic-gate register rpcbs_rmtcalllist_ptr pr; 17667c478bd9Sstevel@tonic-gate struct rpcent *rpc; 17677c478bd9Sstevel@tonic-gate 17687c478bd9Sstevel@tonic-gate if (rtype == RPCBVERS_4_STAT) 1769*791dfaa7SVallish Vaidyeshwara (void) printf( 17707c478bd9Sstevel@tonic-gate "prog\t\tvers\tproc\tnetid\tindirect success failure\n"); 17717c478bd9Sstevel@tonic-gate else 1772*791dfaa7SVallish Vaidyeshwara (void) printf("prog\t\tvers\tproc\tnetid\tsuccess\tfailure\n"); 17737c478bd9Sstevel@tonic-gate for (pr = infp->rmtinfo; pr; pr = pr->next) { 17747c478bd9Sstevel@tonic-gate rpc = getrpcbynumber(pr->prog); 17757c478bd9Sstevel@tonic-gate if (rpc) 1776*791dfaa7SVallish Vaidyeshwara (void) printf("%-16s", rpc->r_name); 17777c478bd9Sstevel@tonic-gate else 1778*791dfaa7SVallish Vaidyeshwara #if defined(_LP64) || defined(_I32LPx) 1779*791dfaa7SVallish Vaidyeshwara (void) printf("%-16u", pr->prog); 1780*791dfaa7SVallish Vaidyeshwara (void) printf("%u\t%u\t%-7s ", 1781*791dfaa7SVallish Vaidyeshwara #else 1782*791dfaa7SVallish Vaidyeshwara (void) printf("%-16lu", pr->prog); 1783*791dfaa7SVallish Vaidyeshwara (void) printf("%lu\t%lu\t%-7s ", 1784*791dfaa7SVallish Vaidyeshwara #endif 17857c478bd9Sstevel@tonic-gate pr->vers, pr->proc, pr->netid); 17867c478bd9Sstevel@tonic-gate if (rtype == RPCBVERS_4_STAT) 1787*791dfaa7SVallish Vaidyeshwara (void) printf("%d\t ", pr->indirect); 1788*791dfaa7SVallish Vaidyeshwara (void) printf("%d\t%d\n", pr->success, pr->failure); 17897c478bd9Sstevel@tonic-gate } 17907c478bd9Sstevel@tonic-gate } 17917c478bd9Sstevel@tonic-gate 17927c478bd9Sstevel@tonic-gate static void 1793*791dfaa7SVallish Vaidyeshwara /* LINTED E_FUNC_ARG_UNUSED for 1st arg rtype */ 17947c478bd9Sstevel@tonic-gate print_getaddrstat(rtype, infp) 17957c478bd9Sstevel@tonic-gate int rtype; 17967c478bd9Sstevel@tonic-gate rpcb_stat *infp; 17977c478bd9Sstevel@tonic-gate { 17987c478bd9Sstevel@tonic-gate rpcbs_addrlist_ptr al; 17997c478bd9Sstevel@tonic-gate register struct rpcent *rpc; 18007c478bd9Sstevel@tonic-gate 1801*791dfaa7SVallish Vaidyeshwara (void) printf("prog\t\tvers\tnetid\t success\tfailure\n"); 18027c478bd9Sstevel@tonic-gate for (al = infp->addrinfo; al; al = al->next) { 18037c478bd9Sstevel@tonic-gate rpc = getrpcbynumber(al->prog); 18047c478bd9Sstevel@tonic-gate if (rpc) 1805*791dfaa7SVallish Vaidyeshwara (void) printf("%-16s", rpc->r_name); 18067c478bd9Sstevel@tonic-gate else 1807*791dfaa7SVallish Vaidyeshwara #if defined(_LP64) || defined(_I32LPx) 1808*791dfaa7SVallish Vaidyeshwara (void) printf("%-16u", al->prog); 1809*791dfaa7SVallish Vaidyeshwara (void) printf("%u\t%-9s %-12d\t%d\n", 1810*791dfaa7SVallish Vaidyeshwara #else 1811*791dfaa7SVallish Vaidyeshwara (void) printf("%-16lu", al->prog); 1812*791dfaa7SVallish Vaidyeshwara (void) printf("%lu\t%-9s %-12d\t%d\n", 1813*791dfaa7SVallish Vaidyeshwara #endif 18147c478bd9Sstevel@tonic-gate al->vers, al->netid, 18157c478bd9Sstevel@tonic-gate al->success, al->failure); 18167c478bd9Sstevel@tonic-gate } 18177c478bd9Sstevel@tonic-gate } 18187c478bd9Sstevel@tonic-gate 18197c478bd9Sstevel@tonic-gate static char * 18207c478bd9Sstevel@tonic-gate spaces(howmany) 18217c478bd9Sstevel@tonic-gate int howmany; 18227c478bd9Sstevel@tonic-gate { 18237c478bd9Sstevel@tonic-gate static char space_array[] = /* 64 spaces */ 18247c478bd9Sstevel@tonic-gate " "; 18257c478bd9Sstevel@tonic-gate 18267c478bd9Sstevel@tonic-gate if (howmany <= 0 || howmany > sizeof (space_array)) { 18277c478bd9Sstevel@tonic-gate return (""); 18287c478bd9Sstevel@tonic-gate } 18297c478bd9Sstevel@tonic-gate return (&space_array[sizeof (space_array) - howmany - 1]); 18307c478bd9Sstevel@tonic-gate } 1831