Import TBBT (NFS trace replay).
[bluesky.git] / TBBT / trace_play / rpc / clnt_generic.c
1 #ifndef lint
2 static char sfs_clnt_generic_id[] = "@(#)clnt_generic.c     2.1     97/10/23";
3 #endif
4
5 /* @(#)clnt_generic.c   2.2 88/08/01 4.0 RPCSRC */
6 /*
7  *   Copyright (c) 1992-1997,2001 by Standard Performance Evaluation Corporation
8  *      All rights reserved.
9  *              Standard Performance Evaluation Corporation (SPEC)
10  *              6585 Merchant Place, Suite 100
11  *              Warrenton, VA 20187
12  *
13  *      This product contains benchmarks acquired from several sources who
14  *      understand and agree with SPEC's goal of creating fair and objective
15  *      benchmarks to measure computer performance.
16  *
17  *      This copyright notice is placed here only to protect SPEC in the
18  *      event the source is misused in any manner that is contrary to the
19  *      spirit, the goals and the intent of SPEC.
20  *
21  *      The source code is provided to the user or company under the license
22  *      agreement for the SPEC Benchmark Suite for this product.
23  */
24 /*
25  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
26  * unrestricted use provided that this legend is included on all tape
27  * media and as a part of the software program in whole or part.  Users
28  * may copy or modify Sun RPC without charge, but are not authorized
29  * to license or distribute it to anyone else except as part of a product or
30  * program developed by the user.
31  * 
32  * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
33  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
34  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
35  * 
36  * Sun RPC is provided with no support and without any obligation on the
37  * part of Sun Microsystems, Inc. to assist in its use, correction,
38  * modification or enhancement.
39  *
40  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
41  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
42  * OR ANY PART THEREOF.
43  * 
44  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
45  * or profits or other special, indirect and consequential damages, even if
46  * Sun has been advised of the possibility of such damages.
47  * 
48  * Sun Microsystems, Inc.
49  * 2550 Garcia Avenue
50  * Mountain View, California  94043
51  */
52 #if !defined(lint) && defined(SCCSIDS)
53 static char sccsid[] = "@(#)clnt_generic.c 1.4 87/08/11 (C) 1987 SMI";
54 #endif
55 /*
56  * Copyright (C) 1987, Sun Microsystems, Inc.
57  */
58
59 #include <string.h>
60 #include "rpc/rpc.h"
61 #include "rpc/osdep.h"
62 #include <errno.h>
63 #include <netdb.h>
64
65 /*
66  * Generic client creation: takes (hostname, program-number, protocol) and
67  * returns client handle. Default options are set, which the user can 
68  * change using the rpc equivalent of ioctl()'s.
69  */
70 CLIENT *
71 clnt_create(char *hostname,
72         uint32_t prog,
73         uint32_t vers,
74         char *proto)
75 {
76         struct hostent *h;
77         struct protoent *p;
78         struct sockaddr_in sin;
79         int sock;
80         struct timeval tv;
81         CLIENT *client;
82
83         h = gethostbyname(hostname);
84         if (h == NULL) {
85                 rpc_createerr.cf_stat = RPC_UNKNOWNHOST;
86                 return (NULL);
87         }
88         if (h->h_addrtype != AF_INET) {
89                 /*
90                  * Only support INET for now
91                  */
92                 rpc_createerr.cf_stat = RPC_SYSTEMERROR;
93                 rpc_createerr.cf_error.re_errno = EAFNOSUPPORT; 
94                 return (NULL);
95         }
96         sin.sin_family = h->h_addrtype;
97         sin.sin_port = 0;
98         memset(sin.sin_zero, '\0', sizeof(sin.sin_zero));
99         memmove((char*)&sin.sin_addr, h->h_addr, h->h_length);
100         p = getprotobyname(proto);
101         if (p == NULL) {
102                 rpc_createerr.cf_stat = RPC_UNKNOWNPROTO;
103                 rpc_createerr.cf_error.re_errno = EPFNOSUPPORT; 
104                 return (NULL);
105         }
106         sock = RPC_ANYSOCK;
107         switch (p->p_proto) {
108         case IPPROTO_UDP:
109                 tv.tv_sec = 5;
110                 tv.tv_usec = 0;
111                 client = sfs_cudp_create(&sin, prog, vers, tv, &sock);
112                 if (client == NULL) {
113                         return (NULL);
114                 }
115                 tv.tv_sec = 25;
116                 clnt_control(client, CLSET_TIMEOUT, &tv);
117                 break;
118         case IPPROTO_TCP:
119                 client = sfs_ctcp_create(&sin, prog, vers, &sock, 0, 0);
120                 if (client == NULL) {
121                         return (NULL);
122                 }
123                 tv.tv_sec = 25;
124                 tv.tv_usec = 0;
125                 clnt_control(client, CLSET_TIMEOUT, &tv);
126                 break;
127         default:
128                 rpc_createerr.cf_stat = RPC_SYSTEMERROR;
129                 rpc_createerr.cf_error.re_errno = EPFNOSUPPORT; 
130                 return (NULL);
131         }
132         return (client);
133 }