rpcinfo.c revision 20d0ade92f2ccd1095364cf9ca5807ad3dee6081
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2015 Nexenta Systems, Inc. All rights reserved.
*/
/*
* Copyright 2010 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/*
* University Copyright- Copyright (c) 1982, 1986, 1988
* The Regents of the University of California
* All Rights Reserved
*
* University Acknowledgment- Portions of this document are derived from
* software developed by the University of California, Berkeley, and its
* contributors.
*/
/*
* rpcinfo: ping a particular rpc program
* or dump the the registered programs on the remote machine.
*/
/*
* We are for now defining PORTMAP here. It doesn't even compile
* unless it is defined.
*/
#ifndef PORTMAP
#define PORTMAP
#endif
/*
* If PORTMAP is defined, rpcinfo will talk to both portmapper and
* rpcbind programs; else it talks only to rpcbind. In the latter case
* all the portmapper specific options such as -u, -t, -p become void.
*/
#include <stdio.h>
#include <rpc/rpcb_prot.h>
#include <netdir.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#ifdef PORTMAP /* Support for version 2 portmapper */
#include <netdb.h>
#include <rpc/pmap_prot.h>
#include <rpc/pmap_clnt.h>
#endif
#define MAXHOSTLEN 256
#define MAX_VERS (4294967295UL)
#define UNKNOWN "unknown"
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
extern int t_errno;
extern long strtol();
static char *spaces();
#ifdef PORTMAP
static void ip_ping(/*ushort_t portflag, char *trans,
int argc, char **argv*/);
long vers, int *fd, char *trans*/);
static void pmapdump(/*int argc, char **argv*/);
static void get_inet_address(/*struct sockaddr_in *addr, char *host*/);
#endif
struct netconfig *nconf*/);
static void brdcst(/*int argc, char **argv*/);
static void addrping(/*char *address, char *netid,
int argc, char **argv*/);
static void progping(/* char *netid, int argc, char **argv*/);
long prog, long vers*/);
static int pstatus(/*CLIENT *client, ulong_t prognum, ulong_t vers*/);
static void rpcbdump(/*char *netid, int argc, char **argv*/);
static void rpcbgetstat(/* int argc, char **argv*/);
static void rpcbaddrlist(/*char *netid, int argc, char **argv*/);
static void deletereg(/*char *netid, int argc, char **argv */);
static void print_rmtcallstat(/* rtype, infp */);
static void print_getaddrstat(/* rtype, infp */);
static void usage(/*void*/);
/*
* Functions to be performed.
*/
#define NONE 0 /* no function */
struct netidlist {
char *netid;
};
struct verslist {
int vers;
};
struct rpcbdump_short {
struct rpcbdump_short *next;
char *owner;
};
char *loopback_netid = NULL;
struct netconfig *loopback_nconf;
int
int argc;
char **argv;
{
register int c;
extern char *optarg;
extern int optind;
int errflg;
int function;
void *handle;
#ifdef PORTMAP
char *strptr;
#endif
errflg = 0;
#ifdef PORTMAP
#else
#endif
switch (c) {
#ifdef PORTMAP
case 'p':
errflg = 1;
else
break;
case 't':
errflg = 1;
else
break;
case 'u':
errflg = 1;
else
break;
case 'n':
"rpcinfo: %s is illegal port number\n",
optarg);
exit(1);
}
break;
#endif
case 'a':
errflg = 1;
else
break;
case 'b':
errflg = 1;
else
break;
case 'd':
errflg = 1;
else
break;
case 'l':
errflg = 1;
else
break;
case 'm':
errflg = 1;
else
break;
case 's':
errflg = 1;
else
break;
case 'T':
break;
case '?':
errflg = 1;
break;
}
}
usage();
return (1);
}
/*
* See if a COTS loopback transport is available, in case we
* will be talking to the local system.
*/
handle = setnetconfig();
NC_LOOPBACK) == 0 &&
break;
}
}
if (loopback_netid == NULL) {
(void) endnetconfig(handle);
}
}
else
}
switch (function) {
#ifdef PORTMAP
case PMAPDUMP:
if (portnum != 0) {
usage();
return (1);
}
break;
case UDPPING:
break;
case TCPPING:
break;
#endif
case BROADCAST:
break;
case DELETES:
break;
case ADDRPING:
break;
case PROGPING:
break;
case RPCBDUMP:
case RPCBDUMP_SHORT:
break;
case RPCBGETSTAT:
break;
case RPCBADDRLIST:
break;
}
return (0);
}
#ifdef PORTMAP
static CLIENT *
struct sockaddr_in *addr;
int *fdp;
char *trans;
{
} else {
}
clnt_pcreateerror("rpcinfo");
else
(void) printf(
"program %lu version %lu is not available\n",
exit(1);
}
return (clnt);
}
/*
* If portnum is 0, then go and get the address from portmapper, which happens
* transparently through clnt*_create(); If version number is not given, it
* tries to find out the version number by making a call to version 0 and if
* that fails, it obtains the high order and the low order version number. If
* version 0 calls succeeds, it tries for MAXVERS call and repeats the same.
*/
static void
char *trans;
int argc;
char **argv;
{
struct sockaddr_in addr;
int failure = 0;
usage();
exit(1);
}
/*
* mismatch, and give us the range of versions supported.
*/
} else {
}
to);
if (argc != 2) {
/* Version number was known */
exit(1);
(void) CLNT_DESTROY(client);
return;
}
/* Version number not known */
if (rpc_stat == RPC_PROGVERSMISMATCH) {
} else if (rpc_stat == RPC_SUCCESS) {
/*
* Oh dear, it DOES support version 0.
* Let's try version MAX_VERS.
*/
(void) CLNT_DESTROY(client);
if (rpc_stat == RPC_PROGVERSMISMATCH) {
} else if (rpc_stat == RPC_SUCCESS) {
/*
* It also supports version MAX_VERS.
* Looks like we have a wise guy.
* OK, we give them information on all
* 4 billion versions they support...
*/
minvers = 0;
} else {
exit(1);
}
} else {
exit(1);
}
(void) CLNT_DESTROY(client);
failure = 1;
(void) CLNT_DESTROY(client);
}
if (failure)
exit(1);
}
/*
* Dump all the portmapper registerations
*/
static void
int argc;
char **argv;
{
struct sockaddr_in server_addr;
int socket = RPC_ANYSOCK;
struct timeval minutetimeout;
char *host;
if (argc > 1) {
usage();
exit(1);
}
if (argc == 1) {
} else {
}
minutetimeout.tv_usec = 0;
/*
* "Misc. TLI error" is not too helpful. Most likely
* the connection to the remote server timed out, so
* this error is at least less perplexing.
*/
}
clnt_pcreateerror("rpcinfo: can't contact portmapper");
exit(1);
}
if (clnt_st != RPC_SUCCESS) {
if ((clnt_st == RPC_PROGVERSMISMATCH) ||
(clnt_st == RPC_PROGUNAVAIL)) {
"%s does not support portmapper. Try rpcinfo %s instead\n",
exit(1);
}
exit(1);
}
(void) printf("No remote programs registered.\n");
} else {
(void) printf(" program vers proto port service\n");
(void) printf("%10ld%5ld",
else
if (rpc)
else
(void) printf("\n");
}
}
}
static void
struct sockaddr_in *addr;
char *host;
{
struct nd_hostserv service;
struct nd_addrlist *naddrs;
"rpcinfo: couldn't find a suitable transport\n");
exit(1);
} else {
host, netdir_sperror());
exit(1);
} else {
}
(void) freenetconfigent(nconf);
}
} else {
}
}
#endif /* PORTMAP */
/*
* reply_proc collects replies from the broadcast.
* to get a unique list of responses the output of rpcinfo should
* be piped through sort(1) and then uniq(1).
*/
/*ARGSUSED*/
static bool_t
void *res; /* Nothing comes back */
{
struct nd_hostservlist *serv;
char *uaddr;
char *hostname;
} else {
}
}
return (FALSE);
}
static void
int argc;
char **argv;
{
if (argc != 2) {
usage();
exit(1);
}
exit(1);
}
exit(0);
}
static bool_t
struct rpcbdump_short *rs;
{
break;
if (vl)
return (TRUE);
return (FALSE);
return (TRUE);
}
static bool_t
struct rpcbdump_short *rs;
char *netid;
{
break;
if (nl)
return (TRUE);
return (FALSE);
return (TRUE);
}
static void
int dumptype;
char *netid;
int argc;
char **argv;
{
struct timeval minutetimeout;
char *host;
if (argc > 1) {
usage();
exit(1);
}
if (argc == 1) {
} else {
}
if (loopback_netid == NULL) {
} else {
}
}
} else {
nc_perror("rpcinfo: invalid transport");
exit(1);
}
if (nconf)
(void) freenetconfigent(nconf);
}
clnt_pcreateerror("rpcinfo: can't contact rpcbind");
exit(1);
}
minutetimeout.tv_usec = 0;
if (clnt_st != RPC_SUCCESS) {
if ((clnt_st == RPC_PROGVERSMISMATCH) ||
(clnt_st == RPC_PROGUNAVAIL)) {
int vers;
if (clnt_st != RPC_SUCCESS)
goto failed;
} else {
(char *)&pmaphead, minutetimeout);
if (clnt_st != RPC_SUCCESS)
goto failed;
/*
* convert to rpcblist_ptr format
*/
goto error;
else
else {
#define MAXLONG_AS_STRING "2147483648"
goto error;
}
}
}
}
} else { /* any other error */
exit(1);
}
}
(void) printf("No remote programs registered.\n");
(void) printf(
" program version netid address service owner\n");
(void) printf("%10ld%5ld ",
if (rpc)
else
}
} else if (dumptype == RPCBDUMP_SHORT) {
break;
rs = (struct rpcbdump_short *)
malloc(sizeof (struct rpcbdump_short));
goto error;
} else {
}
}
goto error;
goto error;
}
(void) printf(
" program version(s) netid(s) service owner\n");
int bytes_trans = 0;
int len;
< 0 ? 0 : len;
? 0 : len;
}
/*
* If number of bytes transferred is less than 10,
* align 10 bytes for version(s) column. If bytes
* transferred is more than 10, add a trailing white
* space.
*/
if (bytes_trans < 10)
else
(void) printf(" ");
bytes_trans = 0;
< 0 ? 0 : len;
? 0 : len;
}
/*
* Align netid(s) column output for 32 bytes.
*/
if (bytes_trans < 32)
if (rpc)
else
}
}
return;
}
static char nullstring[] = "\000";
static void
char *netid;
int argc;
char **argv;
{
struct timeval minutetimeout;
char *host;
if (argc != 3) {
usage();
exit(1);
}
if (loopback_netid == NULL) {
} else {
&targaddr);
}
}
} else {
nc_perror("rpcinfo: invalid transport");
exit(1);
}
if (nconf)
(void) freenetconfigent(nconf);
}
clnt_pcreateerror("rpcinfo: can't contact rpcbind");
exit(1);
}
minutetimeout.tv_usec = 0;
} else {
/*
* We also send the remote system the address we
* used to contact it in case it can help it
* connect back with us
*/
} else {
}
}
exit(1);
}
(void) printf("No remote programs registered.\n");
} else {
(void) printf(
rpcb_entry *re;
char buf[128];
(void) printf("%10ld%3ld ",
"cots_ord");
if (rpc)
else
(void) printf("\n");
}
}
}
/*
* monitor rpcbind
*/
static void
int argc;
char **argv;
{
struct timeval minutetimeout;
char *host;
int i, j;
#define MAXFIELD 64
#define MAXLINE 256
char *pmaphdr[] = {
"NULL", "SET", "UNSET", "GETPORT",
"DUMP", "CALLIT"
};
char *rpcb3hdr[] = {
"NULL", "SET", "UNSET", "GETADDR", "DUMP", "CALLIT", "TIME",
"U2T", "T2U"
};
char *rpcb4hdr[] = {
"NULL", "SET", "UNSET", "GETADDR", "DUMP", "CALLIT", "TIME",
"U2T", "T2U", "VERADDR", "INDRECT", "GETLIST", "GETSTAT"
};
#define TABSTOP 8
if (argc >= 1) {
} else {
}
if (loopback_netid != NULL) {
}
} else {
}
clnt_pcreateerror("rpcinfo: can't contact rpcbind");
exit(1);
}
minutetimeout.tv_usec = 0;
!= RPC_SUCCESS) {
exit(1);
}
(void) printf("PORTMAP (version 2) statistics\n");
for (i = 0; i <= rpcb_highproc_2; i++) {
fieldbuf[0] = '\0';
switch (i) {
case PMAPPROC_SET:
break;
case PMAPPROC_UNSET:
break;
case PMAPPROC_GETPORT:
cnt = 0;
break;
case PMAPPROC_CALLIT:
cnt = 0;
break;
default: break; /* For the remaining ones */
}
- flen)));
}
(void) printf("PMAP_RMTCALL call statistics\n");
(void) printf("\n");
}
(void) printf("PMAP_GETPORT call statistics\n");
(void) printf("\n");
}
(void) printf("RPCBIND (version 3) statistics\n");
for (i = 0; i <= rpcb_highproc_3; i++) {
fieldbuf[0] = '\0';
switch (i) {
case RPCBPROC_SET:
break;
case RPCBPROC_UNSET:
break;
case RPCBPROC_GETADDR:
cnt = 0;
break;
case RPCBPROC_CALLIT:
cnt = 0;
break;
default: break; /* For the remaining ones */
}
- flen)));
}
(void) printf("RPCB_RMTCALL (version 3) call statistics\n");
(void) printf("\n");
}
(void) printf("RPCB_GETADDR (version 3) call statistics\n");
(void) printf("\n");
}
(void) printf("RPCBIND (version 4) statistics\n");
for (j = 0; j <= 9; j += 9) { /* Just two iterations for printing */
fieldbuf[0] = '\0';
switch (i) {
case RPCBPROC_SET:
break;
case RPCBPROC_UNSET:
break;
case RPCBPROC_GETADDR:
cnt = 0;
break;
case RPCBPROC_CALLIT:
cnt = 0;
break;
default: break; /* For the remaining ones */
}
/*
* XXX: We also add RPCBPROC_GETADDRLIST queries to
* RPCB_GETADDR because rpcbind includes the
* RPCB_GETADDRLIST successes in RPCB_GETADDR.
*/
if (i != RPCBPROC_GETADDR)
else
}
}
(void) printf("\n");
(void) printf("RPCB_RMTCALL (version 4) call statistics\n");
}
(void) printf("\n");
(void) printf("RPCB_GETADDR (version 4) call statistics\n");
}
}
/*
* Delete registeration for this (prog, vers, netid)
*/
static void
char *netid;
int argc;
char **argv;
{
if (argc != 2) {
usage();
exit(1);
}
if (netid) {
"rpcinfo: netid %s not supported\n", netid);
exit(1);
}
}
"rpcinfo: Could not delete registration for prog %s version %s\n",
exit(1);
}
}
/*
* Create and return a handle for the given nconf.
* Exit if cannot create handle.
*/
static CLIENT *
char *address;
{
clnt_pcreateerror("rpcinfo");
exit(1);
}
/* Convert the uaddr to taddr */
netdir_perror("rpcinfo");
exit(1);
}
}
clnt_pcreateerror("rpcinfo");
exit(1);
}
return (client);
}
/*
* If the version number is given, ping that (prog, vers); else try to find
* the version numbers supported for that prog and ping all the versions.
* Remote rpcbind is not contacted for this service. The requests are
* sent directly to the services themselves.
*/
static void
char *address;
char *netid;
int argc;
char **argv;
{
int failure = 0;
int fd;
usage();
exit(1);
}
exit(1);
}
/*
* mismatch, and give us the range of versions supported.
*/
} else {
}
if (argc == 2) {
/* Version number was known */
failure = 1;
(void) CLNT_DESTROY(client);
if (failure)
exit(1);
return;
}
/* Version number not known */
if (rpc_stat == RPC_PROGVERSMISMATCH) {
} else if (rpc_stat == RPC_SUCCESS) {
/*
* Oh dear, it DOES support version 0.
* Let's try version MAX_VERS.
*/
(void) CLNT_DESTROY(client);
if (rpc_stat == RPC_PROGVERSMISMATCH) {
} else if (rpc_stat == RPC_SUCCESS) {
/*
* It also supports version MAX_VERS.
* Looks like we have a wise guy.
* OK, we give them information on all
* 4 billion versions they support...
*/
minvers = 0;
} else {
exit(1);
}
} else {
exit(1);
}
(void) CLNT_DESTROY(client);
failure = 1;
(void) CLNT_DESTROY(client);
}
if (failure)
exit(1);
}
/*
* If the version number is given, ping that (prog, vers); else try to find
* the version numbers supported for that prog and ping all the versions.
* Remote rpcbind is *contacted* for this service. The requests are
* then sent directly to the services themselves.
*/
static void
char *netid;
int argc;
char **argv;
{
int failure = 0;
usage();
exit(1);
}
/*
* mismatch, and give us the range of versions supported.
*/
} else {
}
if (netid) {
"rpcinfo: Could not find %s\n", netid);
exit(1);
}
} else {
}
clnt_pcreateerror("rpcinfo");
exit(1);
}
if (argc == 3) {
/* Version number was known */
failure = 1;
(void) CLNT_DESTROY(client);
if (failure)
exit(1);
return;
}
/* Version number not known */
if (rpc_stat == RPC_PROGVERSMISMATCH) {
} else if (rpc_stat == RPC_SUCCESS) {
/*
* Oh dear, it DOES support version 0.
* Let's try version MAX_VERS.
*/
if (rpc_stat == RPC_PROGVERSMISMATCH) {
} else if (rpc_stat == RPC_SUCCESS) {
/*
* It also supports version MAX_VERS.
* Looks like we have a wise guy.
* OK, we give them information on all
* 4 billion versions they support...
*/
minvers = 0;
} else {
exit(1);
}
} else {
exit(1);
}
failure = 1;
}
(void) CLNT_DESTROY(client);
if (failure)
exit(1);
}
static void
usage()
{
#ifdef PORTMAP
#endif
" rpcinfo -T netid host prognum [versnum]\n");
#ifdef PORTMAP
" rpcinfo [-n portnum] -u | -t host prognum [versnum]\n");
#endif
" rpcinfo -a serv_address -T netid prognum [version]\n");
" rpcinfo -d [-T netid] prognum versnum\n");
}
static ulong_t
char *arg;
{
char *strptr;
"rpcinfo: %s is unknown service\n", arg);
exit(1);
}
} else {
"rpcinfo: %s is illegal program number\n", arg);
exit(1);
}
}
return (prognum);
}
static ulong_t
char *arg;
{
char *strptr;
"rpcinfo: %s is illegal version number\n", arg);
exit(1);
}
return (vers);
}
/*
* This routine should take a pointer to an "rpc_err" structure, rather than
* a pointer to a CLIENT structure, but "clnt_perror" takes a pointer to
* a CLIENT structure rather than a pointer to an "rpc_err" structure.
* As such, we have to keep the CLIENT structure around in order to print
* a good error message.
*/
static int
{
(void) printf("program %lu version %lu is not available\n",
return (-1);
} else {
(void) printf("program %lu version %lu ready and waiting\n",
return (0);
}
}
static CLIENT *
char *host;
{
static char *tlist[3] = {
"circuit_n", "circuit_v", "datagram_v"
};
int i;
void *handle;
for (i = 0; i < 3; i++) {
continue;
break;
}
targaddr);
}
if (clnt)
break;
}
return (clnt);
}
static CLIENT*
char *host;
{
struct nd_addrlist *nas;
struct nd_hostserv rpcbind_hs;
/* Get the address of the rpcbind */
return (NULL);
}
rpcbversnum, 0, 0);
if (client) {
*targaddr =
}
}
}
} else {
/*
* Assume that the other system is dead; this is a
* better error to display to the user.
*/
}
}
return (client);
}
static void
int rtype;
{
register rpcbs_rmtcalllist_ptr pr;
if (rtype == RPCBVERS_4_STAT)
(void) printf(
"prog\t\tvers\tproc\tnetid\tindirect success failure\n");
else
(void) printf("prog\t\tvers\tproc\tnetid\tsuccess\tfailure\n");
if (rpc)
else
(void) printf("%u\t%u\t%-7s ",
#else
(void) printf("%lu\t%lu\t%-7s ",
#endif
if (rtype == RPCBVERS_4_STAT)
}
}
static void
/* LINTED E_FUNC_ARG_UNUSED for 1st arg rtype */
int rtype;
{
(void) printf("prog\t\tvers\tnetid\t success\tfailure\n");
if (rpc)
else
(void) printf("%u\t%-9s %-12d\t%d\n",
#else
(void) printf("%lu\t%-9s %-12d\t%d\n",
#endif
}
}
static char *
int howmany;
{
static char space_array[] = /* 64 spaces */
" ";
return ("");
}
}