17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 67c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 77c478bd9Sstevel@tonic-gate * with the License. 87c478bd9Sstevel@tonic-gate * 97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 127c478bd9Sstevel@tonic-gate * and limitations under the License. 137c478bd9Sstevel@tonic-gate * 147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 197c478bd9Sstevel@tonic-gate * 207c478bd9Sstevel@tonic-gate * CDDL HEADER END 217c478bd9Sstevel@tonic-gate * 22*653c780cSssdevi * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate * Use is subject to license terms. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */ 267c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 277c478bd9Sstevel@tonic-gate /* 287c478bd9Sstevel@tonic-gate * University Copyright- Copyright (c) 1982, 1986, 1988 297c478bd9Sstevel@tonic-gate * The Regents of the University of California 307c478bd9Sstevel@tonic-gate * All Rights Reserved 317c478bd9Sstevel@tonic-gate * 327c478bd9Sstevel@tonic-gate * University Acknowledgment- Portions of this document are derived from 337c478bd9Sstevel@tonic-gate * software developed by the University of California, Berkeley, and its 347c478bd9Sstevel@tonic-gate * contributors. 357c478bd9Sstevel@tonic-gate */ 367c478bd9Sstevel@tonic-gate 377c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 387c478bd9Sstevel@tonic-gate 397c478bd9Sstevel@tonic-gate /* 407c478bd9Sstevel@tonic-gate * rpcinfo: ping a particular rpc program 417c478bd9Sstevel@tonic-gate * or dump the the registered programs on the remote machine. 427c478bd9Sstevel@tonic-gate */ 437c478bd9Sstevel@tonic-gate 447c478bd9Sstevel@tonic-gate /* 457c478bd9Sstevel@tonic-gate * We are for now defining PORTMAP here. It doesnt even compile 467c478bd9Sstevel@tonic-gate * unless it is defined. 477c478bd9Sstevel@tonic-gate */ 487c478bd9Sstevel@tonic-gate #ifndef PORTMAP 497c478bd9Sstevel@tonic-gate #define PORTMAP 507c478bd9Sstevel@tonic-gate #endif 517c478bd9Sstevel@tonic-gate 527c478bd9Sstevel@tonic-gate /* 537c478bd9Sstevel@tonic-gate * If PORTMAP is defined, rpcinfo will talk to both portmapper and 547c478bd9Sstevel@tonic-gate * rpcbind programs; else it talks only to rpcbind. In the latter case 557c478bd9Sstevel@tonic-gate * all the portmapper specific options such as -u, -t, -p become void. 567c478bd9Sstevel@tonic-gate */ 577c478bd9Sstevel@tonic-gate #include <rpc/rpc.h> 587c478bd9Sstevel@tonic-gate #include <stdio.h> 597c478bd9Sstevel@tonic-gate #include <rpc/rpcb_prot.h> 607c478bd9Sstevel@tonic-gate #include <rpc/nettype.h> 617c478bd9Sstevel@tonic-gate #include <netdir.h> 627c478bd9Sstevel@tonic-gate #include <rpc/rpcent.h> 637c478bd9Sstevel@tonic-gate #include <sys/utsname.h> 647c478bd9Sstevel@tonic-gate #include <stdlib.h> 657c478bd9Sstevel@tonic-gate #include <string.h> 667c478bd9Sstevel@tonic-gate 677c478bd9Sstevel@tonic-gate #ifdef PORTMAP /* Support for version 2 portmapper */ 687c478bd9Sstevel@tonic-gate #include <netinet/in.h> 697c478bd9Sstevel@tonic-gate #include <sys/socket.h> 707c478bd9Sstevel@tonic-gate #include <netdb.h> 717c478bd9Sstevel@tonic-gate #include <arpa/inet.h> 727c478bd9Sstevel@tonic-gate #include <rpc/pmap_prot.h> 737c478bd9Sstevel@tonic-gate #include <rpc/pmap_clnt.h> 747c478bd9Sstevel@tonic-gate #endif 757c478bd9Sstevel@tonic-gate 767c478bd9Sstevel@tonic-gate #define MAXHOSTLEN 256 777c478bd9Sstevel@tonic-gate #define MIN_VERS ((ulong_t)0) 78*653c780cSssdevi #define MAX_VERS (4294967295UL) 797c478bd9Sstevel@tonic-gate #define UNKNOWN "unknown" 807c478bd9Sstevel@tonic-gate 817c478bd9Sstevel@tonic-gate #define MAX(a, b) (((a) > (b)) ? (a) : (b)) 827c478bd9Sstevel@tonic-gate 837c478bd9Sstevel@tonic-gate extern int t_errno; 847c478bd9Sstevel@tonic-gate extern long strtol(); 857c478bd9Sstevel@tonic-gate static char *spaces(); 867c478bd9Sstevel@tonic-gate 877c478bd9Sstevel@tonic-gate #ifdef PORTMAP 887c478bd9Sstevel@tonic-gate static void ip_ping(/*ushort_t portflag, char *trans, 897c478bd9Sstevel@tonic-gate int argc, char **argv*/); 907c478bd9Sstevel@tonic-gate static CLIENT *clnt_com_create(/* struct sockaddr_in *addr, long prog, 917c478bd9Sstevel@tonic-gate long vers, int *fd, char *trans*/); 927c478bd9Sstevel@tonic-gate static void pmapdump(/*int argc, char **argv*/); 937c478bd9Sstevel@tonic-gate static void get_inet_address(/*struct sockaddr_in *addr, char *host*/); 947c478bd9Sstevel@tonic-gate #endif 957c478bd9Sstevel@tonic-gate 967c478bd9Sstevel@tonic-gate static bool_t reply_proc(/*void *res, struct netbuf *who*, 977c478bd9Sstevel@tonic-gate struct netconfig *nconf*/); 987c478bd9Sstevel@tonic-gate static void brdcst(/*int argc, char **argv*/); 997c478bd9Sstevel@tonic-gate static void addrping(/*char *address, char *netid, 1007c478bd9Sstevel@tonic-gate int argc, char **argv*/); 1017c478bd9Sstevel@tonic-gate static void progping(/* char *netid, int argc, char **argv*/); 1027c478bd9Sstevel@tonic-gate static CLIENT *clnt_addr_create(/* char *addr, struct netconfig *nconf, 1037c478bd9Sstevel@tonic-gate long prog, long vers*/); 1047c478bd9Sstevel@tonic-gate static CLIENT *clnt_rpcbind_create(/* char *host, int vers */); 1057c478bd9Sstevel@tonic-gate static CLIENT *getclnthandle(/* host, nconf, rpcbversnum */); 1067c478bd9Sstevel@tonic-gate static int pstatus(/*CLIENT *client, ulong_t prognum, ulong_t vers*/); 1077c478bd9Sstevel@tonic-gate static void rpcbdump(/*char *netid, int argc, char **argv*/); 1087c478bd9Sstevel@tonic-gate static void rpcbgetstat(/* int argc, char **argv*/); 1097c478bd9Sstevel@tonic-gate static void rpcbaddrlist(/*char *netid, int argc, char **argv*/); 1107c478bd9Sstevel@tonic-gate static void deletereg(/*char *netid, int argc, char **argv */); 1117c478bd9Sstevel@tonic-gate static void print_rmtcallstat(/* rtype, infp */); 1127c478bd9Sstevel@tonic-gate static void print_getaddrstat(/* rtype, infp */); 1137c478bd9Sstevel@tonic-gate static void usage(/*void*/); 1147c478bd9Sstevel@tonic-gate static ulong_t getprognum(/*char *arg*/); 1157c478bd9Sstevel@tonic-gate static ulong_t getvers(/*char *arg*/); 1167c478bd9Sstevel@tonic-gate 1177c478bd9Sstevel@tonic-gate /* 1187c478bd9Sstevel@tonic-gate * Functions to be performed. 1197c478bd9Sstevel@tonic-gate */ 1207c478bd9Sstevel@tonic-gate #define NONE 0 /* no function */ 1217c478bd9Sstevel@tonic-gate #define PMAPDUMP 1 /* dump portmapper registrations */ 1227c478bd9Sstevel@tonic-gate #define TCPPING 2 /* ping TCP service */ 1237c478bd9Sstevel@tonic-gate #define UDPPING 3 /* ping UDP service */ 1247c478bd9Sstevel@tonic-gate #define BROADCAST 4 /* ping broadcast service */ 1257c478bd9Sstevel@tonic-gate #define DELETES 5 /* delete registration for the service */ 1267c478bd9Sstevel@tonic-gate #define ADDRPING 6 /* pings at the given address */ 1277c478bd9Sstevel@tonic-gate #define PROGPING 7 /* pings a program on a given host */ 1287c478bd9Sstevel@tonic-gate #define RPCBDUMP 8 /* dump rpcbind registrations */ 1297c478bd9Sstevel@tonic-gate #define RPCBDUMP_SHORT 9 /* dump rpcbind registrations - short version */ 1307c478bd9Sstevel@tonic-gate #define RPCBADDRLIST 10 /* dump addr list about one prog */ 1317c478bd9Sstevel@tonic-gate #define RPCBGETSTAT 11 /* Get statistics */ 1327c478bd9Sstevel@tonic-gate 1337c478bd9Sstevel@tonic-gate struct netidlist { 1347c478bd9Sstevel@tonic-gate char *netid; 1357c478bd9Sstevel@tonic-gate struct netidlist *next; 1367c478bd9Sstevel@tonic-gate }; 1377c478bd9Sstevel@tonic-gate 1387c478bd9Sstevel@tonic-gate struct verslist { 1397c478bd9Sstevel@tonic-gate int vers; 1407c478bd9Sstevel@tonic-gate struct verslist *next; 1417c478bd9Sstevel@tonic-gate }; 1427c478bd9Sstevel@tonic-gate 1437c478bd9Sstevel@tonic-gate struct rpcbdump_short { 1447c478bd9Sstevel@tonic-gate ulong_t prog; 1457c478bd9Sstevel@tonic-gate struct verslist *vlist; 1467c478bd9Sstevel@tonic-gate struct netidlist *nlist; 1477c478bd9Sstevel@tonic-gate struct rpcbdump_short *next; 1487c478bd9Sstevel@tonic-gate char *owner; 1497c478bd9Sstevel@tonic-gate }; 1507c478bd9Sstevel@tonic-gate 1517c478bd9Sstevel@tonic-gate 1527c478bd9Sstevel@tonic-gate char *loopback_netid = NULL; 1537c478bd9Sstevel@tonic-gate struct netconfig *loopback_nconf; 1547c478bd9Sstevel@tonic-gate 1557c478bd9Sstevel@tonic-gate int 1567c478bd9Sstevel@tonic-gate main(argc, argv) 1577c478bd9Sstevel@tonic-gate int argc; 1587c478bd9Sstevel@tonic-gate char **argv; 1597c478bd9Sstevel@tonic-gate { 1607c478bd9Sstevel@tonic-gate register int c; 1617c478bd9Sstevel@tonic-gate extern char *optarg; 1627c478bd9Sstevel@tonic-gate extern int optind; 1637c478bd9Sstevel@tonic-gate int errflg; 1647c478bd9Sstevel@tonic-gate int function; 1657c478bd9Sstevel@tonic-gate char *netid = NULL; 1667c478bd9Sstevel@tonic-gate char *address = NULL; 1677c478bd9Sstevel@tonic-gate void *handle; 1687c478bd9Sstevel@tonic-gate #ifdef PORTMAP 1697c478bd9Sstevel@tonic-gate char *strptr; 1707c478bd9Sstevel@tonic-gate ushort_t portnum = 0; 1717c478bd9Sstevel@tonic-gate #endif 1727c478bd9Sstevel@tonic-gate 1737c478bd9Sstevel@tonic-gate function = NONE; 1747c478bd9Sstevel@tonic-gate errflg = 0; 1757c478bd9Sstevel@tonic-gate #ifdef PORTMAP 1767c478bd9Sstevel@tonic-gate while ((c = getopt(argc, argv, "a:bdlmn:pstT:u")) != EOF) { 1777c478bd9Sstevel@tonic-gate #else 1787c478bd9Sstevel@tonic-gate while ((c = getopt(argc, argv, "a:bdlmn:sT:")) != EOF) { 1797c478bd9Sstevel@tonic-gate #endif 1807c478bd9Sstevel@tonic-gate switch (c) { 1817c478bd9Sstevel@tonic-gate #ifdef PORTMAP 1827c478bd9Sstevel@tonic-gate case 'p': 1837c478bd9Sstevel@tonic-gate if (function != NONE) 1847c478bd9Sstevel@tonic-gate errflg = 1; 1857c478bd9Sstevel@tonic-gate else 1867c478bd9Sstevel@tonic-gate function = PMAPDUMP; 1877c478bd9Sstevel@tonic-gate break; 1887c478bd9Sstevel@tonic-gate 1897c478bd9Sstevel@tonic-gate case 't': 1907c478bd9Sstevel@tonic-gate if (function != NONE) 1917c478bd9Sstevel@tonic-gate errflg = 1; 1927c478bd9Sstevel@tonic-gate else 1937c478bd9Sstevel@tonic-gate function = TCPPING; 1947c478bd9Sstevel@tonic-gate break; 1957c478bd9Sstevel@tonic-gate 1967c478bd9Sstevel@tonic-gate case 'u': 1977c478bd9Sstevel@tonic-gate if (function != NONE) 1987c478bd9Sstevel@tonic-gate errflg = 1; 1997c478bd9Sstevel@tonic-gate else 2007c478bd9Sstevel@tonic-gate function = UDPPING; 2017c478bd9Sstevel@tonic-gate break; 2027c478bd9Sstevel@tonic-gate 2037c478bd9Sstevel@tonic-gate case 'n': 2047c478bd9Sstevel@tonic-gate portnum = (ushort_t)strtol(optarg, &strptr, 10); 2057c478bd9Sstevel@tonic-gate if (strptr == optarg || *strptr != '\0') { 2067c478bd9Sstevel@tonic-gate fprintf(stderr, 2077c478bd9Sstevel@tonic-gate "rpcinfo: %s is illegal port number\n", 2087c478bd9Sstevel@tonic-gate optarg); 2097c478bd9Sstevel@tonic-gate exit(1); 2107c478bd9Sstevel@tonic-gate } 2117c478bd9Sstevel@tonic-gate break; 2127c478bd9Sstevel@tonic-gate #endif 2137c478bd9Sstevel@tonic-gate case 'a': 2147c478bd9Sstevel@tonic-gate address = optarg; 2157c478bd9Sstevel@tonic-gate if (function != NONE) 2167c478bd9Sstevel@tonic-gate errflg = 1; 2177c478bd9Sstevel@tonic-gate else 2187c478bd9Sstevel@tonic-gate function = ADDRPING; 2197c478bd9Sstevel@tonic-gate break; 2207c478bd9Sstevel@tonic-gate case 'b': 2217c478bd9Sstevel@tonic-gate if (function != NONE) 2227c478bd9Sstevel@tonic-gate errflg = 1; 2237c478bd9Sstevel@tonic-gate else 2247c478bd9Sstevel@tonic-gate function = BROADCAST; 2257c478bd9Sstevel@tonic-gate break; 2267c478bd9Sstevel@tonic-gate 2277c478bd9Sstevel@tonic-gate case 'd': 2287c478bd9Sstevel@tonic-gate if (function != NONE) 2297c478bd9Sstevel@tonic-gate errflg = 1; 2307c478bd9Sstevel@tonic-gate else 2317c478bd9Sstevel@tonic-gate function = DELETES; 2327c478bd9Sstevel@tonic-gate break; 2337c478bd9Sstevel@tonic-gate 2347c478bd9Sstevel@tonic-gate case 'l': 2357c478bd9Sstevel@tonic-gate if (function != NONE) 2367c478bd9Sstevel@tonic-gate errflg = 1; 2377c478bd9Sstevel@tonic-gate else 2387c478bd9Sstevel@tonic-gate function = RPCBADDRLIST; 2397c478bd9Sstevel@tonic-gate break; 2407c478bd9Sstevel@tonic-gate 2417c478bd9Sstevel@tonic-gate case 'm': 2427c478bd9Sstevel@tonic-gate if (function != NONE) 2437c478bd9Sstevel@tonic-gate errflg = 1; 2447c478bd9Sstevel@tonic-gate else 2457c478bd9Sstevel@tonic-gate function = RPCBGETSTAT; 2467c478bd9Sstevel@tonic-gate break; 2477c478bd9Sstevel@tonic-gate 2487c478bd9Sstevel@tonic-gate case 's': 2497c478bd9Sstevel@tonic-gate if (function != NONE) 2507c478bd9Sstevel@tonic-gate errflg = 1; 2517c478bd9Sstevel@tonic-gate else 2527c478bd9Sstevel@tonic-gate function = RPCBDUMP_SHORT; 2537c478bd9Sstevel@tonic-gate break; 2547c478bd9Sstevel@tonic-gate 2557c478bd9Sstevel@tonic-gate case 'T': 2567c478bd9Sstevel@tonic-gate netid = optarg; 2577c478bd9Sstevel@tonic-gate break; 2587c478bd9Sstevel@tonic-gate case '?': 2597c478bd9Sstevel@tonic-gate errflg = 1; 2607c478bd9Sstevel@tonic-gate break; 2617c478bd9Sstevel@tonic-gate } 2627c478bd9Sstevel@tonic-gate } 2637c478bd9Sstevel@tonic-gate 2647c478bd9Sstevel@tonic-gate if (errflg || ((function == ADDRPING) && !netid)) { 2657c478bd9Sstevel@tonic-gate usage(); 2667c478bd9Sstevel@tonic-gate return (1); 2677c478bd9Sstevel@tonic-gate } 2687c478bd9Sstevel@tonic-gate if (netid == NULL) { /* user has not selected transport to use */ 2697c478bd9Sstevel@tonic-gate /* 2707c478bd9Sstevel@tonic-gate * See if a COTS loopback transport is available, in case we 2717c478bd9Sstevel@tonic-gate * will be talking to the local system. 2727c478bd9Sstevel@tonic-gate */ 2737c478bd9Sstevel@tonic-gate handle = setnetconfig(); 2747c478bd9Sstevel@tonic-gate while ((loopback_nconf = getnetconfig(handle)) != NULL) { 2757c478bd9Sstevel@tonic-gate if (strcmp(loopback_nconf->nc_protofmly, 2767c478bd9Sstevel@tonic-gate NC_LOOPBACK) == 0 && 2777c478bd9Sstevel@tonic-gate (loopback_nconf->nc_semantics == NC_TPI_COTS || 2787c478bd9Sstevel@tonic-gate loopback_nconf->nc_semantics == NC_TPI_COTS_ORD)) { 2797c478bd9Sstevel@tonic-gate loopback_netid = loopback_nconf->nc_netid; 2807c478bd9Sstevel@tonic-gate break; 2817c478bd9Sstevel@tonic-gate } 2827c478bd9Sstevel@tonic-gate } 2837c478bd9Sstevel@tonic-gate if (loopback_netid == NULL) { 2847c478bd9Sstevel@tonic-gate endnetconfig(handle); 2857c478bd9Sstevel@tonic-gate } 2867c478bd9Sstevel@tonic-gate } 2877c478bd9Sstevel@tonic-gate if (function == NONE) { 2887c478bd9Sstevel@tonic-gate if (argc - optind > 1) 2897c478bd9Sstevel@tonic-gate function = PROGPING; 2907c478bd9Sstevel@tonic-gate else 2917c478bd9Sstevel@tonic-gate function = RPCBDUMP; 2927c478bd9Sstevel@tonic-gate } 2937c478bd9Sstevel@tonic-gate 2947c478bd9Sstevel@tonic-gate switch (function) { 2957c478bd9Sstevel@tonic-gate #ifdef PORTMAP 2967c478bd9Sstevel@tonic-gate case PMAPDUMP: 2977c478bd9Sstevel@tonic-gate if (portnum != 0) { 2987c478bd9Sstevel@tonic-gate usage(); 2997c478bd9Sstevel@tonic-gate return (1); 3007c478bd9Sstevel@tonic-gate } 3017c478bd9Sstevel@tonic-gate pmapdump(argc - optind, argv + optind); 3027c478bd9Sstevel@tonic-gate break; 3037c478bd9Sstevel@tonic-gate 3047c478bd9Sstevel@tonic-gate case UDPPING: 3057c478bd9Sstevel@tonic-gate ip_ping(portnum, "udp", argc - optind, argv + optind); 3067c478bd9Sstevel@tonic-gate break; 3077c478bd9Sstevel@tonic-gate 3087c478bd9Sstevel@tonic-gate case TCPPING: 3097c478bd9Sstevel@tonic-gate ip_ping(portnum, "tcp", argc - optind, argv + optind); 3107c478bd9Sstevel@tonic-gate break; 3117c478bd9Sstevel@tonic-gate #endif 3127c478bd9Sstevel@tonic-gate case BROADCAST: 3137c478bd9Sstevel@tonic-gate brdcst(argc - optind, argv + optind); 3147c478bd9Sstevel@tonic-gate break; 3157c478bd9Sstevel@tonic-gate case DELETES: 3167c478bd9Sstevel@tonic-gate deletereg(netid, argc - optind, argv + optind); 3177c478bd9Sstevel@tonic-gate break; 3187c478bd9Sstevel@tonic-gate case ADDRPING: 3197c478bd9Sstevel@tonic-gate addrping(address, netid, argc - optind, argv + optind); 3207c478bd9Sstevel@tonic-gate break; 3217c478bd9Sstevel@tonic-gate case PROGPING: 3227c478bd9Sstevel@tonic-gate progping(netid, argc - optind, argv + optind); 3237c478bd9Sstevel@tonic-gate break; 3247c478bd9Sstevel@tonic-gate case RPCBDUMP: 3257c478bd9Sstevel@tonic-gate case RPCBDUMP_SHORT: 3267c478bd9Sstevel@tonic-gate rpcbdump(function, netid, argc - optind, argv + optind); 3277c478bd9Sstevel@tonic-gate break; 3287c478bd9Sstevel@tonic-gate case RPCBGETSTAT: 3297c478bd9Sstevel@tonic-gate rpcbgetstat(argc - optind, argv + optind); 3307c478bd9Sstevel@tonic-gate break; 3317c478bd9Sstevel@tonic-gate case RPCBADDRLIST: 3327c478bd9Sstevel@tonic-gate rpcbaddrlist(netid, argc - optind, argv + optind); 3337c478bd9Sstevel@tonic-gate break; 3347c478bd9Sstevel@tonic-gate } 3357c478bd9Sstevel@tonic-gate return (0); 3367c478bd9Sstevel@tonic-gate } 3377c478bd9Sstevel@tonic-gate 3387c478bd9Sstevel@tonic-gate #ifdef PORTMAP 3397c478bd9Sstevel@tonic-gate static CLIENT * 3407c478bd9Sstevel@tonic-gate clnt_com_create(addr, prog, vers, fdp, trans) 3417c478bd9Sstevel@tonic-gate struct sockaddr_in *addr; 3427c478bd9Sstevel@tonic-gate ulong_t prog; 3437c478bd9Sstevel@tonic-gate ulong_t vers; 3447c478bd9Sstevel@tonic-gate int *fdp; 3457c478bd9Sstevel@tonic-gate char *trans; 3467c478bd9Sstevel@tonic-gate { 3477c478bd9Sstevel@tonic-gate CLIENT *clnt; 3487c478bd9Sstevel@tonic-gate 3497c478bd9Sstevel@tonic-gate if (strcmp(trans, "tcp") == 0) { 3507c478bd9Sstevel@tonic-gate clnt = clnttcp_create(addr, prog, vers, fdp, 0, 0); 3517c478bd9Sstevel@tonic-gate } else { 3527c478bd9Sstevel@tonic-gate struct timeval to; 3537c478bd9Sstevel@tonic-gate 3547c478bd9Sstevel@tonic-gate to.tv_sec = 5; 3557c478bd9Sstevel@tonic-gate to.tv_usec = 0; 3567c478bd9Sstevel@tonic-gate clnt = clntudp_create(addr, prog, vers, to, fdp); 3577c478bd9Sstevel@tonic-gate } 3587c478bd9Sstevel@tonic-gate if (clnt == (CLIENT *)NULL) { 3597c478bd9Sstevel@tonic-gate clnt_pcreateerror("rpcinfo"); 3607c478bd9Sstevel@tonic-gate if (vers == MIN_VERS) 3617c478bd9Sstevel@tonic-gate printf("program %lu is not available\n", prog); 3627c478bd9Sstevel@tonic-gate else 3637c478bd9Sstevel@tonic-gate printf("program %lu version %lu is not available\n", 3647c478bd9Sstevel@tonic-gate prog, vers); 3657c478bd9Sstevel@tonic-gate exit(1); 3667c478bd9Sstevel@tonic-gate } 3677c478bd9Sstevel@tonic-gate return (clnt); 3687c478bd9Sstevel@tonic-gate } 3697c478bd9Sstevel@tonic-gate 3707c478bd9Sstevel@tonic-gate /* 3717c478bd9Sstevel@tonic-gate * If portnum is 0, then go and get the address from portmapper, which happens 3727c478bd9Sstevel@tonic-gate * transparently through clnt*_create(); If version number is not given, it 3737c478bd9Sstevel@tonic-gate * tries to find out the version number by making a call to version 0 and if 3747c478bd9Sstevel@tonic-gate * that fails, it obtains the high order and the low order version number. If 3757c478bd9Sstevel@tonic-gate * version 0 calls succeeds, it tries for MAXVERS call and repeats the same. 3767c478bd9Sstevel@tonic-gate */ 3777c478bd9Sstevel@tonic-gate static void 3787c478bd9Sstevel@tonic-gate ip_ping(portnum, trans, argc, argv) 3797c478bd9Sstevel@tonic-gate ushort_t portnum; 3807c478bd9Sstevel@tonic-gate char *trans; 3817c478bd9Sstevel@tonic-gate int argc; 3827c478bd9Sstevel@tonic-gate char **argv; 3837c478bd9Sstevel@tonic-gate { 3847c478bd9Sstevel@tonic-gate CLIENT *client; 3857c478bd9Sstevel@tonic-gate int fd = RPC_ANYFD; 3867c478bd9Sstevel@tonic-gate struct timeval to; 3877c478bd9Sstevel@tonic-gate struct sockaddr_in addr; 3887c478bd9Sstevel@tonic-gate enum clnt_stat rpc_stat; 3897c478bd9Sstevel@tonic-gate ulong_t prognum, vers, minvers, maxvers; 3907c478bd9Sstevel@tonic-gate struct rpc_err rpcerr; 3917c478bd9Sstevel@tonic-gate int failure = 0; 3927c478bd9Sstevel@tonic-gate 3937c478bd9Sstevel@tonic-gate if (argc < 2 || argc > 3) { 3947c478bd9Sstevel@tonic-gate usage(); 3957c478bd9Sstevel@tonic-gate exit(1); 3967c478bd9Sstevel@tonic-gate } 3977c478bd9Sstevel@tonic-gate to.tv_sec = 10; 3987c478bd9Sstevel@tonic-gate to.tv_usec = 0; 3997c478bd9Sstevel@tonic-gate prognum = getprognum(argv[1]); 4007c478bd9Sstevel@tonic-gate get_inet_address(&addr, argv[0]); 4017c478bd9Sstevel@tonic-gate if (argc == 2) { /* Version number not known */ 4027c478bd9Sstevel@tonic-gate /* 4037c478bd9Sstevel@tonic-gate * A call to version 0 should fail with a program/version 4047c478bd9Sstevel@tonic-gate * mismatch, and give us the range of versions supported. 4057c478bd9Sstevel@tonic-gate */ 4067c478bd9Sstevel@tonic-gate vers = MIN_VERS; 4077c478bd9Sstevel@tonic-gate } else { 4087c478bd9Sstevel@tonic-gate vers = getvers(argv[2]); 4097c478bd9Sstevel@tonic-gate } 4107c478bd9Sstevel@tonic-gate addr.sin_port = htons(portnum); 4117c478bd9Sstevel@tonic-gate client = clnt_com_create(&addr, prognum, vers, &fd, trans); 4127c478bd9Sstevel@tonic-gate rpc_stat = CLNT_CALL(client, NULLPROC, (xdrproc_t)xdr_void, 4137c478bd9Sstevel@tonic-gate (char *)NULL, (xdrproc_t)xdr_void, (char *)NULL, 4147c478bd9Sstevel@tonic-gate to); 4157c478bd9Sstevel@tonic-gate if (argc != 2) { 4167c478bd9Sstevel@tonic-gate /* Version number was known */ 4177c478bd9Sstevel@tonic-gate if (pstatus(client, prognum, vers) < 0) 4187c478bd9Sstevel@tonic-gate exit(1); 4197c478bd9Sstevel@tonic-gate (void) CLNT_DESTROY(client); 4207c478bd9Sstevel@tonic-gate return; 4217c478bd9Sstevel@tonic-gate } 4227c478bd9Sstevel@tonic-gate /* Version number not known */ 4237c478bd9Sstevel@tonic-gate (void) CLNT_CONTROL(client, CLSET_FD_NCLOSE, (char *)NULL); 4247c478bd9Sstevel@tonic-gate if (rpc_stat == RPC_PROGVERSMISMATCH) { 4257c478bd9Sstevel@tonic-gate clnt_geterr(client, &rpcerr); 4267c478bd9Sstevel@tonic-gate minvers = rpcerr.re_vers.low; 4277c478bd9Sstevel@tonic-gate maxvers = rpcerr.re_vers.high; 4287c478bd9Sstevel@tonic-gate } else if (rpc_stat == RPC_SUCCESS) { 4297c478bd9Sstevel@tonic-gate /* 4307c478bd9Sstevel@tonic-gate * Oh dear, it DOES support version 0. 4317c478bd9Sstevel@tonic-gate * Let's try version MAX_VERS. 4327c478bd9Sstevel@tonic-gate */ 4337c478bd9Sstevel@tonic-gate (void) CLNT_DESTROY(client); 4347c478bd9Sstevel@tonic-gate addr.sin_port = htons(portnum); 4357c478bd9Sstevel@tonic-gate client = clnt_com_create(&addr, prognum, MAX_VERS, &fd, trans); 4367c478bd9Sstevel@tonic-gate rpc_stat = CLNT_CALL(client, NULLPROC, (xdrproc_t)xdr_void, 4377c478bd9Sstevel@tonic-gate (char *)NULL, (xdrproc_t)xdr_void, 4387c478bd9Sstevel@tonic-gate (char *)NULL, to); 4397c478bd9Sstevel@tonic-gate if (rpc_stat == RPC_PROGVERSMISMATCH) { 4407c478bd9Sstevel@tonic-gate clnt_geterr(client, &rpcerr); 4417c478bd9Sstevel@tonic-gate minvers = rpcerr.re_vers.low; 4427c478bd9Sstevel@tonic-gate maxvers = rpcerr.re_vers.high; 4437c478bd9Sstevel@tonic-gate } else if (rpc_stat == RPC_SUCCESS) { 4447c478bd9Sstevel@tonic-gate /* 4457c478bd9Sstevel@tonic-gate * It also supports version MAX_VERS. 4467c478bd9Sstevel@tonic-gate * Looks like we have a wise guy. 4477c478bd9Sstevel@tonic-gate * OK, we give them information on all 4487c478bd9Sstevel@tonic-gate * 4 billion versions they support... 4497c478bd9Sstevel@tonic-gate */ 4507c478bd9Sstevel@tonic-gate minvers = 0; 4517c478bd9Sstevel@tonic-gate maxvers = MAX_VERS; 4527c478bd9Sstevel@tonic-gate } else { 4537c478bd9Sstevel@tonic-gate (void) pstatus(client, prognum, MAX_VERS); 4547c478bd9Sstevel@tonic-gate exit(1); 4557c478bd9Sstevel@tonic-gate } 4567c478bd9Sstevel@tonic-gate } else { 4577c478bd9Sstevel@tonic-gate (void) pstatus(client, prognum, (ulong_t)0); 4587c478bd9Sstevel@tonic-gate exit(1); 4597c478bd9Sstevel@tonic-gate } 4607c478bd9Sstevel@tonic-gate (void) CLNT_DESTROY(client); 4617c478bd9Sstevel@tonic-gate for (vers = minvers; vers <= maxvers; vers++) { 4627c478bd9Sstevel@tonic-gate addr.sin_port = htons(portnum); 4637c478bd9Sstevel@tonic-gate client = clnt_com_create(&addr, prognum, vers, &fd, trans); 4647c478bd9Sstevel@tonic-gate rpc_stat = CLNT_CALL(client, NULLPROC, (xdrproc_t)xdr_void, 4657c478bd9Sstevel@tonic-gate (char *)NULL, (xdrproc_t)xdr_void, 4667c478bd9Sstevel@tonic-gate (char *)NULL, to); 4677c478bd9Sstevel@tonic-gate if (pstatus(client, prognum, vers) < 0) 4687c478bd9Sstevel@tonic-gate failure = 1; 4697c478bd9Sstevel@tonic-gate (void) CLNT_DESTROY(client); 4707c478bd9Sstevel@tonic-gate } 4717c478bd9Sstevel@tonic-gate if (failure) 4727c478bd9Sstevel@tonic-gate exit(1); 4737c478bd9Sstevel@tonic-gate (void) t_close(fd); 4747c478bd9Sstevel@tonic-gate } 4757c478bd9Sstevel@tonic-gate 4767c478bd9Sstevel@tonic-gate /* 4777c478bd9Sstevel@tonic-gate * Dump all the portmapper registerations 4787c478bd9Sstevel@tonic-gate */ 4797c478bd9Sstevel@tonic-gate static void 4807c478bd9Sstevel@tonic-gate pmapdump(argc, argv) 4817c478bd9Sstevel@tonic-gate int argc; 4827c478bd9Sstevel@tonic-gate char **argv; 4837c478bd9Sstevel@tonic-gate { 4847c478bd9Sstevel@tonic-gate struct sockaddr_in server_addr; 4857c478bd9Sstevel@tonic-gate pmaplist_ptr head = NULL; 4867c478bd9Sstevel@tonic-gate int socket = RPC_ANYSOCK; 4877c478bd9Sstevel@tonic-gate struct timeval minutetimeout; 4887c478bd9Sstevel@tonic-gate register CLIENT *client; 4897c478bd9Sstevel@tonic-gate struct rpcent *rpc; 4907c478bd9Sstevel@tonic-gate enum clnt_stat clnt_st; 4917c478bd9Sstevel@tonic-gate struct rpc_err err; 4927c478bd9Sstevel@tonic-gate struct utsname utsname; 4937c478bd9Sstevel@tonic-gate char *host; 4947c478bd9Sstevel@tonic-gate 4957c478bd9Sstevel@tonic-gate if (argc > 1) { 4967c478bd9Sstevel@tonic-gate usage(); 4977c478bd9Sstevel@tonic-gate exit(1); 4987c478bd9Sstevel@tonic-gate } 4997c478bd9Sstevel@tonic-gate if (argc == 1) { 5007c478bd9Sstevel@tonic-gate host = argv[0]; 5017c478bd9Sstevel@tonic-gate get_inet_address(&server_addr, host); 5027c478bd9Sstevel@tonic-gate } else { 5037c478bd9Sstevel@tonic-gate uname(&utsname); 5047c478bd9Sstevel@tonic-gate host = utsname.nodename; 5057c478bd9Sstevel@tonic-gate get_inet_address(&server_addr, host); 5067c478bd9Sstevel@tonic-gate } 5077c478bd9Sstevel@tonic-gate minutetimeout.tv_sec = 60; 5087c478bd9Sstevel@tonic-gate minutetimeout.tv_usec = 0; 5097c478bd9Sstevel@tonic-gate server_addr.sin_port = htons(PMAPPORT); 5107c478bd9Sstevel@tonic-gate if ((client = clnttcp_create(&server_addr, PMAPPROG, 5117c478bd9Sstevel@tonic-gate PMAPVERS, &socket, 50, 500)) == NULL) { 5127c478bd9Sstevel@tonic-gate if (rpc_createerr.cf_stat == RPC_TLIERROR) { 5137c478bd9Sstevel@tonic-gate /* 5147c478bd9Sstevel@tonic-gate * "Misc. TLI error" is not too helpful. Most likely 5157c478bd9Sstevel@tonic-gate * the connection to the remote server timed out, so 5167c478bd9Sstevel@tonic-gate * this error is at least less perplexing. 5177c478bd9Sstevel@tonic-gate */ 5187c478bd9Sstevel@tonic-gate rpc_createerr.cf_stat = RPC_PMAPFAILURE; 5197c478bd9Sstevel@tonic-gate rpc_createerr.cf_error.re_status = RPC_FAILED; 5207c478bd9Sstevel@tonic-gate } 5217c478bd9Sstevel@tonic-gate clnt_pcreateerror("rpcinfo: can't contact portmapper"); 5227c478bd9Sstevel@tonic-gate exit(1); 5237c478bd9Sstevel@tonic-gate } 5247c478bd9Sstevel@tonic-gate clnt_st = CLNT_CALL(client, PMAPPROC_DUMP, (xdrproc_t)xdr_void, 5257c478bd9Sstevel@tonic-gate NULL, (xdrproc_t)xdr_pmaplist_ptr, (char *)&head, 5267c478bd9Sstevel@tonic-gate minutetimeout); 5277c478bd9Sstevel@tonic-gate if (clnt_st != RPC_SUCCESS) { 5287c478bd9Sstevel@tonic-gate if ((clnt_st == RPC_PROGVERSMISMATCH) || 5297c478bd9Sstevel@tonic-gate (clnt_st == RPC_PROGUNAVAIL)) { 5307c478bd9Sstevel@tonic-gate CLNT_GETERR(client, &err); 5317c478bd9Sstevel@tonic-gate if (err.re_vers.low > PMAPVERS) 5327c478bd9Sstevel@tonic-gate fprintf(stderr, 5337c478bd9Sstevel@tonic-gate "%s does not support portmapper. Try rpcinfo %s instead\n", 5347c478bd9Sstevel@tonic-gate host, host); 5357c478bd9Sstevel@tonic-gate exit(1); 5367c478bd9Sstevel@tonic-gate } 5377c478bd9Sstevel@tonic-gate clnt_perror(client, "rpcinfo: can't contact portmapper"); 5387c478bd9Sstevel@tonic-gate exit(1); 5397c478bd9Sstevel@tonic-gate } 5407c478bd9Sstevel@tonic-gate if (head == NULL) { 5417c478bd9Sstevel@tonic-gate printf("No remote programs registered.\n"); 5427c478bd9Sstevel@tonic-gate } else { 5437c478bd9Sstevel@tonic-gate printf(" program vers proto port service\n"); 5447c478bd9Sstevel@tonic-gate for (; head != NULL; head = head->pml_next) { 5457c478bd9Sstevel@tonic-gate printf("%10ld%5ld", 5467c478bd9Sstevel@tonic-gate head->pml_map.pm_prog, 5477c478bd9Sstevel@tonic-gate head->pml_map.pm_vers); 5487c478bd9Sstevel@tonic-gate if (head->pml_map.pm_prot == IPPROTO_UDP) 5497c478bd9Sstevel@tonic-gate printf("%6s", "udp"); 5507c478bd9Sstevel@tonic-gate else if (head->pml_map.pm_prot == IPPROTO_TCP) 5517c478bd9Sstevel@tonic-gate printf("%6s", "tcp"); 5527c478bd9Sstevel@tonic-gate else 5537c478bd9Sstevel@tonic-gate printf("%6ld", head->pml_map.pm_prot); 5547c478bd9Sstevel@tonic-gate printf("%7ld", head->pml_map.pm_port); 5557c478bd9Sstevel@tonic-gate rpc = getrpcbynumber(head->pml_map.pm_prog); 5567c478bd9Sstevel@tonic-gate if (rpc) 5577c478bd9Sstevel@tonic-gate printf(" %s\n", rpc->r_name); 5587c478bd9Sstevel@tonic-gate else 5597c478bd9Sstevel@tonic-gate printf("\n"); 5607c478bd9Sstevel@tonic-gate } 5617c478bd9Sstevel@tonic-gate } 5627c478bd9Sstevel@tonic-gate } 5637c478bd9Sstevel@tonic-gate 5647c478bd9Sstevel@tonic-gate static void 5657c478bd9Sstevel@tonic-gate get_inet_address(addr, host) 5667c478bd9Sstevel@tonic-gate struct sockaddr_in *addr; 5677c478bd9Sstevel@tonic-gate char *host; 5687c478bd9Sstevel@tonic-gate { 5697c478bd9Sstevel@tonic-gate struct netconfig *nconf; 5707c478bd9Sstevel@tonic-gate struct nd_hostserv service; 5717c478bd9Sstevel@tonic-gate struct nd_addrlist *naddrs; 5727c478bd9Sstevel@tonic-gate 5737c478bd9Sstevel@tonic-gate (void) memset((char *)addr, 0, sizeof (*addr)); 5747c478bd9Sstevel@tonic-gate addr->sin_addr.s_addr = inet_addr(host); 5757c478bd9Sstevel@tonic-gate if (addr->sin_addr.s_addr == -1 || addr->sin_addr.s_addr == 0) { 5767c478bd9Sstevel@tonic-gate if ((nconf = __rpc_getconfip("udp")) == NULL && 5777c478bd9Sstevel@tonic-gate (nconf = __rpc_getconfip("tcp")) == NULL) { 5787c478bd9Sstevel@tonic-gate 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)) { 5857c478bd9Sstevel@tonic-gate 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 } 6267c478bd9Sstevel@tonic-gate 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)) { 6527c478bd9Sstevel@tonic-gate 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 char buf[256]; 7177c478bd9Sstevel@tonic-gate enum clnt_stat clnt_st; 7187c478bd9Sstevel@tonic-gate struct rpc_err err; 7197c478bd9Sstevel@tonic-gate struct utsname utsname; 7207c478bd9Sstevel@tonic-gate struct rpcbdump_short *rs_head = NULL; 7217c478bd9Sstevel@tonic-gate 7227c478bd9Sstevel@tonic-gate if (argc > 1) { 7237c478bd9Sstevel@tonic-gate usage(); 7247c478bd9Sstevel@tonic-gate exit(1); 7257c478bd9Sstevel@tonic-gate } 7267c478bd9Sstevel@tonic-gate if (argc == 1) { 7277c478bd9Sstevel@tonic-gate host = argv[0]; 7287c478bd9Sstevel@tonic-gate } else { 7297c478bd9Sstevel@tonic-gate uname(&utsname); 7307c478bd9Sstevel@tonic-gate host = utsname.nodename; 7317c478bd9Sstevel@tonic-gate } 7327c478bd9Sstevel@tonic-gate if (netid == NULL) { 7337c478bd9Sstevel@tonic-gate if (loopback_netid == NULL) { 7347c478bd9Sstevel@tonic-gate client = clnt_rpcbind_create(host, RPCBVERS, NULL); 7357c478bd9Sstevel@tonic-gate } else { 7367c478bd9Sstevel@tonic-gate client = getclnthandle(host, loopback_nconf, RPCBVERS, NULL); 7377c478bd9Sstevel@tonic-gate if (client == NULL && rpc_createerr.cf_stat == 7387c478bd9Sstevel@tonic-gate RPC_N2AXLATEFAILURE) { 7397c478bd9Sstevel@tonic-gate client = clnt_rpcbind_create(host, RPCBVERS, NULL); 7407c478bd9Sstevel@tonic-gate } 7417c478bd9Sstevel@tonic-gate } 7427c478bd9Sstevel@tonic-gate } else { 7437c478bd9Sstevel@tonic-gate struct netconfig *nconf; 7447c478bd9Sstevel@tonic-gate 7457c478bd9Sstevel@tonic-gate nconf = getnetconfigent(netid); 7467c478bd9Sstevel@tonic-gate if (nconf == NULL) { 7477c478bd9Sstevel@tonic-gate nc_perror("rpcinfo: invalid transport"); 7487c478bd9Sstevel@tonic-gate exit(1); 7497c478bd9Sstevel@tonic-gate } 7507c478bd9Sstevel@tonic-gate client = getclnthandle(host, nconf, RPCBVERS, NULL); 7517c478bd9Sstevel@tonic-gate if (nconf) 7527c478bd9Sstevel@tonic-gate (void) freenetconfigent(nconf); 7537c478bd9Sstevel@tonic-gate } 7547c478bd9Sstevel@tonic-gate if (client == (CLIENT *)NULL) { 7557c478bd9Sstevel@tonic-gate clnt_pcreateerror("rpcinfo: can't contact rpcbind"); 7567c478bd9Sstevel@tonic-gate exit(1); 7577c478bd9Sstevel@tonic-gate } 7587c478bd9Sstevel@tonic-gate minutetimeout.tv_sec = 60; 7597c478bd9Sstevel@tonic-gate minutetimeout.tv_usec = 0; 7607c478bd9Sstevel@tonic-gate clnt_st = CLNT_CALL(client, RPCBPROC_DUMP, (xdrproc_t)xdr_void, 7617c478bd9Sstevel@tonic-gate NULL, (xdrproc_t)xdr_rpcblist_ptr, (char *)&head, 7627c478bd9Sstevel@tonic-gate minutetimeout); 7637c478bd9Sstevel@tonic-gate if (clnt_st != RPC_SUCCESS) { 7647c478bd9Sstevel@tonic-gate if ((clnt_st == RPC_PROGVERSMISMATCH) || 7657c478bd9Sstevel@tonic-gate (clnt_st == RPC_PROGUNAVAIL)) { 7667c478bd9Sstevel@tonic-gate int vers; 7677c478bd9Sstevel@tonic-gate 7687c478bd9Sstevel@tonic-gate CLNT_GETERR(client, &err); 7697c478bd9Sstevel@tonic-gate if (err.re_vers.low == RPCBVERS4) { 7707c478bd9Sstevel@tonic-gate vers = RPCBVERS4; 7717c478bd9Sstevel@tonic-gate clnt_control(client, CLSET_VERS, (char *)&vers); 7727c478bd9Sstevel@tonic-gate clnt_st = CLNT_CALL(client, RPCBPROC_DUMP, 7737c478bd9Sstevel@tonic-gate (xdrproc_t)xdr_void, NULL, 7747c478bd9Sstevel@tonic-gate (xdrproc_t)xdr_rpcblist_ptr, (char *)&head, 7757c478bd9Sstevel@tonic-gate minutetimeout); 7767c478bd9Sstevel@tonic-gate if (clnt_st != RPC_SUCCESS) 7777c478bd9Sstevel@tonic-gate goto failed; 7787c478bd9Sstevel@tonic-gate } else { 7797c478bd9Sstevel@tonic-gate if (err.re_vers.high == PMAPVERS) { 7807c478bd9Sstevel@tonic-gate int high, low; 7817c478bd9Sstevel@tonic-gate pmaplist_ptr pmaphead = NULL; 7827c478bd9Sstevel@tonic-gate rpcblist_ptr list, prev; 7837c478bd9Sstevel@tonic-gate 7847c478bd9Sstevel@tonic-gate vers = PMAPVERS; 7857c478bd9Sstevel@tonic-gate clnt_control(client, CLSET_VERS, (char *)&vers); 7867c478bd9Sstevel@tonic-gate clnt_st = CLNT_CALL(client, PMAPPROC_DUMP, 7877c478bd9Sstevel@tonic-gate (xdrproc_t)xdr_void, NULL, 7887c478bd9Sstevel@tonic-gate (xdrproc_t)xdr_pmaplist_ptr, 7897c478bd9Sstevel@tonic-gate (char *)&pmaphead, minutetimeout); 7907c478bd9Sstevel@tonic-gate if (clnt_st != RPC_SUCCESS) 7917c478bd9Sstevel@tonic-gate goto failed; 7927c478bd9Sstevel@tonic-gate /* 7937c478bd9Sstevel@tonic-gate * convert to rpcblist_ptr format 7947c478bd9Sstevel@tonic-gate */ 7957c478bd9Sstevel@tonic-gate for (head = NULL; pmaphead != NULL; 7967c478bd9Sstevel@tonic-gate pmaphead = pmaphead->pml_next) { 7977c478bd9Sstevel@tonic-gate list = (rpcblist *)malloc(sizeof (rpcblist)); 7987c478bd9Sstevel@tonic-gate if (list == NULL) 7997c478bd9Sstevel@tonic-gate goto error; 8007c478bd9Sstevel@tonic-gate if (head == NULL) 8017c478bd9Sstevel@tonic-gate head = list; 8027c478bd9Sstevel@tonic-gate else 8037c478bd9Sstevel@tonic-gate prev->rpcb_next = (rpcblist_ptr) list; 8047c478bd9Sstevel@tonic-gate 8057c478bd9Sstevel@tonic-gate list->rpcb_next = NULL; 8067c478bd9Sstevel@tonic-gate list->rpcb_map.r_prog = pmaphead->pml_map.pm_prog; 8077c478bd9Sstevel@tonic-gate list->rpcb_map.r_vers = pmaphead->pml_map.pm_vers; 8087c478bd9Sstevel@tonic-gate if (pmaphead->pml_map.pm_prot == IPPROTO_UDP) 8097c478bd9Sstevel@tonic-gate list->rpcb_map.r_netid = "udp"; 8107c478bd9Sstevel@tonic-gate else if (pmaphead->pml_map.pm_prot == IPPROTO_TCP) 8117c478bd9Sstevel@tonic-gate list->rpcb_map.r_netid = "tcp"; 8127c478bd9Sstevel@tonic-gate else { 8137c478bd9Sstevel@tonic-gate #define MAXLONG_AS_STRING "2147483648" 8147c478bd9Sstevel@tonic-gate list->rpcb_map.r_netid = 8157c478bd9Sstevel@tonic-gate malloc(strlen(MAXLONG_AS_STRING) + 1); 8167c478bd9Sstevel@tonic-gate if (list->rpcb_map.r_netid == NULL) 8177c478bd9Sstevel@tonic-gate goto error; 8187c478bd9Sstevel@tonic-gate sprintf(list->rpcb_map.r_netid, "%6ld", 8197c478bd9Sstevel@tonic-gate pmaphead->pml_map.pm_prot); 8207c478bd9Sstevel@tonic-gate } 8217c478bd9Sstevel@tonic-gate list->rpcb_map.r_owner = UNKNOWN; 8227c478bd9Sstevel@tonic-gate low = pmaphead->pml_map.pm_port & 0xff; 8237c478bd9Sstevel@tonic-gate high = (pmaphead->pml_map.pm_port >> 8) & 0xff; 8247c478bd9Sstevel@tonic-gate list->rpcb_map.r_addr = strdup("0.0.0.0.XXX.XXX"); 8257c478bd9Sstevel@tonic-gate sprintf(&list->rpcb_map.r_addr[8], "%d.%d", 8267c478bd9Sstevel@tonic-gate high, low); 8277c478bd9Sstevel@tonic-gate prev = list; 8287c478bd9Sstevel@tonic-gate } 8297c478bd9Sstevel@tonic-gate } 8307c478bd9Sstevel@tonic-gate } 8317c478bd9Sstevel@tonic-gate } else { /* any other error */ 8327c478bd9Sstevel@tonic-gate failed: 8337c478bd9Sstevel@tonic-gate clnt_perror(client, "rpcinfo: can't contact rpcbind: "); 8347c478bd9Sstevel@tonic-gate exit(1); 8357c478bd9Sstevel@tonic-gate } 8367c478bd9Sstevel@tonic-gate } 8377c478bd9Sstevel@tonic-gate if (head == NULL) { 8387c478bd9Sstevel@tonic-gate printf("No remote programs registered.\n"); 8397c478bd9Sstevel@tonic-gate } else if (dumptype == RPCBDUMP) { 8407c478bd9Sstevel@tonic-gate printf( 8417c478bd9Sstevel@tonic-gate " program version netid address service owner\n"); 8427c478bd9Sstevel@tonic-gate for (; head != NULL; head = head->rpcb_next) { 8437c478bd9Sstevel@tonic-gate printf("%10ld%5ld ", 8447c478bd9Sstevel@tonic-gate head->rpcb_map.r_prog, head->rpcb_map.r_vers); 8457c478bd9Sstevel@tonic-gate printf("%-9s ", head->rpcb_map.r_netid); 8467c478bd9Sstevel@tonic-gate printf("%-19s", head->rpcb_map.r_addr); 8477c478bd9Sstevel@tonic-gate rpc = getrpcbynumber(head->rpcb_map.r_prog); 8487c478bd9Sstevel@tonic-gate if (rpc) 8497c478bd9Sstevel@tonic-gate printf(" %-10s", rpc->r_name); 8507c478bd9Sstevel@tonic-gate else 8517c478bd9Sstevel@tonic-gate printf(" %-10s", "-"); 8527c478bd9Sstevel@tonic-gate printf(" %s\n", head->rpcb_map.r_owner); 8537c478bd9Sstevel@tonic-gate } 8547c478bd9Sstevel@tonic-gate } else if (dumptype == RPCBDUMP_SHORT) { 8557c478bd9Sstevel@tonic-gate for (; head != NULL; head = head->rpcb_next) { 8567c478bd9Sstevel@tonic-gate for (rs = rs_head; rs; rs = rs->next) 8577c478bd9Sstevel@tonic-gate if (head->rpcb_map.r_prog == rs->prog) 8587c478bd9Sstevel@tonic-gate break; 8597c478bd9Sstevel@tonic-gate if (rs == NULL) { 8607c478bd9Sstevel@tonic-gate rs = (struct rpcbdump_short *) 8617c478bd9Sstevel@tonic-gate malloc(sizeof (struct rpcbdump_short)); 8627c478bd9Sstevel@tonic-gate if (rs == NULL) 8637c478bd9Sstevel@tonic-gate goto error; 8647c478bd9Sstevel@tonic-gate rs->next = NULL; 8657c478bd9Sstevel@tonic-gate if (rs_head == NULL) { 8667c478bd9Sstevel@tonic-gate rs_head = rs; 8677c478bd9Sstevel@tonic-gate rs_tail = rs; 8687c478bd9Sstevel@tonic-gate } else { 8697c478bd9Sstevel@tonic-gate rs_tail->next = rs; 8707c478bd9Sstevel@tonic-gate rs_tail = rs; 8717c478bd9Sstevel@tonic-gate } 8727c478bd9Sstevel@tonic-gate rs->prog = head->rpcb_map.r_prog; 8737c478bd9Sstevel@tonic-gate rs->owner = head->rpcb_map.r_owner; 8747c478bd9Sstevel@tonic-gate rs->nlist = NULL; 8757c478bd9Sstevel@tonic-gate rs->vlist = NULL; 8767c478bd9Sstevel@tonic-gate } 8777c478bd9Sstevel@tonic-gate if (add_version(rs, head->rpcb_map.r_vers) == FALSE) 8787c478bd9Sstevel@tonic-gate goto error; 8797c478bd9Sstevel@tonic-gate if (add_netid(rs, head->rpcb_map.r_netid) == FALSE) 8807c478bd9Sstevel@tonic-gate goto error; 8817c478bd9Sstevel@tonic-gate } 8827c478bd9Sstevel@tonic-gate printf( 8837c478bd9Sstevel@tonic-gate " program version(s) netid(s) service owner\n"); 8847c478bd9Sstevel@tonic-gate for (rs = rs_head; rs; rs = rs->next) { 8857c478bd9Sstevel@tonic-gate char *p = buf; 8867c478bd9Sstevel@tonic-gate 8877c478bd9Sstevel@tonic-gate printf("%10ld ", rs->prog); 8887c478bd9Sstevel@tonic-gate for (vl = rs->vlist; vl; vl = vl->next) { 8897c478bd9Sstevel@tonic-gate sprintf(p, "%d", vl->vers); 8907c478bd9Sstevel@tonic-gate p = p + strlen(p); 8917c478bd9Sstevel@tonic-gate if (vl->next) 8927c478bd9Sstevel@tonic-gate sprintf(p++, ","); 8937c478bd9Sstevel@tonic-gate } 8947c478bd9Sstevel@tonic-gate printf("%-10s", buf); 8957c478bd9Sstevel@tonic-gate buf[0] = NULL; 8967c478bd9Sstevel@tonic-gate for (nl = rs->nlist; nl; nl = nl->next) { 8977c478bd9Sstevel@tonic-gate strcat(buf, nl->netid); 8987c478bd9Sstevel@tonic-gate if (nl->next) 8997c478bd9Sstevel@tonic-gate strcat(buf, ","); 9007c478bd9Sstevel@tonic-gate } 9017c478bd9Sstevel@tonic-gate printf("%-32s", buf); 9027c478bd9Sstevel@tonic-gate rpc = getrpcbynumber(rs->prog); 9037c478bd9Sstevel@tonic-gate if (rpc) 9047c478bd9Sstevel@tonic-gate printf(" %-11s", rpc->r_name); 9057c478bd9Sstevel@tonic-gate else 9067c478bd9Sstevel@tonic-gate printf(" %-11s", "-"); 9077c478bd9Sstevel@tonic-gate printf(" %s\n", rs->owner); 9087c478bd9Sstevel@tonic-gate } 9097c478bd9Sstevel@tonic-gate } 9107c478bd9Sstevel@tonic-gate clnt_destroy(client); 9117c478bd9Sstevel@tonic-gate return; 9127c478bd9Sstevel@tonic-gate 9137c478bd9Sstevel@tonic-gate error: fprintf(stderr, "rpcinfo: no memory\n"); 9147c478bd9Sstevel@tonic-gate } 9157c478bd9Sstevel@tonic-gate 9167c478bd9Sstevel@tonic-gate static char nullstring[] = "\000"; 9177c478bd9Sstevel@tonic-gate 9187c478bd9Sstevel@tonic-gate static void 9197c478bd9Sstevel@tonic-gate rpcbaddrlist(netid, argc, argv) 9207c478bd9Sstevel@tonic-gate char *netid; 9217c478bd9Sstevel@tonic-gate int argc; 9227c478bd9Sstevel@tonic-gate char **argv; 9237c478bd9Sstevel@tonic-gate { 9247c478bd9Sstevel@tonic-gate rpcb_entry_list_ptr head = NULL; 9257c478bd9Sstevel@tonic-gate struct timeval minutetimeout; 9267c478bd9Sstevel@tonic-gate register CLIENT *client; 9277c478bd9Sstevel@tonic-gate struct rpcent *rpc; 9287c478bd9Sstevel@tonic-gate char *host; 9297c478bd9Sstevel@tonic-gate RPCB parms; 9307c478bd9Sstevel@tonic-gate struct netbuf *targaddr; 9317c478bd9Sstevel@tonic-gate 9327c478bd9Sstevel@tonic-gate if (argc != 3) { 9337c478bd9Sstevel@tonic-gate usage(); 9347c478bd9Sstevel@tonic-gate exit(1); 9357c478bd9Sstevel@tonic-gate } 9367c478bd9Sstevel@tonic-gate host = argv[0]; 9377c478bd9Sstevel@tonic-gate if (netid == NULL) { 9387c478bd9Sstevel@tonic-gate if (loopback_netid == NULL) { 9397c478bd9Sstevel@tonic-gate client = clnt_rpcbind_create(host, RPCBVERS4, &targaddr); 9407c478bd9Sstevel@tonic-gate } else { 9417c478bd9Sstevel@tonic-gate client = getclnthandle(host, loopback_nconf, RPCBVERS4, 9427c478bd9Sstevel@tonic-gate &targaddr); 9437c478bd9Sstevel@tonic-gate if (client == NULL && rpc_createerr.cf_stat == 9447c478bd9Sstevel@tonic-gate RPC_N2AXLATEFAILURE) { 9457c478bd9Sstevel@tonic-gate client = clnt_rpcbind_create(host, RPCBVERS4, &targaddr); 9467c478bd9Sstevel@tonic-gate } 9477c478bd9Sstevel@tonic-gate } 9487c478bd9Sstevel@tonic-gate } else { 9497c478bd9Sstevel@tonic-gate struct netconfig *nconf; 9507c478bd9Sstevel@tonic-gate 9517c478bd9Sstevel@tonic-gate nconf = getnetconfigent(netid); 9527c478bd9Sstevel@tonic-gate if (nconf == NULL) { 9537c478bd9Sstevel@tonic-gate nc_perror("rpcinfo: invalid transport"); 9547c478bd9Sstevel@tonic-gate exit(1); 9557c478bd9Sstevel@tonic-gate } 9567c478bd9Sstevel@tonic-gate client = getclnthandle(host, nconf, RPCBVERS4, &targaddr); 9577c478bd9Sstevel@tonic-gate if (nconf) 9587c478bd9Sstevel@tonic-gate (void) freenetconfigent(nconf); 9597c478bd9Sstevel@tonic-gate } 9607c478bd9Sstevel@tonic-gate if (client == (CLIENT *)NULL) { 9617c478bd9Sstevel@tonic-gate clnt_pcreateerror("rpcinfo: can't contact rpcbind"); 9627c478bd9Sstevel@tonic-gate exit(1); 9637c478bd9Sstevel@tonic-gate } 9647c478bd9Sstevel@tonic-gate minutetimeout.tv_sec = 60; 9657c478bd9Sstevel@tonic-gate minutetimeout.tv_usec = 0; 9667c478bd9Sstevel@tonic-gate 9677c478bd9Sstevel@tonic-gate parms.r_prog = getprognum(argv[1]); 9687c478bd9Sstevel@tonic-gate parms.r_vers = getvers(argv[2]); 9697c478bd9Sstevel@tonic-gate parms.r_netid = client->cl_netid; 9707c478bd9Sstevel@tonic-gate if (targaddr == NULL) { 9717c478bd9Sstevel@tonic-gate parms.r_addr = nullstring; /* for XDRing */ 9727c478bd9Sstevel@tonic-gate } else { 9737c478bd9Sstevel@tonic-gate /* 9747c478bd9Sstevel@tonic-gate * We also send the remote system the address we 9757c478bd9Sstevel@tonic-gate * used to contact it in case it can help it 9767c478bd9Sstevel@tonic-gate * connect back with us 9777c478bd9Sstevel@tonic-gate */ 9787c478bd9Sstevel@tonic-gate struct netconfig *nconf; 9797c478bd9Sstevel@tonic-gate 9807c478bd9Sstevel@tonic-gate nconf = getnetconfigent(client->cl_netid); 9817c478bd9Sstevel@tonic-gate if (nconf != NULL) { 9827c478bd9Sstevel@tonic-gate parms.r_addr = taddr2uaddr(nconf, targaddr); 9837c478bd9Sstevel@tonic-gate if (parms.r_addr == NULL) 9847c478bd9Sstevel@tonic-gate parms.r_addr = nullstring; 9857c478bd9Sstevel@tonic-gate freenetconfigent(nconf); 9867c478bd9Sstevel@tonic-gate } else { 9877c478bd9Sstevel@tonic-gate parms.r_addr = nullstring; /* for XDRing */ 9887c478bd9Sstevel@tonic-gate } 9897c478bd9Sstevel@tonic-gate free(targaddr->buf); 9907c478bd9Sstevel@tonic-gate free(targaddr); 9917c478bd9Sstevel@tonic-gate } 9927c478bd9Sstevel@tonic-gate parms.r_owner = nullstring; 9937c478bd9Sstevel@tonic-gate 9947c478bd9Sstevel@tonic-gate if (CLNT_CALL(client, RPCBPROC_GETADDRLIST, (xdrproc_t)xdr_rpcb, 9957c478bd9Sstevel@tonic-gate (char *)&parms, (xdrproc_t)xdr_rpcb_entry_list_ptr, 9967c478bd9Sstevel@tonic-gate (char *)&head, minutetimeout) != RPC_SUCCESS) { 9977c478bd9Sstevel@tonic-gate clnt_perror(client, "rpcinfo: can't contact rpcbind: "); 9987c478bd9Sstevel@tonic-gate exit(1); 9997c478bd9Sstevel@tonic-gate } 10007c478bd9Sstevel@tonic-gate if (head == NULL) { 10017c478bd9Sstevel@tonic-gate printf("No remote programs registered.\n"); 10027c478bd9Sstevel@tonic-gate } else { 10037c478bd9Sstevel@tonic-gate printf( 10047c478bd9Sstevel@tonic-gate " program vers tp_family/name/class address\t\t service\n"); 10057c478bd9Sstevel@tonic-gate for (; head != NULL; head = head->rpcb_entry_next) { 10067c478bd9Sstevel@tonic-gate rpcb_entry *re; 10077c478bd9Sstevel@tonic-gate char buf[128]; 10087c478bd9Sstevel@tonic-gate 10097c478bd9Sstevel@tonic-gate re = &head->rpcb_entry_map; 10107c478bd9Sstevel@tonic-gate printf("%10ld%3ld ", 10117c478bd9Sstevel@tonic-gate parms.r_prog, parms.r_vers); 10127c478bd9Sstevel@tonic-gate sprintf(buf, "%s/%s/%s ", 10137c478bd9Sstevel@tonic-gate re->r_nc_protofmly, re->r_nc_proto, 10147c478bd9Sstevel@tonic-gate re->r_nc_semantics == NC_TPI_CLTS ? "clts" : 10157c478bd9Sstevel@tonic-gate re->r_nc_semantics == NC_TPI_COTS ? "cots" : 10167c478bd9Sstevel@tonic-gate "cots_ord"); 10177c478bd9Sstevel@tonic-gate printf("%-24s", buf); 10187c478bd9Sstevel@tonic-gate printf("%-24s", re->r_maddr); 10197c478bd9Sstevel@tonic-gate rpc = getrpcbynumber(parms.r_prog); 10207c478bd9Sstevel@tonic-gate if (rpc) 10217c478bd9Sstevel@tonic-gate printf(" %-13s", rpc->r_name); 10227c478bd9Sstevel@tonic-gate else 10237c478bd9Sstevel@tonic-gate printf(" %-13s", "-"); 10247c478bd9Sstevel@tonic-gate printf("\n"); 10257c478bd9Sstevel@tonic-gate } 10267c478bd9Sstevel@tonic-gate } 10277c478bd9Sstevel@tonic-gate clnt_destroy(client); 10287c478bd9Sstevel@tonic-gate } 10297c478bd9Sstevel@tonic-gate 10307c478bd9Sstevel@tonic-gate /* 10317c478bd9Sstevel@tonic-gate * monitor rpcbind 10327c478bd9Sstevel@tonic-gate */ 10337c478bd9Sstevel@tonic-gate static void 10347c478bd9Sstevel@tonic-gate rpcbgetstat(argc, argv) 10357c478bd9Sstevel@tonic-gate int argc; 10367c478bd9Sstevel@tonic-gate char **argv; 10377c478bd9Sstevel@tonic-gate { 10387c478bd9Sstevel@tonic-gate rpcb_stat_byvers inf; 10397c478bd9Sstevel@tonic-gate struct timeval minutetimeout; 10407c478bd9Sstevel@tonic-gate register CLIENT *client; 10417c478bd9Sstevel@tonic-gate char *host; 10427c478bd9Sstevel@tonic-gate int i, j; 10437c478bd9Sstevel@tonic-gate rpcbs_addrlist *pa; 10447c478bd9Sstevel@tonic-gate rpcbs_rmtcalllist *pr; 10457c478bd9Sstevel@tonic-gate int cnt, flen; 10467c478bd9Sstevel@tonic-gate struct utsname utsname; 10477c478bd9Sstevel@tonic-gate #define MAXFIELD 64 10487c478bd9Sstevel@tonic-gate char fieldbuf[MAXFIELD]; 10497c478bd9Sstevel@tonic-gate #define MAXLINE 256 10507c478bd9Sstevel@tonic-gate char linebuf[MAXLINE]; 10517c478bd9Sstevel@tonic-gate char *cp, *bp, *lp; 10527c478bd9Sstevel@tonic-gate char *pmaphdr[] = { 10537c478bd9Sstevel@tonic-gate "NULL", "SET", "UNSET", "GETPORT", 10547c478bd9Sstevel@tonic-gate "DUMP", "CALLIT" 10557c478bd9Sstevel@tonic-gate }; 10567c478bd9Sstevel@tonic-gate char *rpcb3hdr[] = { 10577c478bd9Sstevel@tonic-gate "NULL", "SET", "UNSET", "GETADDR", "DUMP", "CALLIT", "TIME", 10587c478bd9Sstevel@tonic-gate "U2T", "T2U" 10597c478bd9Sstevel@tonic-gate }; 10607c478bd9Sstevel@tonic-gate char *rpcb4hdr[] = { 10617c478bd9Sstevel@tonic-gate "NULL", "SET", "UNSET", "GETADDR", "DUMP", "CALLIT", "TIME", 10627c478bd9Sstevel@tonic-gate "U2T", "T2U", "VERADDR", "INDRECT", "GETLIST", "GETSTAT" 10637c478bd9Sstevel@tonic-gate }; 10647c478bd9Sstevel@tonic-gate 10657c478bd9Sstevel@tonic-gate #define TABSTOP 8 10667c478bd9Sstevel@tonic-gate 10677c478bd9Sstevel@tonic-gate if (argc >= 1) { 10687c478bd9Sstevel@tonic-gate host = argv[0]; 10697c478bd9Sstevel@tonic-gate } else { 10707c478bd9Sstevel@tonic-gate uname(&utsname); 10717c478bd9Sstevel@tonic-gate host = utsname.nodename; 10727c478bd9Sstevel@tonic-gate } 10737c478bd9Sstevel@tonic-gate if (loopback_netid != NULL) { 10747c478bd9Sstevel@tonic-gate client = getclnthandle(host, loopback_nconf, RPCBVERS4, NULL); 10757c478bd9Sstevel@tonic-gate if (client == NULL && rpc_createerr.cf_stat == 10767c478bd9Sstevel@tonic-gate RPC_N2AXLATEFAILURE) { 10777c478bd9Sstevel@tonic-gate client = clnt_rpcbind_create(host, RPCBVERS4, NULL); 10787c478bd9Sstevel@tonic-gate } 10797c478bd9Sstevel@tonic-gate } else { 10807c478bd9Sstevel@tonic-gate client = clnt_rpcbind_create(host, RPCBVERS4, NULL); 10817c478bd9Sstevel@tonic-gate } 10827c478bd9Sstevel@tonic-gate if (client == (CLIENT *)NULL) { 10837c478bd9Sstevel@tonic-gate clnt_pcreateerror("rpcinfo: can't contact rpcbind"); 10847c478bd9Sstevel@tonic-gate exit(1); 10857c478bd9Sstevel@tonic-gate } 10867c478bd9Sstevel@tonic-gate minutetimeout.tv_sec = 60; 10877c478bd9Sstevel@tonic-gate minutetimeout.tv_usec = 0; 10887c478bd9Sstevel@tonic-gate memset((char *)&inf, 0, sizeof (rpcb_stat_byvers)); 10897c478bd9Sstevel@tonic-gate if (CLNT_CALL(client, RPCBPROC_GETSTAT, (xdrproc_t)xdr_void, NULL, 10907c478bd9Sstevel@tonic-gate (xdrproc_t)xdr_rpcb_stat_byvers, (char *)&inf, minutetimeout) 10917c478bd9Sstevel@tonic-gate != RPC_SUCCESS) { 10927c478bd9Sstevel@tonic-gate clnt_perror(client, "rpcinfo: can't contact rpcbind: "); 10937c478bd9Sstevel@tonic-gate exit(1); 10947c478bd9Sstevel@tonic-gate } 10957c478bd9Sstevel@tonic-gate printf("PORTMAP (version 2) statistics\n"); 10967c478bd9Sstevel@tonic-gate lp = linebuf; 10977c478bd9Sstevel@tonic-gate for (i = 0; i <= rpcb_highproc_2; i++) { 10987c478bd9Sstevel@tonic-gate fieldbuf[0] = '\0'; 10997c478bd9Sstevel@tonic-gate switch (i) { 11007c478bd9Sstevel@tonic-gate case PMAPPROC_SET: 11017c478bd9Sstevel@tonic-gate sprintf(fieldbuf, "%d/", inf[RPCBVERS_2_STAT].setinfo); 11027c478bd9Sstevel@tonic-gate break; 11037c478bd9Sstevel@tonic-gate case PMAPPROC_UNSET: 11047c478bd9Sstevel@tonic-gate sprintf(fieldbuf, "%d/", 11057c478bd9Sstevel@tonic-gate inf[RPCBVERS_2_STAT].unsetinfo); 11067c478bd9Sstevel@tonic-gate break; 11077c478bd9Sstevel@tonic-gate case PMAPPROC_GETPORT: 11087c478bd9Sstevel@tonic-gate cnt = 0; 11097c478bd9Sstevel@tonic-gate for (pa = inf[RPCBVERS_2_STAT].addrinfo; pa; 11107c478bd9Sstevel@tonic-gate pa = pa->next) 11117c478bd9Sstevel@tonic-gate cnt += pa->success; 11127c478bd9Sstevel@tonic-gate sprintf(fieldbuf, "%d/", cnt); 11137c478bd9Sstevel@tonic-gate break; 11147c478bd9Sstevel@tonic-gate case PMAPPROC_CALLIT: 11157c478bd9Sstevel@tonic-gate cnt = 0; 11167c478bd9Sstevel@tonic-gate for (pr = inf[RPCBVERS_2_STAT].rmtinfo; pr; 11177c478bd9Sstevel@tonic-gate pr = pr->next) 11187c478bd9Sstevel@tonic-gate cnt += pr->success; 11197c478bd9Sstevel@tonic-gate sprintf(fieldbuf, "%d/", cnt); 11207c478bd9Sstevel@tonic-gate break; 11217c478bd9Sstevel@tonic-gate default: break; /* For the remaining ones */ 11227c478bd9Sstevel@tonic-gate } 11237c478bd9Sstevel@tonic-gate cp = &fieldbuf[0] + strlen(fieldbuf); 11247c478bd9Sstevel@tonic-gate sprintf(cp, "%d", inf[RPCBVERS_2_STAT].info[i]); 11257c478bd9Sstevel@tonic-gate flen = strlen(fieldbuf); 11267c478bd9Sstevel@tonic-gate printf("%s%s", pmaphdr[i], 11277c478bd9Sstevel@tonic-gate spaces((TABSTOP * (1 + flen / TABSTOP)) 11287c478bd9Sstevel@tonic-gate - strlen(pmaphdr[i]))); 11297c478bd9Sstevel@tonic-gate sprintf(lp, "%s%s", fieldbuf, 11307c478bd9Sstevel@tonic-gate spaces(cnt = ((TABSTOP * (1 + flen / TABSTOP)) 11317c478bd9Sstevel@tonic-gate - flen))); 11327c478bd9Sstevel@tonic-gate lp += (flen + cnt); 11337c478bd9Sstevel@tonic-gate } 11347c478bd9Sstevel@tonic-gate printf("\n%s\n\n", linebuf); 11357c478bd9Sstevel@tonic-gate 11367c478bd9Sstevel@tonic-gate if (inf[RPCBVERS_2_STAT].info[PMAPPROC_CALLIT]) { 11377c478bd9Sstevel@tonic-gate printf("PMAP_RMTCALL call statistics\n"); 11387c478bd9Sstevel@tonic-gate print_rmtcallstat(RPCBVERS_2_STAT, &inf[RPCBVERS_2_STAT]); 11397c478bd9Sstevel@tonic-gate printf("\n"); 11407c478bd9Sstevel@tonic-gate } 11417c478bd9Sstevel@tonic-gate 11427c478bd9Sstevel@tonic-gate if (inf[RPCBVERS_2_STAT].info[PMAPPROC_GETPORT]) { 11437c478bd9Sstevel@tonic-gate printf("PMAP_GETPORT call statistics\n"); 11447c478bd9Sstevel@tonic-gate print_getaddrstat(RPCBVERS_2_STAT, &inf[RPCBVERS_2_STAT]); 11457c478bd9Sstevel@tonic-gate printf("\n"); 11467c478bd9Sstevel@tonic-gate } 11477c478bd9Sstevel@tonic-gate 11487c478bd9Sstevel@tonic-gate printf("RPCBIND (version 3) statistics\n"); 11497c478bd9Sstevel@tonic-gate lp = linebuf; 11507c478bd9Sstevel@tonic-gate for (i = 0; i <= rpcb_highproc_3; i++) { 11517c478bd9Sstevel@tonic-gate fieldbuf[0] = '\0'; 11527c478bd9Sstevel@tonic-gate switch (i) { 11537c478bd9Sstevel@tonic-gate case RPCBPROC_SET: 11547c478bd9Sstevel@tonic-gate sprintf(fieldbuf, "%d/", inf[RPCBVERS_3_STAT].setinfo); 11557c478bd9Sstevel@tonic-gate break; 11567c478bd9Sstevel@tonic-gate case RPCBPROC_UNSET: 11577c478bd9Sstevel@tonic-gate sprintf(fieldbuf, "%d/", 11587c478bd9Sstevel@tonic-gate inf[RPCBVERS_3_STAT].unsetinfo); 11597c478bd9Sstevel@tonic-gate break; 11607c478bd9Sstevel@tonic-gate case RPCBPROC_GETADDR: 11617c478bd9Sstevel@tonic-gate cnt = 0; 11627c478bd9Sstevel@tonic-gate for (pa = inf[RPCBVERS_3_STAT].addrinfo; pa; 11637c478bd9Sstevel@tonic-gate pa = pa->next) 11647c478bd9Sstevel@tonic-gate cnt += pa->success; 11657c478bd9Sstevel@tonic-gate sprintf(fieldbuf, "%d/", cnt); 11667c478bd9Sstevel@tonic-gate break; 11677c478bd9Sstevel@tonic-gate case RPCBPROC_CALLIT: 11687c478bd9Sstevel@tonic-gate cnt = 0; 11697c478bd9Sstevel@tonic-gate for (pr = inf[RPCBVERS_3_STAT].rmtinfo; pr; 11707c478bd9Sstevel@tonic-gate pr = pr->next) 11717c478bd9Sstevel@tonic-gate cnt += pr->success; 11727c478bd9Sstevel@tonic-gate sprintf(fieldbuf, "%d/", cnt); 11737c478bd9Sstevel@tonic-gate break; 11747c478bd9Sstevel@tonic-gate default: break; /* For the remaining ones */ 11757c478bd9Sstevel@tonic-gate } 11767c478bd9Sstevel@tonic-gate cp = &fieldbuf[0] + strlen(fieldbuf); 11777c478bd9Sstevel@tonic-gate sprintf(cp, "%d", inf[RPCBVERS_3_STAT].info[i]); 11787c478bd9Sstevel@tonic-gate flen = strlen(fieldbuf); 11797c478bd9Sstevel@tonic-gate printf("%s%s", rpcb3hdr[i], 11807c478bd9Sstevel@tonic-gate spaces((TABSTOP * (1 + flen / TABSTOP)) 11817c478bd9Sstevel@tonic-gate - strlen(rpcb3hdr[i]))); 11827c478bd9Sstevel@tonic-gate sprintf(lp, "%s%s", fieldbuf, 11837c478bd9Sstevel@tonic-gate spaces(cnt = ((TABSTOP * (1 + flen / TABSTOP)) 11847c478bd9Sstevel@tonic-gate - flen))); 11857c478bd9Sstevel@tonic-gate lp += (flen + cnt); 11867c478bd9Sstevel@tonic-gate } 11877c478bd9Sstevel@tonic-gate printf("\n%s\n\n", linebuf); 11887c478bd9Sstevel@tonic-gate 11897c478bd9Sstevel@tonic-gate if (inf[RPCBVERS_3_STAT].info[RPCBPROC_CALLIT]) { 11907c478bd9Sstevel@tonic-gate printf("RPCB_RMTCALL (version 3) call statistics\n"); 11917c478bd9Sstevel@tonic-gate print_rmtcallstat(RPCBVERS_3_STAT, &inf[RPCBVERS_3_STAT]); 11927c478bd9Sstevel@tonic-gate printf("\n"); 11937c478bd9Sstevel@tonic-gate } 11947c478bd9Sstevel@tonic-gate 11957c478bd9Sstevel@tonic-gate if (inf[RPCBVERS_3_STAT].info[RPCBPROC_GETADDR]) { 11967c478bd9Sstevel@tonic-gate printf("RPCB_GETADDR (version 3) call statistics\n"); 11977c478bd9Sstevel@tonic-gate print_getaddrstat(RPCBVERS_3_STAT, &inf[RPCBVERS_3_STAT]); 11987c478bd9Sstevel@tonic-gate printf("\n"); 11997c478bd9Sstevel@tonic-gate } 12007c478bd9Sstevel@tonic-gate 12017c478bd9Sstevel@tonic-gate printf("RPCBIND (version 4) statistics\n"); 12027c478bd9Sstevel@tonic-gate 12037c478bd9Sstevel@tonic-gate for (j = 0; j <= 9; j += 9) { /* Just two iterations for printing */ 12047c478bd9Sstevel@tonic-gate lp = linebuf; 12057c478bd9Sstevel@tonic-gate for (i = j; i <= MAX(8, rpcb_highproc_4 - 9 + j); i++) { 12067c478bd9Sstevel@tonic-gate fieldbuf[0] = '\0'; 12077c478bd9Sstevel@tonic-gate switch (i) { 12087c478bd9Sstevel@tonic-gate case RPCBPROC_SET: 12097c478bd9Sstevel@tonic-gate sprintf(fieldbuf, "%d/", 12107c478bd9Sstevel@tonic-gate inf[RPCBVERS_4_STAT].setinfo); 12117c478bd9Sstevel@tonic-gate break; 12127c478bd9Sstevel@tonic-gate case RPCBPROC_UNSET: 12137c478bd9Sstevel@tonic-gate sprintf(fieldbuf, "%d/", 12147c478bd9Sstevel@tonic-gate inf[RPCBVERS_4_STAT].unsetinfo); 12157c478bd9Sstevel@tonic-gate break; 12167c478bd9Sstevel@tonic-gate case RPCBPROC_GETADDR: 12177c478bd9Sstevel@tonic-gate cnt = 0; 12187c478bd9Sstevel@tonic-gate for (pa = inf[RPCBVERS_4_STAT].addrinfo; pa; 12197c478bd9Sstevel@tonic-gate pa = pa->next) 12207c478bd9Sstevel@tonic-gate cnt += pa->success; 12217c478bd9Sstevel@tonic-gate sprintf(fieldbuf, "%d/", cnt); 12227c478bd9Sstevel@tonic-gate break; 12237c478bd9Sstevel@tonic-gate case RPCBPROC_CALLIT: 12247c478bd9Sstevel@tonic-gate cnt = 0; 12257c478bd9Sstevel@tonic-gate for (pr = inf[RPCBVERS_4_STAT].rmtinfo; pr; 12267c478bd9Sstevel@tonic-gate pr = pr->next) 12277c478bd9Sstevel@tonic-gate cnt += pr->success; 12287c478bd9Sstevel@tonic-gate sprintf(fieldbuf, "%d/", cnt); 12297c478bd9Sstevel@tonic-gate break; 12307c478bd9Sstevel@tonic-gate default: break; /* For the remaining ones */ 12317c478bd9Sstevel@tonic-gate } 12327c478bd9Sstevel@tonic-gate cp = &fieldbuf[0] + strlen(fieldbuf); 12337c478bd9Sstevel@tonic-gate /* 12347c478bd9Sstevel@tonic-gate * XXX: We also add RPCBPROC_GETADDRLIST queries to 12357c478bd9Sstevel@tonic-gate * RPCB_GETADDR because rpcbind includes the 12367c478bd9Sstevel@tonic-gate * RPCB_GETADDRLIST successes in RPCB_GETADDR. 12377c478bd9Sstevel@tonic-gate */ 12387c478bd9Sstevel@tonic-gate if (i != RPCBPROC_GETADDR) 12397c478bd9Sstevel@tonic-gate sprintf(cp, "%d", inf[RPCBVERS_4_STAT].info[i]); 12407c478bd9Sstevel@tonic-gate else 12417c478bd9Sstevel@tonic-gate sprintf(cp, "%d", inf[RPCBVERS_4_STAT].info[i] + 12427c478bd9Sstevel@tonic-gate inf[RPCBVERS_4_STAT].info[RPCBPROC_GETADDRLIST]); 12437c478bd9Sstevel@tonic-gate flen = strlen(fieldbuf); 12447c478bd9Sstevel@tonic-gate printf("%s%s", rpcb4hdr[i], 12457c478bd9Sstevel@tonic-gate spaces((TABSTOP * (1 + flen / TABSTOP)) 12467c478bd9Sstevel@tonic-gate - strlen(rpcb4hdr[i]))); 12477c478bd9Sstevel@tonic-gate sprintf(lp, "%s%s", fieldbuf, 12487c478bd9Sstevel@tonic-gate spaces(cnt = ((TABSTOP * (1 + flen / TABSTOP)) 12497c478bd9Sstevel@tonic-gate - flen))); 12507c478bd9Sstevel@tonic-gate lp += (flen + cnt); 12517c478bd9Sstevel@tonic-gate } 12527c478bd9Sstevel@tonic-gate printf("\n%s\n", linebuf); 12537c478bd9Sstevel@tonic-gate } 12547c478bd9Sstevel@tonic-gate 12557c478bd9Sstevel@tonic-gate if (inf[RPCBVERS_4_STAT].info[RPCBPROC_CALLIT] || 12567c478bd9Sstevel@tonic-gate inf[RPCBVERS_4_STAT].info[RPCBPROC_INDIRECT]) { 12577c478bd9Sstevel@tonic-gate printf("\n"); 12587c478bd9Sstevel@tonic-gate printf("RPCB_RMTCALL (version 4) call statistics\n"); 12597c478bd9Sstevel@tonic-gate print_rmtcallstat(RPCBVERS_4_STAT, &inf[RPCBVERS_4_STAT]); 12607c478bd9Sstevel@tonic-gate } 12617c478bd9Sstevel@tonic-gate 12627c478bd9Sstevel@tonic-gate if (inf[RPCBVERS_4_STAT].info[RPCBPROC_GETADDR]) { 12637c478bd9Sstevel@tonic-gate printf("\n"); 12647c478bd9Sstevel@tonic-gate printf("RPCB_GETADDR (version 4) call statistics\n"); 12657c478bd9Sstevel@tonic-gate print_getaddrstat(RPCBVERS_4_STAT, &inf[RPCBVERS_4_STAT]); 12667c478bd9Sstevel@tonic-gate } 12677c478bd9Sstevel@tonic-gate clnt_destroy(client); 12687c478bd9Sstevel@tonic-gate } 12697c478bd9Sstevel@tonic-gate 12707c478bd9Sstevel@tonic-gate /* 12717c478bd9Sstevel@tonic-gate * Delete registeration for this (prog, vers, netid) 12727c478bd9Sstevel@tonic-gate */ 12737c478bd9Sstevel@tonic-gate static void 12747c478bd9Sstevel@tonic-gate deletereg(netid, argc, argv) 12757c478bd9Sstevel@tonic-gate char *netid; 12767c478bd9Sstevel@tonic-gate int argc; 12777c478bd9Sstevel@tonic-gate char **argv; 12787c478bd9Sstevel@tonic-gate { 12797c478bd9Sstevel@tonic-gate struct netconfig *nconf = NULL; 12807c478bd9Sstevel@tonic-gate 12817c478bd9Sstevel@tonic-gate if (argc != 2) { 12827c478bd9Sstevel@tonic-gate usage(); 12837c478bd9Sstevel@tonic-gate exit(1); 12847c478bd9Sstevel@tonic-gate } 12857c478bd9Sstevel@tonic-gate if (netid) { 12867c478bd9Sstevel@tonic-gate nconf = getnetconfigent(netid); 12877c478bd9Sstevel@tonic-gate if (nconf == NULL) { 12887c478bd9Sstevel@tonic-gate fprintf(stderr, "rpcinfo: netid %s not supported\n", 12897c478bd9Sstevel@tonic-gate netid); 12907c478bd9Sstevel@tonic-gate exit(1); 12917c478bd9Sstevel@tonic-gate } 12927c478bd9Sstevel@tonic-gate } 12937c478bd9Sstevel@tonic-gate if ((rpcb_unset(getprognum(argv[0]), getvers(argv[1]), nconf)) == 0) { 12947c478bd9Sstevel@tonic-gate fprintf(stderr, 12957c478bd9Sstevel@tonic-gate "rpcinfo: Could not delete registration for prog %s version %s\n", 12967c478bd9Sstevel@tonic-gate argv[0], argv[1]); 12977c478bd9Sstevel@tonic-gate exit(1); 12987c478bd9Sstevel@tonic-gate } 12997c478bd9Sstevel@tonic-gate } 13007c478bd9Sstevel@tonic-gate 13017c478bd9Sstevel@tonic-gate /* 13027c478bd9Sstevel@tonic-gate * Create and return a handle for the given nconf. 13037c478bd9Sstevel@tonic-gate * Exit if cannot create handle. 13047c478bd9Sstevel@tonic-gate */ 13057c478bd9Sstevel@tonic-gate static CLIENT * 13067c478bd9Sstevel@tonic-gate clnt_addr_create(address, nconf, prog, vers) 13077c478bd9Sstevel@tonic-gate char *address; 13087c478bd9Sstevel@tonic-gate struct netconfig *nconf; 13097c478bd9Sstevel@tonic-gate ulong_t prog; 13107c478bd9Sstevel@tonic-gate ulong_t vers; 13117c478bd9Sstevel@tonic-gate { 13127c478bd9Sstevel@tonic-gate CLIENT *client; 13137c478bd9Sstevel@tonic-gate static struct netbuf *nbuf; 13147c478bd9Sstevel@tonic-gate static int fd = RPC_ANYFD; 13157c478bd9Sstevel@tonic-gate struct t_info tinfo; 13167c478bd9Sstevel@tonic-gate 13177c478bd9Sstevel@tonic-gate if (fd == RPC_ANYFD) { 13187c478bd9Sstevel@tonic-gate if ((fd = t_open(nconf->nc_device, O_RDWR, &tinfo)) == -1) { 13197c478bd9Sstevel@tonic-gate rpc_createerr.cf_stat = RPC_TLIERROR; 13207c478bd9Sstevel@tonic-gate rpc_createerr.cf_error.re_terrno = t_errno; 13217c478bd9Sstevel@tonic-gate clnt_pcreateerror("rpcinfo"); 13227c478bd9Sstevel@tonic-gate exit(1); 13237c478bd9Sstevel@tonic-gate } 13247c478bd9Sstevel@tonic-gate /* Convert the uaddr to taddr */ 13257c478bd9Sstevel@tonic-gate nbuf = uaddr2taddr(nconf, address); 13267c478bd9Sstevel@tonic-gate if (nbuf == NULL) { 13277c478bd9Sstevel@tonic-gate netdir_perror("rpcinfo"); 13287c478bd9Sstevel@tonic-gate exit(1); 13297c478bd9Sstevel@tonic-gate } 13307c478bd9Sstevel@tonic-gate } 13317c478bd9Sstevel@tonic-gate client = clnt_tli_create(fd, nconf, nbuf, prog, vers, 0, 0); 13327c478bd9Sstevel@tonic-gate if (client == (CLIENT *)NULL) { 13337c478bd9Sstevel@tonic-gate clnt_pcreateerror("rpcinfo"); 13347c478bd9Sstevel@tonic-gate exit(1); 13357c478bd9Sstevel@tonic-gate } 13367c478bd9Sstevel@tonic-gate return (client); 13377c478bd9Sstevel@tonic-gate } 13387c478bd9Sstevel@tonic-gate 13397c478bd9Sstevel@tonic-gate /* 13407c478bd9Sstevel@tonic-gate * If the version number is given, ping that (prog, vers); else try to find 13417c478bd9Sstevel@tonic-gate * the version numbers supported for that prog and ping all the versions. 13427c478bd9Sstevel@tonic-gate * Remote rpcbind is not contacted for this service. The requests are 13437c478bd9Sstevel@tonic-gate * sent directly to the services themselves. 13447c478bd9Sstevel@tonic-gate */ 13457c478bd9Sstevel@tonic-gate static void 13467c478bd9Sstevel@tonic-gate addrping(address, netid, argc, argv) 13477c478bd9Sstevel@tonic-gate char *address; 13487c478bd9Sstevel@tonic-gate char *netid; 13497c478bd9Sstevel@tonic-gate int argc; 13507c478bd9Sstevel@tonic-gate char **argv; 13517c478bd9Sstevel@tonic-gate { 13527c478bd9Sstevel@tonic-gate CLIENT *client; 13537c478bd9Sstevel@tonic-gate struct timeval to; 13547c478bd9Sstevel@tonic-gate enum clnt_stat rpc_stat; 13557c478bd9Sstevel@tonic-gate ulong_t prognum, versnum, minvers, maxvers; 13567c478bd9Sstevel@tonic-gate struct rpc_err rpcerr; 13577c478bd9Sstevel@tonic-gate int failure = 0; 13587c478bd9Sstevel@tonic-gate struct netconfig *nconf; 13597c478bd9Sstevel@tonic-gate int fd; 13607c478bd9Sstevel@tonic-gate 13617c478bd9Sstevel@tonic-gate if (argc < 1 || argc > 2 || (netid == NULL)) { 13627c478bd9Sstevel@tonic-gate usage(); 13637c478bd9Sstevel@tonic-gate exit(1); 13647c478bd9Sstevel@tonic-gate } 13657c478bd9Sstevel@tonic-gate nconf = getnetconfigent(netid); 13667c478bd9Sstevel@tonic-gate if (nconf == (struct netconfig *)NULL) { 13677c478bd9Sstevel@tonic-gate fprintf(stderr, "rpcinfo: Could not find %s\n", netid); 13687c478bd9Sstevel@tonic-gate exit(1); 13697c478bd9Sstevel@tonic-gate } 13707c478bd9Sstevel@tonic-gate to.tv_sec = 10; 13717c478bd9Sstevel@tonic-gate to.tv_usec = 0; 13727c478bd9Sstevel@tonic-gate prognum = getprognum(argv[0]); 13737c478bd9Sstevel@tonic-gate if (argc == 1) { /* Version number not known */ 13747c478bd9Sstevel@tonic-gate /* 13757c478bd9Sstevel@tonic-gate * A call to version 0 should fail with a program/version 13767c478bd9Sstevel@tonic-gate * mismatch, and give us the range of versions supported. 13777c478bd9Sstevel@tonic-gate */ 13787c478bd9Sstevel@tonic-gate versnum = MIN_VERS; 13797c478bd9Sstevel@tonic-gate } else { 13807c478bd9Sstevel@tonic-gate versnum = getvers(argv[1]); 13817c478bd9Sstevel@tonic-gate } 13827c478bd9Sstevel@tonic-gate client = clnt_addr_create(address, nconf, prognum, versnum); 13837c478bd9Sstevel@tonic-gate rpc_stat = CLNT_CALL(client, NULLPROC, (xdrproc_t)xdr_void, 13847c478bd9Sstevel@tonic-gate (char *)NULL, (xdrproc_t)xdr_void, 13857c478bd9Sstevel@tonic-gate (char *)NULL, to); 13867c478bd9Sstevel@tonic-gate if (argc == 2) { 13877c478bd9Sstevel@tonic-gate /* Version number was known */ 13887c478bd9Sstevel@tonic-gate if (pstatus(client, prognum, versnum) < 0) 13897c478bd9Sstevel@tonic-gate failure = 1; 13907c478bd9Sstevel@tonic-gate (void) CLNT_DESTROY(client); 13917c478bd9Sstevel@tonic-gate if (failure) 13927c478bd9Sstevel@tonic-gate exit(1); 13937c478bd9Sstevel@tonic-gate return; 13947c478bd9Sstevel@tonic-gate } 13957c478bd9Sstevel@tonic-gate /* Version number not known */ 13967c478bd9Sstevel@tonic-gate (void) CLNT_CONTROL(client, CLSET_FD_NCLOSE, (char *)NULL); 13977c478bd9Sstevel@tonic-gate (void) CLNT_CONTROL(client, CLGET_FD, (char *)&fd); 13987c478bd9Sstevel@tonic-gate if (rpc_stat == RPC_PROGVERSMISMATCH) { 13997c478bd9Sstevel@tonic-gate clnt_geterr(client, &rpcerr); 14007c478bd9Sstevel@tonic-gate minvers = rpcerr.re_vers.low; 14017c478bd9Sstevel@tonic-gate maxvers = rpcerr.re_vers.high; 14027c478bd9Sstevel@tonic-gate } else if (rpc_stat == RPC_SUCCESS) { 14037c478bd9Sstevel@tonic-gate /* 14047c478bd9Sstevel@tonic-gate * Oh dear, it DOES support version 0. 14057c478bd9Sstevel@tonic-gate * Let's try version MAX_VERS. 14067c478bd9Sstevel@tonic-gate */ 14077c478bd9Sstevel@tonic-gate (void) CLNT_DESTROY(client); 14087c478bd9Sstevel@tonic-gate client = clnt_addr_create(address, nconf, prognum, MAX_VERS); 14097c478bd9Sstevel@tonic-gate rpc_stat = CLNT_CALL(client, NULLPROC, (xdrproc_t)xdr_void, 14107c478bd9Sstevel@tonic-gate (char *)NULL, (xdrproc_t)xdr_void, 14117c478bd9Sstevel@tonic-gate (char *)NULL, to); 14127c478bd9Sstevel@tonic-gate if (rpc_stat == RPC_PROGVERSMISMATCH) { 14137c478bd9Sstevel@tonic-gate clnt_geterr(client, &rpcerr); 14147c478bd9Sstevel@tonic-gate minvers = rpcerr.re_vers.low; 14157c478bd9Sstevel@tonic-gate maxvers = rpcerr.re_vers.high; 14167c478bd9Sstevel@tonic-gate } else if (rpc_stat == RPC_SUCCESS) { 14177c478bd9Sstevel@tonic-gate /* 14187c478bd9Sstevel@tonic-gate * It also supports version MAX_VERS. 14197c478bd9Sstevel@tonic-gate * Looks like we have a wise guy. 14207c478bd9Sstevel@tonic-gate * OK, we give them information on all 14217c478bd9Sstevel@tonic-gate * 4 billion versions they support... 14227c478bd9Sstevel@tonic-gate */ 14237c478bd9Sstevel@tonic-gate minvers = 0; 14247c478bd9Sstevel@tonic-gate maxvers = MAX_VERS; 14257c478bd9Sstevel@tonic-gate } else { 14267c478bd9Sstevel@tonic-gate (void) pstatus(client, prognum, MAX_VERS); 14277c478bd9Sstevel@tonic-gate exit(1); 14287c478bd9Sstevel@tonic-gate } 14297c478bd9Sstevel@tonic-gate } else { 14307c478bd9Sstevel@tonic-gate (void) pstatus(client, prognum, (ulong_t)0); 14317c478bd9Sstevel@tonic-gate exit(1); 14327c478bd9Sstevel@tonic-gate } 14337c478bd9Sstevel@tonic-gate (void) CLNT_DESTROY(client); 14347c478bd9Sstevel@tonic-gate for (versnum = minvers; versnum <= maxvers; versnum++) { 14357c478bd9Sstevel@tonic-gate client = clnt_addr_create(address, nconf, prognum, versnum); 14367c478bd9Sstevel@tonic-gate rpc_stat = CLNT_CALL(client, NULLPROC, (xdrproc_t)xdr_void, 14377c478bd9Sstevel@tonic-gate (char *)NULL, (xdrproc_t)xdr_void, 14387c478bd9Sstevel@tonic-gate (char *)NULL, to); 14397c478bd9Sstevel@tonic-gate if (pstatus(client, prognum, versnum) < 0) 14407c478bd9Sstevel@tonic-gate failure = 1; 14417c478bd9Sstevel@tonic-gate (void) CLNT_DESTROY(client); 14427c478bd9Sstevel@tonic-gate } 14437c478bd9Sstevel@tonic-gate (void) t_close(fd); 14447c478bd9Sstevel@tonic-gate if (failure) 14457c478bd9Sstevel@tonic-gate exit(1); 14467c478bd9Sstevel@tonic-gate } 14477c478bd9Sstevel@tonic-gate 14487c478bd9Sstevel@tonic-gate /* 14497c478bd9Sstevel@tonic-gate * If the version number is given, ping that (prog, vers); else try to find 14507c478bd9Sstevel@tonic-gate * the version numbers supported for that prog and ping all the versions. 14517c478bd9Sstevel@tonic-gate * Remote rpcbind is *contacted* for this service. The requests are 14527c478bd9Sstevel@tonic-gate * then sent directly to the services themselves. 14537c478bd9Sstevel@tonic-gate */ 14547c478bd9Sstevel@tonic-gate static void 14557c478bd9Sstevel@tonic-gate progping(netid, argc, argv) 14567c478bd9Sstevel@tonic-gate char *netid; 14577c478bd9Sstevel@tonic-gate int argc; 14587c478bd9Sstevel@tonic-gate char **argv; 14597c478bd9Sstevel@tonic-gate { 14607c478bd9Sstevel@tonic-gate CLIENT *client; 14617c478bd9Sstevel@tonic-gate struct timeval to; 14627c478bd9Sstevel@tonic-gate enum clnt_stat rpc_stat; 14637c478bd9Sstevel@tonic-gate ulong_t prognum, versnum, minvers, maxvers; 14647c478bd9Sstevel@tonic-gate struct rpc_err rpcerr; 14657c478bd9Sstevel@tonic-gate int failure = 0; 14667c478bd9Sstevel@tonic-gate struct netconfig *nconf; 14677c478bd9Sstevel@tonic-gate int fd; 14687c478bd9Sstevel@tonic-gate 14697c478bd9Sstevel@tonic-gate if (argc < 2 || argc > 3 || (netid == NULL)) { 14707c478bd9Sstevel@tonic-gate usage(); 14717c478bd9Sstevel@tonic-gate exit(1); 14727c478bd9Sstevel@tonic-gate } 14737c478bd9Sstevel@tonic-gate prognum = getprognum(argv[1]); 14747c478bd9Sstevel@tonic-gate if (argc == 2) { /* Version number not known */ 14757c478bd9Sstevel@tonic-gate /* 14767c478bd9Sstevel@tonic-gate * A call to version 0 should fail with a program/version 14777c478bd9Sstevel@tonic-gate * mismatch, and give us the range of versions supported. 14787c478bd9Sstevel@tonic-gate */ 14797c478bd9Sstevel@tonic-gate versnum = MIN_VERS; 14807c478bd9Sstevel@tonic-gate } else { 14817c478bd9Sstevel@tonic-gate versnum = getvers(argv[2]); 14827c478bd9Sstevel@tonic-gate } 14837c478bd9Sstevel@tonic-gate if (netid) { 14847c478bd9Sstevel@tonic-gate nconf = getnetconfigent(netid); 14857c478bd9Sstevel@tonic-gate if (nconf == (struct netconfig *)NULL) { 14867c478bd9Sstevel@tonic-gate fprintf(stderr, "rpcinfo: Could not find %s\n", netid); 14877c478bd9Sstevel@tonic-gate exit(1); 14887c478bd9Sstevel@tonic-gate } 14897c478bd9Sstevel@tonic-gate client = clnt_tp_create(argv[0], prognum, versnum, nconf); 14907c478bd9Sstevel@tonic-gate } else { 14917c478bd9Sstevel@tonic-gate client = clnt_create(argv[0], prognum, versnum, "NETPATH"); 14927c478bd9Sstevel@tonic-gate } 14937c478bd9Sstevel@tonic-gate if (client == (CLIENT *)NULL) { 14947c478bd9Sstevel@tonic-gate clnt_pcreateerror("rpcinfo"); 14957c478bd9Sstevel@tonic-gate exit(1); 14967c478bd9Sstevel@tonic-gate } 14977c478bd9Sstevel@tonic-gate to.tv_sec = 10; 14987c478bd9Sstevel@tonic-gate to.tv_usec = 0; 14997c478bd9Sstevel@tonic-gate rpc_stat = CLNT_CALL(client, NULLPROC, (xdrproc_t)xdr_void, 15007c478bd9Sstevel@tonic-gate (char *)NULL, (xdrproc_t)xdr_void, 15017c478bd9Sstevel@tonic-gate (char *)NULL, to); 15027c478bd9Sstevel@tonic-gate if (argc == 3) { 15037c478bd9Sstevel@tonic-gate /* Version number was known */ 15047c478bd9Sstevel@tonic-gate if (pstatus(client, prognum, versnum) < 0) 15057c478bd9Sstevel@tonic-gate failure = 1; 15067c478bd9Sstevel@tonic-gate (void) CLNT_DESTROY(client); 15077c478bd9Sstevel@tonic-gate if (failure) 15087c478bd9Sstevel@tonic-gate exit(1); 15097c478bd9Sstevel@tonic-gate return; 15107c478bd9Sstevel@tonic-gate } 15117c478bd9Sstevel@tonic-gate /* Version number not known */ 15127c478bd9Sstevel@tonic-gate if (rpc_stat == RPC_PROGVERSMISMATCH) { 15137c478bd9Sstevel@tonic-gate clnt_geterr(client, &rpcerr); 15147c478bd9Sstevel@tonic-gate minvers = rpcerr.re_vers.low; 15157c478bd9Sstevel@tonic-gate maxvers = rpcerr.re_vers.high; 15167c478bd9Sstevel@tonic-gate } else if (rpc_stat == RPC_SUCCESS) { 15177c478bd9Sstevel@tonic-gate /* 15187c478bd9Sstevel@tonic-gate * Oh dear, it DOES support version 0. 15197c478bd9Sstevel@tonic-gate * Let's try version MAX_VERS. 15207c478bd9Sstevel@tonic-gate */ 15217c478bd9Sstevel@tonic-gate versnum = MAX_VERS; 15227c478bd9Sstevel@tonic-gate (void) CLNT_CONTROL(client, CLSET_VERS, (char *)&versnum); 15237c478bd9Sstevel@tonic-gate rpc_stat = CLNT_CALL(client, NULLPROC, 15247c478bd9Sstevel@tonic-gate (xdrproc_t)xdr_void, (char *)NULL, 15257c478bd9Sstevel@tonic-gate (xdrproc_t)xdr_void, (char *)NULL, to); 15267c478bd9Sstevel@tonic-gate if (rpc_stat == RPC_PROGVERSMISMATCH) { 15277c478bd9Sstevel@tonic-gate clnt_geterr(client, &rpcerr); 15287c478bd9Sstevel@tonic-gate minvers = rpcerr.re_vers.low; 15297c478bd9Sstevel@tonic-gate maxvers = rpcerr.re_vers.high; 15307c478bd9Sstevel@tonic-gate } else if (rpc_stat == RPC_SUCCESS) { 15317c478bd9Sstevel@tonic-gate /* 15327c478bd9Sstevel@tonic-gate * It also supports version MAX_VERS. 15337c478bd9Sstevel@tonic-gate * Looks like we have a wise guy. 15347c478bd9Sstevel@tonic-gate * OK, we give them information on all 15357c478bd9Sstevel@tonic-gate * 4 billion versions they support... 15367c478bd9Sstevel@tonic-gate */ 15377c478bd9Sstevel@tonic-gate minvers = 0; 15387c478bd9Sstevel@tonic-gate maxvers = MAX_VERS; 15397c478bd9Sstevel@tonic-gate } else { 15407c478bd9Sstevel@tonic-gate (void) pstatus(client, prognum, MAX_VERS); 15417c478bd9Sstevel@tonic-gate exit(1); 15427c478bd9Sstevel@tonic-gate } 15437c478bd9Sstevel@tonic-gate } else { 15447c478bd9Sstevel@tonic-gate (void) pstatus(client, prognum, (ulong_t)0); 15457c478bd9Sstevel@tonic-gate exit(1); 15467c478bd9Sstevel@tonic-gate } 15477c478bd9Sstevel@tonic-gate for (versnum = minvers; versnum <= maxvers; versnum++) { 15487c478bd9Sstevel@tonic-gate (void) CLNT_CONTROL(client, CLSET_VERS, (char *)&versnum); 15497c478bd9Sstevel@tonic-gate rpc_stat = CLNT_CALL(client, NULLPROC, (xdrproc_t)xdr_void, 15507c478bd9Sstevel@tonic-gate (char *)NULL, (xdrproc_t)xdr_void, 15517c478bd9Sstevel@tonic-gate (char *)NULL, to); 15527c478bd9Sstevel@tonic-gate if (pstatus(client, prognum, versnum) < 0) 15537c478bd9Sstevel@tonic-gate failure = 1; 15547c478bd9Sstevel@tonic-gate } 15557c478bd9Sstevel@tonic-gate (void) CLNT_DESTROY(client); 15567c478bd9Sstevel@tonic-gate if (failure) 15577c478bd9Sstevel@tonic-gate exit(1); 15587c478bd9Sstevel@tonic-gate } 15597c478bd9Sstevel@tonic-gate 15607c478bd9Sstevel@tonic-gate static void 15617c478bd9Sstevel@tonic-gate usage() 15627c478bd9Sstevel@tonic-gate { 15637c478bd9Sstevel@tonic-gate fprintf(stderr, "Usage: rpcinfo [-m | -s] [host]\n"); 15647c478bd9Sstevel@tonic-gate #ifdef PORTMAP 15657c478bd9Sstevel@tonic-gate fprintf(stderr, " rpcinfo -p [host]\n"); 15667c478bd9Sstevel@tonic-gate #endif 15677c478bd9Sstevel@tonic-gate fprintf(stderr, " rpcinfo -T netid host prognum [versnum]\n"); 15687c478bd9Sstevel@tonic-gate fprintf(stderr, " rpcinfo -l host prognum versnum\n"); 15697c478bd9Sstevel@tonic-gate #ifdef PORTMAP 15707c478bd9Sstevel@tonic-gate fprintf(stderr, 15717c478bd9Sstevel@tonic-gate " rpcinfo [-n portnum] -u | -t host prognum [versnum]\n"); 15727c478bd9Sstevel@tonic-gate #endif 15737c478bd9Sstevel@tonic-gate fprintf(stderr, 15747c478bd9Sstevel@tonic-gate " rpcinfo -a serv_address -T netid prognum [version]\n"); 15757c478bd9Sstevel@tonic-gate fprintf(stderr, " rpcinfo -b prognum versnum\n"); 15767c478bd9Sstevel@tonic-gate fprintf(stderr, " rpcinfo -d [-T netid] prognum versnum\n"); 15777c478bd9Sstevel@tonic-gate } 15787c478bd9Sstevel@tonic-gate 15797c478bd9Sstevel@tonic-gate static ulong_t 15807c478bd9Sstevel@tonic-gate getprognum (arg) 15817c478bd9Sstevel@tonic-gate char *arg; 15827c478bd9Sstevel@tonic-gate { 15837c478bd9Sstevel@tonic-gate char *strptr; 15847c478bd9Sstevel@tonic-gate register struct rpcent *rpc; 15857c478bd9Sstevel@tonic-gate register ulong_t prognum; 15867c478bd9Sstevel@tonic-gate char *tptr = arg; 15877c478bd9Sstevel@tonic-gate 15887c478bd9Sstevel@tonic-gate while (*tptr && isdigit(*tptr++)); 15897c478bd9Sstevel@tonic-gate if (*tptr || isalpha(*(tptr - 1))) { 15907c478bd9Sstevel@tonic-gate rpc = getrpcbyname(arg); 15917c478bd9Sstevel@tonic-gate if (rpc == NULL) { 15927c478bd9Sstevel@tonic-gate fprintf(stderr, "rpcinfo: %s is unknown service\n", 15937c478bd9Sstevel@tonic-gate arg); 15947c478bd9Sstevel@tonic-gate exit(1); 15957c478bd9Sstevel@tonic-gate } 15967c478bd9Sstevel@tonic-gate prognum = rpc->r_number; 15977c478bd9Sstevel@tonic-gate } else { 15987c478bd9Sstevel@tonic-gate prognum = strtol(arg, &strptr, 10); 15997c478bd9Sstevel@tonic-gate if (strptr == arg || *strptr != '\0') { 16007c478bd9Sstevel@tonic-gate fprintf(stderr, 16017c478bd9Sstevel@tonic-gate "rpcinfo: %s is illegal program number\n", arg); 16027c478bd9Sstevel@tonic-gate exit(1); 16037c478bd9Sstevel@tonic-gate } 16047c478bd9Sstevel@tonic-gate } 16057c478bd9Sstevel@tonic-gate return (prognum); 16067c478bd9Sstevel@tonic-gate } 16077c478bd9Sstevel@tonic-gate 16087c478bd9Sstevel@tonic-gate static ulong_t 16097c478bd9Sstevel@tonic-gate getvers(arg) 16107c478bd9Sstevel@tonic-gate char *arg; 16117c478bd9Sstevel@tonic-gate { 16127c478bd9Sstevel@tonic-gate char *strptr; 16137c478bd9Sstevel@tonic-gate register ulong_t vers; 16147c478bd9Sstevel@tonic-gate 16157c478bd9Sstevel@tonic-gate vers = (int)strtol(arg, &strptr, 10); 16167c478bd9Sstevel@tonic-gate if (strptr == arg || *strptr != '\0') { 16177c478bd9Sstevel@tonic-gate fprintf(stderr, "rpcinfo: %s is illegal version number\n", 16187c478bd9Sstevel@tonic-gate arg); 16197c478bd9Sstevel@tonic-gate exit(1); 16207c478bd9Sstevel@tonic-gate } 16217c478bd9Sstevel@tonic-gate return (vers); 16227c478bd9Sstevel@tonic-gate } 16237c478bd9Sstevel@tonic-gate 16247c478bd9Sstevel@tonic-gate /* 16257c478bd9Sstevel@tonic-gate * This routine should take a pointer to an "rpc_err" structure, rather than 16267c478bd9Sstevel@tonic-gate * a pointer to a CLIENT structure, but "clnt_perror" takes a pointer to 16277c478bd9Sstevel@tonic-gate * a CLIENT structure rather than a pointer to an "rpc_err" structure. 16287c478bd9Sstevel@tonic-gate * As such, we have to keep the CLIENT structure around in order to print 16297c478bd9Sstevel@tonic-gate * a good error message. 16307c478bd9Sstevel@tonic-gate */ 16317c478bd9Sstevel@tonic-gate static int 16327c478bd9Sstevel@tonic-gate pstatus(client, prog, vers) 16337c478bd9Sstevel@tonic-gate register CLIENT *client; 16347c478bd9Sstevel@tonic-gate ulong_t prog; 16357c478bd9Sstevel@tonic-gate ulong_t vers; 16367c478bd9Sstevel@tonic-gate { 16377c478bd9Sstevel@tonic-gate struct rpc_err rpcerr; 16387c478bd9Sstevel@tonic-gate 16397c478bd9Sstevel@tonic-gate clnt_geterr(client, &rpcerr); 16407c478bd9Sstevel@tonic-gate if (rpcerr.re_status != RPC_SUCCESS) { 16417c478bd9Sstevel@tonic-gate clnt_perror(client, "rpcinfo"); 16427c478bd9Sstevel@tonic-gate printf("program %lu version %lu is not available\n", 16437c478bd9Sstevel@tonic-gate prog, vers); 16447c478bd9Sstevel@tonic-gate return (-1); 16457c478bd9Sstevel@tonic-gate } else { 16467c478bd9Sstevel@tonic-gate printf("program %lu version %lu ready and waiting\n", 16477c478bd9Sstevel@tonic-gate prog, vers); 16487c478bd9Sstevel@tonic-gate return (0); 16497c478bd9Sstevel@tonic-gate } 16507c478bd9Sstevel@tonic-gate } 16517c478bd9Sstevel@tonic-gate 16527c478bd9Sstevel@tonic-gate static CLIENT * 16537c478bd9Sstevel@tonic-gate clnt_rpcbind_create(host, rpcbversnum, targaddr) 16547c478bd9Sstevel@tonic-gate char *host; 16557c478bd9Sstevel@tonic-gate ulong_t rpcbversnum; 16567c478bd9Sstevel@tonic-gate struct netbuf **targaddr; 16577c478bd9Sstevel@tonic-gate { 16587c478bd9Sstevel@tonic-gate static char *tlist[3] = { 16597c478bd9Sstevel@tonic-gate "circuit_n", "circuit_v", "datagram_v" 16607c478bd9Sstevel@tonic-gate }; 16617c478bd9Sstevel@tonic-gate int i; 16627c478bd9Sstevel@tonic-gate struct netconfig *nconf; 16637c478bd9Sstevel@tonic-gate CLIENT *clnt = NULL; 16647c478bd9Sstevel@tonic-gate void *handle; 16657c478bd9Sstevel@tonic-gate 16667c478bd9Sstevel@tonic-gate rpc_createerr.cf_stat = RPC_SUCCESS; 16677c478bd9Sstevel@tonic-gate for (i = 0; i < 3; i++) { 16687c478bd9Sstevel@tonic-gate if ((handle = __rpc_setconf(tlist[i])) == NULL) 16697c478bd9Sstevel@tonic-gate continue; 16707c478bd9Sstevel@tonic-gate while (clnt == (CLIENT *)NULL) { 16717c478bd9Sstevel@tonic-gate if ((nconf = __rpc_getconf(handle)) == NULL) { 16727c478bd9Sstevel@tonic-gate if (rpc_createerr.cf_stat == RPC_SUCCESS) 16737c478bd9Sstevel@tonic-gate rpc_createerr.cf_stat = RPC_UNKNOWNPROTO; 16747c478bd9Sstevel@tonic-gate break; 16757c478bd9Sstevel@tonic-gate } 16767c478bd9Sstevel@tonic-gate clnt = getclnthandle(host, nconf, rpcbversnum, 16777c478bd9Sstevel@tonic-gate targaddr); 16787c478bd9Sstevel@tonic-gate } 16797c478bd9Sstevel@tonic-gate if (clnt) 16807c478bd9Sstevel@tonic-gate break; 16817c478bd9Sstevel@tonic-gate __rpc_endconf(handle); 16827c478bd9Sstevel@tonic-gate } 16837c478bd9Sstevel@tonic-gate return (clnt); 16847c478bd9Sstevel@tonic-gate } 16857c478bd9Sstevel@tonic-gate 16867c478bd9Sstevel@tonic-gate static CLIENT* 16877c478bd9Sstevel@tonic-gate getclnthandle(host, nconf, rpcbversnum, targaddr) 16887c478bd9Sstevel@tonic-gate char *host; 16897c478bd9Sstevel@tonic-gate struct netconfig *nconf; 16907c478bd9Sstevel@tonic-gate ulong_t rpcbversnum; 16917c478bd9Sstevel@tonic-gate struct netbuf **targaddr; 16927c478bd9Sstevel@tonic-gate { 16937c478bd9Sstevel@tonic-gate struct netbuf *addr; 16947c478bd9Sstevel@tonic-gate struct nd_addrlist *nas; 16957c478bd9Sstevel@tonic-gate struct nd_hostserv rpcbind_hs; 16967c478bd9Sstevel@tonic-gate CLIENT *client = NULL; 16977c478bd9Sstevel@tonic-gate 16987c478bd9Sstevel@tonic-gate /* Get the address of the rpcbind */ 16997c478bd9Sstevel@tonic-gate rpcbind_hs.h_host = host; 17007c478bd9Sstevel@tonic-gate rpcbind_hs.h_serv = "rpcbind"; 17017c478bd9Sstevel@tonic-gate if (netdir_getbyname(nconf, &rpcbind_hs, &nas)) { 17027c478bd9Sstevel@tonic-gate rpc_createerr.cf_stat = RPC_N2AXLATEFAILURE; 17037c478bd9Sstevel@tonic-gate return (NULL); 17047c478bd9Sstevel@tonic-gate } 17057c478bd9Sstevel@tonic-gate addr = nas->n_addrs; 17067c478bd9Sstevel@tonic-gate client = clnt_tli_create(RPC_ANYFD, nconf, addr, RPCBPROG, 17077c478bd9Sstevel@tonic-gate rpcbversnum, 0, 0); 17087c478bd9Sstevel@tonic-gate if (client) { 17097c478bd9Sstevel@tonic-gate if (targaddr != NULL) { 17107c478bd9Sstevel@tonic-gate *targaddr = 17117c478bd9Sstevel@tonic-gate (struct netbuf *)malloc(sizeof (struct netbuf)); 17127c478bd9Sstevel@tonic-gate if (*targaddr != NULL) { 17137c478bd9Sstevel@tonic-gate (*targaddr)->maxlen = addr->maxlen; 17147c478bd9Sstevel@tonic-gate (*targaddr)->len = addr->len; 17157c478bd9Sstevel@tonic-gate (*targaddr)->buf = (char *)malloc(addr->len); 17167c478bd9Sstevel@tonic-gate if ((*targaddr)->buf != NULL) { 17177c478bd9Sstevel@tonic-gate memcpy((*targaddr)->buf, addr->buf, 17187c478bd9Sstevel@tonic-gate addr->len); 17197c478bd9Sstevel@tonic-gate } 17207c478bd9Sstevel@tonic-gate } 17217c478bd9Sstevel@tonic-gate } 17227c478bd9Sstevel@tonic-gate } else { 17237c478bd9Sstevel@tonic-gate if (rpc_createerr.cf_stat == RPC_TLIERROR) { 17247c478bd9Sstevel@tonic-gate /* 17257c478bd9Sstevel@tonic-gate * Assume that the other system is dead; this is a 17267c478bd9Sstevel@tonic-gate * better error to display to the user. 17277c478bd9Sstevel@tonic-gate */ 17287c478bd9Sstevel@tonic-gate rpc_createerr.cf_stat = RPC_RPCBFAILURE; 17297c478bd9Sstevel@tonic-gate rpc_createerr.cf_error.re_status = RPC_FAILED; 17307c478bd9Sstevel@tonic-gate } 17317c478bd9Sstevel@tonic-gate } 17327c478bd9Sstevel@tonic-gate netdir_free((char *)nas, ND_ADDRLIST); 17337c478bd9Sstevel@tonic-gate return (client); 17347c478bd9Sstevel@tonic-gate } 17357c478bd9Sstevel@tonic-gate 17367c478bd9Sstevel@tonic-gate static void 17377c478bd9Sstevel@tonic-gate print_rmtcallstat(rtype, infp) 17387c478bd9Sstevel@tonic-gate int rtype; 17397c478bd9Sstevel@tonic-gate rpcb_stat *infp; 17407c478bd9Sstevel@tonic-gate { 17417c478bd9Sstevel@tonic-gate register rpcbs_rmtcalllist_ptr pr; 17427c478bd9Sstevel@tonic-gate struct rpcent *rpc; 17437c478bd9Sstevel@tonic-gate 17447c478bd9Sstevel@tonic-gate if (rtype == RPCBVERS_4_STAT) 17457c478bd9Sstevel@tonic-gate printf( 17467c478bd9Sstevel@tonic-gate "prog\t\tvers\tproc\tnetid\tindirect success failure\n"); 17477c478bd9Sstevel@tonic-gate else 17487c478bd9Sstevel@tonic-gate printf("prog\t\tvers\tproc\tnetid\tsuccess\tfailure\n"); 17497c478bd9Sstevel@tonic-gate for (pr = infp->rmtinfo; pr; pr = pr->next) { 17507c478bd9Sstevel@tonic-gate rpc = getrpcbynumber(pr->prog); 17517c478bd9Sstevel@tonic-gate if (rpc) 17527c478bd9Sstevel@tonic-gate printf("%-16s", rpc->r_name); 17537c478bd9Sstevel@tonic-gate else 17547c478bd9Sstevel@tonic-gate printf("%-16d", pr->prog); 17557c478bd9Sstevel@tonic-gate printf("%d\t%d\t%-7s ", 17567c478bd9Sstevel@tonic-gate pr->vers, pr->proc, pr->netid); 17577c478bd9Sstevel@tonic-gate if (rtype == RPCBVERS_4_STAT) 17587c478bd9Sstevel@tonic-gate printf("%d\t ", pr->indirect); 17597c478bd9Sstevel@tonic-gate printf("%d\t%d\n", pr->success, pr->failure); 17607c478bd9Sstevel@tonic-gate } 17617c478bd9Sstevel@tonic-gate } 17627c478bd9Sstevel@tonic-gate 17637c478bd9Sstevel@tonic-gate static void 17647c478bd9Sstevel@tonic-gate print_getaddrstat(rtype, infp) 17657c478bd9Sstevel@tonic-gate int rtype; 17667c478bd9Sstevel@tonic-gate rpcb_stat *infp; 17677c478bd9Sstevel@tonic-gate { 17687c478bd9Sstevel@tonic-gate rpcbs_addrlist_ptr al; 17697c478bd9Sstevel@tonic-gate register struct rpcent *rpc; 17707c478bd9Sstevel@tonic-gate 17717c478bd9Sstevel@tonic-gate printf("prog\t\tvers\tnetid\t success\tfailure\n"); 17727c478bd9Sstevel@tonic-gate for (al = infp->addrinfo; al; al = al->next) { 17737c478bd9Sstevel@tonic-gate rpc = getrpcbynumber(al->prog); 17747c478bd9Sstevel@tonic-gate if (rpc) 17757c478bd9Sstevel@tonic-gate printf("%-16s", rpc->r_name); 17767c478bd9Sstevel@tonic-gate else 17777c478bd9Sstevel@tonic-gate printf("%-16d", al->prog); 17787c478bd9Sstevel@tonic-gate printf("%d\t%-9s %-12d\t%d\n", 17797c478bd9Sstevel@tonic-gate al->vers, al->netid, 17807c478bd9Sstevel@tonic-gate al->success, al->failure); 17817c478bd9Sstevel@tonic-gate } 17827c478bd9Sstevel@tonic-gate } 17837c478bd9Sstevel@tonic-gate 17847c478bd9Sstevel@tonic-gate static char * 17857c478bd9Sstevel@tonic-gate spaces(howmany) 17867c478bd9Sstevel@tonic-gate int howmany; 17877c478bd9Sstevel@tonic-gate { 17887c478bd9Sstevel@tonic-gate static char space_array[] = /* 64 spaces */ 17897c478bd9Sstevel@tonic-gate " "; 17907c478bd9Sstevel@tonic-gate 17917c478bd9Sstevel@tonic-gate if (howmany <= 0 || howmany > sizeof (space_array)) { 17927c478bd9Sstevel@tonic-gate return (""); 17937c478bd9Sstevel@tonic-gate } 17947c478bd9Sstevel@tonic-gate return (&space_array[sizeof (space_array) - howmany - 1]); 17957c478bd9Sstevel@tonic-gate } 1796