1: /*
   2:  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
   3:  * unrestricted use provided that this legend is included on all tape
   4:  * media and as a part of the software program in whole or part.  Users
   5:  * may copy or modify Sun RPC without charge, but are not authorized
   6:  * to license or distribute it to anyone else except as part of a product or
   7:  * program developed by the user.
   8:  *
   9:  * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
  10:  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
  11:  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
  12:  *
  13:  * Sun RPC is provided with no support and without any obligation on the
  14:  * part of Sun Microsystems, Inc. to assist in its use, correction,
  15:  * modification or enhancement.
  16:  *
  17:  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
  18:  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
  19:  * OR ANY PART THEREOF.
  20:  *
  21:  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
  22:  * or profits or other special, indirect and consequential damages, even if
  23:  * Sun has been advised of the possibility of such damages.
  24:  *
  25:  * Sun Microsystems, Inc.
  26:  * 2550 Garcia Avenue
  27:  * Mountain View, California  94043
  28:  */
  29: 
  30: /*
  31:  * Copyright (C) 1984, Sun Microsystems, Inc.
  32:  */
  33: 
  34: /*
  35:  * rpcinfo: ping a particular rpc program
  36:  *     or dump the portmapper
  37:  */
  38: 
  39: #include <rpc/rpc.h>
  40: #include <stdio.h>
  41: #include <sys/socket.h>
  42: #include <sys/time.h>
  43: #include <netdb.h>
  44: #include <rpc/pmap_prot.h>
  45: #include <rpc/pmap_clnt.h>
  46: 
  47: #define MAXHOSTLEN 256
  48: 
  49: main(argc, argv)
  50:     char **argv;
  51: {
  52:     int ans;
  53: 
  54:     if (argc < 2) {
  55:         usage();
  56:         exit(1);
  57:     }
  58:     if (argv[1][0] == '-') {
  59:         switch(argv[1][1]) {
  60:             case 't':
  61:                 tcpping(argc-1, argv+1);
  62:                 break;
  63:             case 'p':
  64:                 pmapdump(argc-1, argv+1);
  65:                 break;
  66:             case 'u':
  67:                 udpping(argc-1, argv+1);
  68:                 break;
  69:             default:
  70:                 usage();
  71:                 exit(1);
  72:                 break;
  73:         }
  74:     }
  75:     else
  76:         usage();
  77: }
  78: 
  79: udpping(argc, argv)
  80:     char **argv;
  81: {
  82:     int ans;
  83: 
  84:     if (argc != 4) {
  85:         usage();
  86:         exit(1);
  87:     }
  88:     ans = callrpc(argv[1], atoi(argv[2]), atoi(argv[3]), NULLPROC,
  89:         xdr_void, 0, xdr_void, 0);
  90:     if (ans != 0) {
  91:         clnt_perrno(ans);
  92:         fprintf(stderr, "\n");
  93:         printf("proc %d vers %d is not available\n", atoi(argv[2]),
  94:             atoi(argv[3]));
  95:     }
  96:     else
  97:         printf("proc %d vers %d ready and waiting\n", atoi(argv[2]),
  98:             atoi(argv[3]));
  99: }
 100: 
 101: tcpping(argc, argv)
 102:     int argc;
 103:     char **argv;
 104: {
 105:     struct timeval to;
 106:     struct sockaddr_in addr;
 107:     enum clnt_stat rpc_stat;
 108:     CLIENT *client;
 109:     int sock = -1;
 110:     struct hostent *hp;
 111: 
 112:     if (argc != 4) {
 113:         usage();
 114:         exit(1);
 115:     }
 116:     if ((hp = gethostbyname(argv[1])) == NULL) {
 117:         fprintf(stderr, "can't find %s\n", argv[1]);
 118:         exit(1);
 119:     }
 120:     addr.sin_family = AF_INET;
 121:     addr.sin_port = 0;
 122:     addr.sin_addr.s_addr = *(int *)hp->h_addr;
 123:     if ((client = clnttcp_create(&addr, atoi(argv[2]),
 124:         atoi(argv[3]), &sock, 0, 0)) == NULL) {
 125:             clnt_pcreateerror("");
 126:             printf("proc %d vers %d is not available\n",
 127:                 atoi(argv[2]), atoi(argv[3]));
 128:             exit(1);
 129:         }
 130:     to.tv_usec = 0;
 131:     to.tv_sec = 10;
 132:     rpc_stat = clnt_call(client, 0, xdr_void, NULL, xdr_void, NULL, to);
 133:     if (rpc_stat != RPC_SUCCESS) {
 134:         clnt_perrno(rpc_stat);
 135:         fprintf(stderr, "\n");
 136:         printf("proc %d vers %d is not available\n", atoi(argv[2]),
 137:             atoi(argv[3]));
 138:     }
 139:     else
 140:         printf("proc %d vers %d ready and waiting\n", atoi(argv[2]),
 141:             atoi(argv[3]));
 142: }
 143: 
 144: pmapdump(argc, argv)
 145:     int argc;
 146:     char **argv;
 147: {
 148:     struct sockaddr_in server_addr;
 149:     struct hostent *hp;
 150:     struct pmaplist *head;
 151:     char hoststr[MAXHOSTLEN];
 152:     int socket = -1;
 153:     struct timeval minutetimeout;
 154:     char *hostnm;
 155:     register CLIENT *client;
 156:     enum clnt_stat rpc_stat;
 157: 
 158:     if (argc > 2) {
 159:         usage();
 160:         exit(1);
 161:     }
 162:     if (argc == 2) {
 163:         hostnm = argv[1];
 164:     } else {
 165:         gethostname(hoststr, sizeof(hoststr));
 166:         hostnm = hoststr;
 167:     }
 168:     if ((hp = gethostbyname(hostnm)) == NULL) {
 169:         fprintf(stderr, "cannot get addr for '%s'\n", hostnm);
 170:         exit(0);
 171:     }
 172:     bcopy(hp->h_addr, (caddr_t)&server_addr.sin_addr, hp->h_length);
 173:     server_addr.sin_family = AF_INET;
 174:     minutetimeout.tv_sec = 60;
 175:     minutetimeout.tv_usec = 0;
 176:     server_addr.sin_port = htons(PMAPPORT);
 177:     if ((client = clnttcp_create(&server_addr, PMAPPROG,
 178:         PMAPVERS, &socket, 50, 500)) == NULL) {
 179:         clnt_pcreateerror("rpcinfo: can't contact portmapper");
 180:         exit(1);
 181:     }
 182:     if (clnt_call(client, PMAPPROC_DUMP, xdr_void, NULL,
 183:         xdr_pmaplist, &head, minutetimeout) != RPC_SUCCESS) {
 184:         fprintf(stderr, "rpcinfo: can't contact portmapper");
 185:         clnt_perrno(rpc_stat);
 186:         fprintf(stderr, "\n");
 187:         exit(1);
 188:     }
 189:     if (head == NULL) {
 190:         printf("No remote programs registered.\n");
 191:     } else {
 192:         printf("[program, version, protocol, port]:\n\n");
 193:         for (; head != (struct pmaplist *)NULL; head = head->pml_next) {
 194:             printf("[%ld, %ld, %ld, %ld]\n",
 195:                 head->pml_map.pm_prog,
 196:                 head->pml_map.pm_vers,
 197:                 head->pml_map.pm_prot,
 198:                 head->pml_map.pm_port);
 199:         }
 200:     }
 201: }
 202: 
 203: usage()
 204: {
 205:     fprintf(stderr, "Usage: rpcinfo -u host prognum versnum\n");
 206:     fprintf(stderr, "       rpcinfo -t host prognum versnum\n");
 207:     fprintf(stderr, "       rpcinfo -p [host]\n");
 208: }

Defined functions

main defined in line 49; never used
pmapdump defined in line 144; used 1 times
  • in line 64
tcpping defined in line 101; used 1 times
  • in line 61
udpping defined in line 79; used 1 times
  • in line 67
usage defined in line 203; used 6 times

Defined macros

MAXHOSTLEN defined in line 47; used 1 times
Last modified: 1985-04-19
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1279
Valid CSS Valid XHTML 1.0 Strict