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: #ifndef lint
  30: static char sccsid[] = "@(#)clnt_simple.c 1.1 84/12/20 Copyr 1984 Sun Micro";
  31: #endif
  32: 
  33: /*
  34:  * clnt_simple.c
  35:  * Simplified front end to rpc.
  36:  *
  37:  * Copyright (C) 1984, Sun Microsystems, Inc.
  38:  */
  39: 
  40: #include <stdio.h>
  41: #include <rpc/rpc.h>
  42: #include <sys/socket.h>
  43: #include <sys/time.h>
  44: #include <netdb.h>
  45: 
  46: callrpc(host, prognum, versnum, procnum, inproc, in, outproc, out)
  47:     char *host;
  48:     xdrproc_t inproc, outproc;
  49:     char *in, *out;
  50: {
  51:     struct sockaddr_in server_addr;
  52:     enum clnt_stat clnt_stat;
  53:     struct hostent *hp;
  54:     struct timeval timeout, tottimeout;
  55: 
  56:     static CLIENT *client;
  57:     static int socket = RPC_ANYSOCK;
  58:     static int oldprognum, oldversnum, valid;
  59:     static char oldhost[256];
  60: 
  61:     if (valid && oldprognum == prognum && oldversnum == versnum
  62:         && strcmp(oldhost, host) == 0) {
  63:         /* reuse old client */
  64:     }
  65:     else {
  66:         close(socket);
  67:         socket = RPC_ANYSOCK;
  68:         if (client) {
  69:             clnt_destroy(client);
  70:             client = NULL;
  71:         }
  72:         if ((hp = gethostbyname(host)) == NULL)
  73:             return ((int) RPC_UNKNOWNHOST);
  74:         timeout.tv_usec = 0;
  75:         timeout.tv_sec = 10;
  76:         bcopy(hp->h_addr, &server_addr.sin_addr, hp->h_length);
  77:         server_addr.sin_family = AF_INET;
  78:         server_addr.sin_port =  0;
  79:         if ((client = clntudp_create(&server_addr, prognum,
  80:             versnum, timeout, &socket)) == NULL)
  81:             return ((int) rpc_createerr.cf_stat);
  82:         valid = 1;
  83:         oldprognum = prognum;
  84:         oldversnum = versnum;
  85:         strcpy(oldhost, host);
  86:     }
  87:     tottimeout.tv_sec = 25;
  88:     tottimeout.tv_usec = 0;
  89:     clnt_stat = clnt_call(client, procnum, inproc, in,
  90:         outproc, out, tottimeout);
  91:     /*
  92: 	 * if call failed, empty cache
  93: 	 */
  94:     if (clnt_stat != RPC_SUCCESS)
  95:         valid = 0;
  96:     return ((int) clnt_stat);
  97: }

Defined functions

callrpc defined in line 46; used 1 times

Defined variables

sccsid defined in line 30; never used
Last modified: 1985-04-19
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 974
Valid CSS Valid XHTML 1.0 Strict