pmap_rmt.c revision 1.30.6.1 1 1.30.6.1 yamt /* $NetBSD: pmap_rmt.c,v 1.30.6.1 2012/04/17 00:05:23 yamt 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.30.6.1 yamt __RCSID("$NetBSD: pmap_rmt.c,v 1.30.6.1 2012/04/17 00:05:23 yamt 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(xdr_rmtcall_args,_xdr_rmtcall_args)
75 1.24 mycroft __weak_alias(xdr_rmtcallres,_xdr_rmtcallres)
76 1.10 jtc #endif
77 1.10 jtc
78 1.16 mycroft static const struct timeval timeout = { 3, 0 };
79 1.1 cgd
80 1.1 cgd /*
81 1.1 cgd * pmapper remote-call-service interface.
82 1.1 cgd * This routine is used to call the pmapper remote call service
83 1.1 cgd * which will look up a service program in the port maps, and then
84 1.1 cgd * remotely call that routine with the given parameters. This allows
85 1.1 cgd * programs to do a lookup and call in one step.
86 1.1 cgd */
87 1.1 cgd enum clnt_stat
88 1.18 lukem pmap_rmtcall(addr, prog, vers, proc, xdrargs, argsp, xdrres, resp, tout,
89 1.18 lukem port_ptr)
90 1.1 cgd struct sockaddr_in *addr;
91 1.13 lukem u_long prog, vers, proc;
92 1.1 cgd xdrproc_t xdrargs, xdrres;
93 1.1 cgd caddr_t argsp, resp;
94 1.1 cgd struct timeval tout;
95 1.13 lukem u_long *port_ptr;
96 1.1 cgd {
97 1.17 christos int sock = -1;
98 1.14 lukem CLIENT *client;
99 1.1 cgd struct rmtcallargs a;
100 1.1 cgd struct rmtcallres r;
101 1.1 cgd enum clnt_stat stat;
102 1.1 cgd
103 1.22 lukem _DIAGASSERT(addr != NULL);
104 1.22 lukem _DIAGASSERT(port_ptr != NULL);
105 1.22 lukem
106 1.1 cgd addr->sin_port = htons(PMAPPORT);
107 1.17 christos client = clntudp_create(addr, PMAPPROG, PMAPVERS, timeout, &sock);
108 1.29 christos if (client != NULL) {
109 1.1 cgd a.prog = prog;
110 1.1 cgd a.vers = vers;
111 1.1 cgd a.proc = proc;
112 1.1 cgd a.args_ptr = argsp;
113 1.1 cgd a.xdr_args = xdrargs;
114 1.1 cgd r.port_ptr = port_ptr;
115 1.1 cgd r.results_ptr = resp;
116 1.1 cgd r.xdr_results = xdrres;
117 1.29 christos stat = CLNT_CALL(client, (rpcproc_t)PMAPPROC_CALLIT,
118 1.19 christos (xdrproc_t)xdr_rmtcall_args, &a, (xdrproc_t)xdr_rmtcallres,
119 1.19 christos &r, tout);
120 1.1 cgd CLNT_DESTROY(client);
121 1.1 cgd } else {
122 1.1 cgd stat = RPC_FAILED;
123 1.1 cgd }
124 1.1 cgd addr->sin_port = 0;
125 1.1 cgd return (stat);
126 1.1 cgd }
127 1.1 cgd
128 1.1 cgd
129 1.1 cgd /*
130 1.1 cgd * XDR remote call arguments
131 1.1 cgd * written for XDR_ENCODE direction only
132 1.1 cgd */
133 1.1 cgd bool_t
134 1.30.6.1 yamt xdr_rmtcall_args(XDR *xdrs, struct rmtcallargs *cap)
135 1.1 cgd {
136 1.13 lukem u_int lenposition, argposition, position;
137 1.1 cgd
138 1.22 lukem _DIAGASSERT(xdrs != NULL);
139 1.22 lukem _DIAGASSERT(cap != NULL);
140 1.22 lukem
141 1.13 lukem if (xdr_u_long(xdrs, &(cap->prog)) &&
142 1.13 lukem xdr_u_long(xdrs, &(cap->vers)) &&
143 1.13 lukem xdr_u_long(xdrs, &(cap->proc))) {
144 1.1 cgd lenposition = XDR_GETPOS(xdrs);
145 1.13 lukem if (! xdr_u_long(xdrs, &(cap->arglen)))
146 1.1 cgd return (FALSE);
147 1.1 cgd argposition = XDR_GETPOS(xdrs);
148 1.1 cgd if (! (*(cap->xdr_args))(xdrs, cap->args_ptr))
149 1.1 cgd return (FALSE);
150 1.1 cgd position = XDR_GETPOS(xdrs);
151 1.13 lukem cap->arglen = (u_long)position - (u_long)argposition;
152 1.1 cgd XDR_SETPOS(xdrs, lenposition);
153 1.13 lukem if (! xdr_u_long(xdrs, &(cap->arglen)))
154 1.1 cgd return (FALSE);
155 1.1 cgd XDR_SETPOS(xdrs, position);
156 1.1 cgd return (TRUE);
157 1.1 cgd }
158 1.1 cgd return (FALSE);
159 1.1 cgd }
160 1.1 cgd
161 1.1 cgd /*
162 1.1 cgd * XDR remote call results
163 1.1 cgd * written for XDR_DECODE direction only
164 1.1 cgd */
165 1.1 cgd bool_t
166 1.30.6.1 yamt xdr_rmtcallres(XDR *xdrs, struct rmtcallres *crp)
167 1.1 cgd {
168 1.1 cgd caddr_t port_ptr;
169 1.1 cgd
170 1.22 lukem _DIAGASSERT(xdrs != NULL);
171 1.22 lukem _DIAGASSERT(crp != NULL);
172 1.22 lukem
173 1.17 christos port_ptr = (caddr_t)(void *)crp->port_ptr;
174 1.30.6.1 yamt if (xdr_reference(xdrs, &port_ptr, (u_int)sizeof(u_long),
175 1.19 christos (xdrproc_t)xdr_u_long) && xdr_u_long(xdrs, &crp->resultslen)) {
176 1.17 christos crp->port_ptr = (u_long *)(void *)port_ptr;
177 1.1 cgd return ((*(crp->xdr_results))(xdrs, crp->results_ptr));
178 1.1 cgd }
179 1.1 cgd return (FALSE);
180 1.1 cgd }
181