Import TBBT (NFS trace replay).
[bluesky.git] / TBBT / trace_play / rpc / pmap_clnt.c
1 #ifndef lint
2 static char sfs_pmap_clnt_id[] = "@(#)pmap_clnt.c     2.1     97/10/23";
3 #endif
4 /* @(#)pmap_clnt.c      2.2 88/08/01 4.0 RPCSRC */
5 /*
6  *   Copyright (c) 1992-1997,2001 by Standard Performance Evaluation Corporation
7  *      All rights reserved.
8  *              Standard Performance Evaluation Corporation (SPEC)
9  *              6585 Merchant Place, Suite 100
10  *              Warrenton, VA 20187
11  *
12  *      This product contains benchmarks acquired from several sources who
13  *      understand and agree with SPEC's goal of creating fair and objective
14  *      benchmarks to measure computer performance.
15  *
16  *      This copyright notice is placed here only to protect SPEC in the
17  *      event the source is misused in any manner that is contrary to the
18  *      spirit, the goals and the intent of SPEC.
19  *
20  *      The source code is provided to the user or company under the license
21  *      agreement for the SPEC Benchmark Suite for this product.
22  */
23 /*
24  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
25  * unrestricted use provided that this legend is included on all tape
26  * media and as a part of the software program in whole or part.  Users
27  * may copy or modify Sun RPC without charge, but are not authorized
28  * to license or distribute it to anyone else except as part of a product or
29  * program developed by the user.
30  * 
31  * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
32  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
33  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
34  * 
35  * Sun RPC is provided with no support and without any obligation on the
36  * part of Sun Microsystems, Inc. to assist in its use, correction,
37  * modification or enhancement.
38  * 
39  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
40  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
41  * OR ANY PART THEREOF.
42  * 
43  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
44  * or profits or other special, indirect and consequential damages, even if
45  * Sun has been advised of the possibility of such damages.
46  * 
47  * Sun Microsystems, Inc.
48  * 2550 Garcia Avenue
49  * Mountain View, California  94043
50  */
51 #if !defined(lint) && defined(SCCSIDS)
52 static char sccsid[] = "@(#)pmap_clnt.c 1.37 87/08/11 Copyr 1984 Sun Micro";
53 #endif
54
55 /*
56  * pmap_clnt.c
57  * Client interface to pmap rpc service.
58  *
59  * Copyright (C) 1984, Sun Microsystems, Inc.
60  */
61
62 #include <stdio.h>
63 #include <stdlib.h>
64 #include <unistd.h>
65 #include "rpc/rpc.h"
66 #include "rpc/pmap_prot.h"
67 #include "rpc/pmap_clnt.h"
68
69 static struct timeval timeout = { 5, 0 };
70 static struct timeval tottimeout = { 60, 0 };
71
72 extern void get_myaddress(struct sockaddr_in *addr);
73
74 /*
75  * Set a mapping between program,version and port.
76  * Calls the pmap service remotely to do the mapping.
77  */
78 bool_t
79 pmap_set(
80         uint32_t program,
81         uint32_t version,
82         int protocol,
83         uint16_t port)
84 {
85         struct sockaddr_in myaddress;
86         int socket = -1;
87         register CLIENT *client;
88         struct pmap parms;
89         bool_t rslt;
90
91         get_myaddress(&myaddress);
92         client = clntudp_bufcreate(&myaddress, PMAPPROG, PMAPVERS,
93             timeout, &socket, RPCSMALLMSGSIZE, RPCSMALLMSGSIZE);
94         if (client == (CLIENT *)NULL)
95                 return (FALSE);
96         parms.pm_prog = program;
97         parms.pm_vers = version;
98         parms.pm_prot = protocol;
99         parms.pm_port = port;
100         if (CLNT_CALL(client, PMAPPROC_SET, xdr_pmap, &parms, xdr_bool, &rslt,
101             tottimeout) != RPC_SUCCESS) {
102                 clnt_perror(client, "Cannot register service");
103                 return (FALSE);
104         }
105         CLNT_DESTROY(client);
106         (void)close(socket);
107         return (rslt);
108 }
109
110 /*
111  * Remove the mapping between program,version and port.
112  * Calls the pmap service remotely to do the un-mapping.
113  */
114 bool_t
115 pmap_unset(
116         uint32_t program,
117         uint32_t version)
118 {
119         struct sockaddr_in myaddress;
120         int socket = -1;
121         register CLIENT *client;
122         struct pmap parms;
123         bool_t rslt;
124
125         get_myaddress(&myaddress);
126         client = clntudp_bufcreate(&myaddress, PMAPPROG, PMAPVERS,
127             timeout, &socket, RPCSMALLMSGSIZE, RPCSMALLMSGSIZE);
128         if (client == (CLIENT *)NULL)
129                 return (FALSE);
130         parms.pm_prog = program;
131         parms.pm_vers = version;
132         parms.pm_port = parms.pm_prot = 0;
133         CLNT_CALL(client, PMAPPROC_UNSET, xdr_pmap, &parms, xdr_bool, &rslt,
134             tottimeout);
135         CLNT_DESTROY(client);
136         (void)close(socket);
137         return (rslt);
138 }