pmap_rmt.c revision 1.29 1 1.29 christos /* $NetBSD: pmap_rmt.c,v 1.29 2000/07/06 03:10:34 christos Exp $ */
2 1.4 cgd
3 1.1 cgd /*
4 1.1 cgd * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
5 1.1 cgd * unrestricted use provided that this legend is included on all tape
6 1.1 cgd * media and as a part of the software program in whole or part. Users
7 1.1 cgd * may copy or modify Sun RPC without charge, but are not authorized
8 1.1 cgd * to license or distribute it to anyone else except as part of a product or
9 1.1 cgd * program developed by the user.
10 1.1 cgd *
11 1.1 cgd * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
12 1.1 cgd * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
13 1.1 cgd * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
14 1.1 cgd *
15 1.1 cgd * Sun RPC is provided with no support and without any obligation on the
16 1.1 cgd * part of Sun Microsystems, Inc. to assist in its use, correction,
17 1.1 cgd * modification or enhancement.
18 1.1 cgd *
19 1.1 cgd * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
20 1.1 cgd * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
21 1.1 cgd * OR ANY PART THEREOF.
22 1.1 cgd *
23 1.1 cgd * In no event will Sun Microsystems, Inc. be liable for any lost revenue
24 1.1 cgd * or profits or other special, indirect and consequential damages, even if
25 1.1 cgd * Sun has been advised of the possibility of such damages.
26 1.1 cgd *
27 1.1 cgd * Sun Microsystems, Inc.
28 1.1 cgd * 2550 Garcia Avenue
29 1.1 cgd * Mountain View, California 94043
30 1.1 cgd */
31 1.1 cgd
32 1.9 christos #include <sys/cdefs.h>
33 1.1 cgd #if defined(LIBC_SCCS) && !defined(lint)
34 1.9 christos #if 0
35 1.9 christos static char *sccsid = "@(#)pmap_rmt.c 1.21 87/08/27 Copyr 1984 Sun Micro";
36 1.9 christos static char *sccsid = "@(#)pmap_rmt.c 2.2 88/08/01 4.0 RPCSRC";
37 1.9 christos #else
38 1.29 christos __RCSID("$NetBSD: pmap_rmt.c,v 1.29 2000/07/06 03:10:34 christos Exp $");
39 1.9 christos #endif
40 1.1 cgd #endif
41 1.1 cgd
42 1.1 cgd /*
43 1.1 cgd * pmap_rmt.c
44 1.1 cgd * Client interface to pmap rpc service.
45 1.1 cgd * remote call and broadcast service
46 1.1 cgd *
47 1.1 cgd * Copyright (C) 1984, Sun Microsystems, Inc.
48 1.1 cgd */
49 1.1 cgd
50 1.10 jtc #include "namespace.h"
51 1.14 lukem
52 1.7 mrg #include <sys/types.h>
53 1.14 lukem #include <sys/ioctl.h>
54 1.7 mrg #include <sys/poll.h>
55 1.14 lukem #include <sys/socket.h>
56 1.14 lukem
57 1.14 lukem #include <net/if.h>
58 1.14 lukem #include <netinet/in.h>
59 1.14 lukem #include <arpa/inet.h>
60 1.14 lukem
61 1.22 lukem #include <assert.h>
62 1.14 lukem #include <err.h>
63 1.14 lukem #include <errno.h>
64 1.14 lukem #include <stdio.h>
65 1.14 lukem #include <string.h>
66 1.14 lukem #include <unistd.h>
67 1.13 lukem
68 1.13 lukem #include <rpc/rpc.h>
69 1.13 lukem #include <rpc/pmap_prot.h>
70 1.13 lukem #include <rpc/pmap_clnt.h>
71 1.13 lukem #include <rpc/pmap_rmt.h>
72 1.7 mrg
73 1.10 jtc #ifdef __weak_alias
74 1.24 mycroft __weak_alias(pmap_rmtcall,_pmap_rmtcall)
75 1.24 mycroft __weak_alias(xdr_rmtcall_args,_xdr_rmtcall_args)
76 1.24 mycroft __weak_alias(xdr_rmtcallres,_xdr_rmtcallres)
77 1.10 jtc #endif
78 1.10 jtc
79 1.16 mycroft static const struct timeval timeout = { 3, 0 };
80 1.1 cgd
81 1.1 cgd /*
82 1.1 cgd * pmapper remote-call-service interface.
83 1.1 cgd * This routine is used to call the pmapper remote call service
84 1.1 cgd * which will look up a service program in the port maps, and then
85 1.1 cgd * remotely call that routine with the given parameters. This allows
86 1.1 cgd * programs to do a lookup and call in one step.
87 1.1 cgd */
88 1.1 cgd enum clnt_stat
89 1.18 lukem pmap_rmtcall(addr, prog, vers, proc, xdrargs, argsp, xdrres, resp, tout,
90 1.18 lukem port_ptr)
91 1.1 cgd struct sockaddr_in *addr;
92 1.13 lukem u_long prog, vers, proc;
93 1.1 cgd xdrproc_t xdrargs, xdrres;
94 1.1 cgd caddr_t argsp, resp;
95 1.1 cgd struct timeval tout;
96 1.13 lukem u_long *port_ptr;
97 1.1 cgd {
98 1.17 christos int sock = -1;
99 1.14 lukem CLIENT *client;
100 1.1 cgd struct rmtcallargs a;
101 1.1 cgd struct rmtcallres r;
102 1.1 cgd enum clnt_stat stat;
103 1.1 cgd
104 1.22 lukem _DIAGASSERT(addr != NULL);
105 1.22 lukem _DIAGASSERT(port_ptr != NULL);
106 1.22 lukem
107 1.1 cgd addr->sin_port = htons(PMAPPORT);
108 1.17 christos client = clntudp_create(addr, PMAPPROG, PMAPVERS, timeout, &sock);
109 1.29 christos if (client != NULL) {
110 1.1 cgd a.prog = prog;
111 1.1 cgd a.vers = vers;
112 1.1 cgd a.proc = proc;
113 1.1 cgd a.args_ptr = argsp;
114 1.1 cgd a.xdr_args = xdrargs;
115 1.1 cgd r.port_ptr = port_ptr;
116 1.1 cgd r.results_ptr = resp;
117 1.1 cgd r.xdr_results = xdrres;
118 1.29 christos stat = CLNT_CALL(client, (rpcproc_t)PMAPPROC_CALLIT,
119 1.19 christos (xdrproc_t)xdr_rmtcall_args, &a, (xdrproc_t)xdr_rmtcallres,
120 1.19 christos &r, tout);
121 1.1 cgd CLNT_DESTROY(client);
122 1.1 cgd } else {
123 1.1 cgd stat = RPC_FAILED;
124 1.1 cgd }
125 1.1 cgd addr->sin_port = 0;
126 1.1 cgd return (stat);
127 1.1 cgd }
128 1.1 cgd
129 1.1 cgd
130 1.1 cgd /*
131 1.1 cgd * XDR remote call arguments
132 1.1 cgd * written for XDR_ENCODE direction only
133 1.1 cgd */
134 1.1 cgd bool_t
135 1.1 cgd xdr_rmtcall_args(xdrs, cap)
136 1.14 lukem XDR *xdrs;
137 1.14 lukem struct rmtcallargs *cap;
138 1.1 cgd {
139 1.13 lukem u_int lenposition, argposition, position;
140 1.1 cgd
141 1.22 lukem _DIAGASSERT(xdrs != NULL);
142 1.22 lukem _DIAGASSERT(cap != NULL);
143 1.22 lukem
144 1.13 lukem if (xdr_u_long(xdrs, &(cap->prog)) &&
145 1.13 lukem xdr_u_long(xdrs, &(cap->vers)) &&
146 1.13 lukem xdr_u_long(xdrs, &(cap->proc))) {
147 1.1 cgd lenposition = XDR_GETPOS(xdrs);
148 1.13 lukem if (! xdr_u_long(xdrs, &(cap->arglen)))
149 1.1 cgd return (FALSE);
150 1.1 cgd argposition = XDR_GETPOS(xdrs);
151 1.1 cgd if (! (*(cap->xdr_args))(xdrs, cap->args_ptr))
152 1.1 cgd return (FALSE);
153 1.1 cgd position = XDR_GETPOS(xdrs);
154 1.13 lukem cap->arglen = (u_long)position - (u_long)argposition;
155 1.1 cgd XDR_SETPOS(xdrs, lenposition);
156 1.13 lukem if (! xdr_u_long(xdrs, &(cap->arglen)))
157 1.1 cgd return (FALSE);
158 1.1 cgd XDR_SETPOS(xdrs, position);
159 1.1 cgd return (TRUE);
160 1.1 cgd }
161 1.1 cgd return (FALSE);
162 1.1 cgd }
163 1.1 cgd
164 1.1 cgd /*
165 1.1 cgd * XDR remote call results
166 1.1 cgd * written for XDR_DECODE direction only
167 1.1 cgd */
168 1.1 cgd bool_t
169 1.1 cgd xdr_rmtcallres(xdrs, crp)
170 1.14 lukem XDR *xdrs;
171 1.14 lukem struct rmtcallres *crp;
172 1.1 cgd {
173 1.1 cgd caddr_t port_ptr;
174 1.1 cgd
175 1.22 lukem _DIAGASSERT(xdrs != NULL);
176 1.22 lukem _DIAGASSERT(crp != NULL);
177 1.22 lukem
178 1.17 christos port_ptr = (caddr_t)(void *)crp->port_ptr;
179 1.13 lukem if (xdr_reference(xdrs, &port_ptr, sizeof (u_long),
180 1.19 christos (xdrproc_t)xdr_u_long) && xdr_u_long(xdrs, &crp->resultslen)) {
181 1.17 christos crp->port_ptr = (u_long *)(void *)port_ptr;
182 1.1 cgd return ((*(crp->xdr_results))(xdrs, crp->results_ptr));
183 1.1 cgd }
184 1.1 cgd return (FALSE);
185 1.1 cgd }
186