xref: /csrg-svn/lib/librpc/rpc/pmap_clnt.c (revision 45083)
1*45083Smckusick /* @(#)pmap_clnt.c	2.2 88/08/01 4.0 RPCSRC */
2*45083Smckusick /*
3*45083Smckusick  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
4*45083Smckusick  * unrestricted use provided that this legend is included on all tape
5*45083Smckusick  * media and as a part of the software program in whole or part.  Users
6*45083Smckusick  * may copy or modify Sun RPC without charge, but are not authorized
7*45083Smckusick  * to license or distribute it to anyone else except as part of a product or
8*45083Smckusick  * program developed by the user.
9*45083Smckusick  *
10*45083Smckusick  * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
11*45083Smckusick  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
12*45083Smckusick  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
13*45083Smckusick  *
14*45083Smckusick  * Sun RPC is provided with no support and without any obligation on the
15*45083Smckusick  * part of Sun Microsystems, Inc. to assist in its use, correction,
16*45083Smckusick  * modification or enhancement.
17*45083Smckusick  *
18*45083Smckusick  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
19*45083Smckusick  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
20*45083Smckusick  * OR ANY PART THEREOF.
21*45083Smckusick  *
22*45083Smckusick  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
23*45083Smckusick  * or profits or other special, indirect and consequential damages, even if
24*45083Smckusick  * Sun has been advised of the possibility of such damages.
25*45083Smckusick  *
26*45083Smckusick  * Sun Microsystems, Inc.
27*45083Smckusick  * 2550 Garcia Avenue
28*45083Smckusick  * Mountain View, California  94043
29*45083Smckusick  */
30*45083Smckusick #if !defined(lint) && defined(SCCSIDS)
31*45083Smckusick static char sccsid[] = "@(#)pmap_clnt.c 1.37 87/08/11 Copyr 1984 Sun Micro";
32*45083Smckusick #endif
33*45083Smckusick 
34*45083Smckusick /*
35*45083Smckusick  * pmap_clnt.c
36*45083Smckusick  * Client interface to pmap rpc service.
37*45083Smckusick  *
38*45083Smckusick  * Copyright (C) 1984, Sun Microsystems, Inc.
39*45083Smckusick  */
40*45083Smckusick 
41*45083Smckusick #include <rpc/rpc.h>
42*45083Smckusick #include <rpc/pmap_prot.h>
43*45083Smckusick #include <rpc/pmap_clnt.h>
44*45083Smckusick 
45*45083Smckusick static struct timeval timeout = { 5, 0 };
46*45083Smckusick static struct timeval tottimeout = { 60, 0 };
47*45083Smckusick 
48*45083Smckusick void clnt_perror();
49*45083Smckusick 
50*45083Smckusick 
51*45083Smckusick /*
52*45083Smckusick  * Set a mapping between program,version and port.
53*45083Smckusick  * Calls the pmap service remotely to do the mapping.
54*45083Smckusick  */
55*45083Smckusick bool_t
pmap_set(program,version,protocol,port)56*45083Smckusick pmap_set(program, version, protocol, port)
57*45083Smckusick 	u_long program;
58*45083Smckusick 	u_long version;
59*45083Smckusick 	int protocol;
60*45083Smckusick 	u_short port;
61*45083Smckusick {
62*45083Smckusick 	struct sockaddr_in myaddress;
63*45083Smckusick 	int socket = -1;
64*45083Smckusick 	register CLIENT *client;
65*45083Smckusick 	struct pmap parms;
66*45083Smckusick 	bool_t rslt;
67*45083Smckusick 
68*45083Smckusick 	get_myaddress(&myaddress);
69*45083Smckusick 	client = clntudp_bufcreate(&myaddress, PMAPPROG, PMAPVERS,
70*45083Smckusick 	    timeout, &socket, RPCSMALLMSGSIZE, RPCSMALLMSGSIZE);
71*45083Smckusick 	if (client == (CLIENT *)NULL)
72*45083Smckusick 		return (FALSE);
73*45083Smckusick 	parms.pm_prog = program;
74*45083Smckusick 	parms.pm_vers = version;
75*45083Smckusick 	parms.pm_prot = protocol;
76*45083Smckusick 	parms.pm_port = port;
77*45083Smckusick 	if (CLNT_CALL(client, PMAPPROC_SET, xdr_pmap, &parms, xdr_bool, &rslt,
78*45083Smckusick 	    tottimeout) != RPC_SUCCESS) {
79*45083Smckusick 		clnt_perror(client, "Cannot register service");
80*45083Smckusick 		return (FALSE);
81*45083Smckusick 	}
82*45083Smckusick 	CLNT_DESTROY(client);
83*45083Smckusick 	(void)close(socket);
84*45083Smckusick 	return (rslt);
85*45083Smckusick }
86*45083Smckusick 
87*45083Smckusick /*
88*45083Smckusick  * Remove the mapping between program,version and port.
89*45083Smckusick  * Calls the pmap service remotely to do the un-mapping.
90*45083Smckusick  */
91*45083Smckusick bool_t
pmap_unset(program,version)92*45083Smckusick pmap_unset(program, version)
93*45083Smckusick 	u_long program;
94*45083Smckusick 	u_long version;
95*45083Smckusick {
96*45083Smckusick 	struct sockaddr_in myaddress;
97*45083Smckusick 	int socket = -1;
98*45083Smckusick 	register CLIENT *client;
99*45083Smckusick 	struct pmap parms;
100*45083Smckusick 	bool_t rslt;
101*45083Smckusick 
102*45083Smckusick 	get_myaddress(&myaddress);
103*45083Smckusick 	client = clntudp_bufcreate(&myaddress, PMAPPROG, PMAPVERS,
104*45083Smckusick 	    timeout, &socket, RPCSMALLMSGSIZE, RPCSMALLMSGSIZE);
105*45083Smckusick 	if (client == (CLIENT *)NULL)
106*45083Smckusick 		return (FALSE);
107*45083Smckusick 	parms.pm_prog = program;
108*45083Smckusick 	parms.pm_vers = version;
109*45083Smckusick 	parms.pm_port = parms.pm_prot = 0;
110*45083Smckusick 	CLNT_CALL(client, PMAPPROC_UNSET, xdr_pmap, &parms, xdr_bool, &rslt,
111*45083Smckusick 	    tottimeout);
112*45083Smckusick 	CLNT_DESTROY(client);
113*45083Smckusick 	(void)close(socket);
114*45083Smckusick 	return (rslt);
115*45083Smckusick }
116