1 /* $NetBSD: pmap_rmt.c,v 1.29 2000/07/06 03:10:34 christos Exp $ */
4 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
5 * unrestricted use provided that this legend is included on all tape
6 * media and as a part of the software program in whole or part. Users
7 * may copy or modify Sun RPC without charge, but are not authorized
8 * to license or distribute it to anyone else except as part of a product or
9 * program developed by the user.
11 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
12 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
13 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
15 * Sun RPC is provided with no support and without any obligation on the
16 * part of Sun Microsystems, Inc. to assist in its use, correction,
17 * modification or enhancement.
19 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
20 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
21 * OR ANY PART THEREOF.
23 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
24 * or profits or other special, indirect and consequential damages, even if
25 * Sun has been advised of the possibility of such damages.
27 * Sun Microsystems, Inc.
29 * Mountain View, California 94043
32 #if defined(LIBC_SCCS) && !defined(lint)
33 static char *sccsid2 = "@(#)pmap_rmt.c 1.21 87/08/27 Copyr 1984 Sun Micro";
34 static char *sccsid = "@(#)pmap_rmt.c 2.2 88/08/01 4.0 RPCSRC";
36 #include <sys/cdefs.h>
37 __FBSDID("$FreeBSD$");
41 * Client interface to pmap rpc service.
42 * remote call and broadcast service
44 * Copyright (C) 1984, Sun Microsystems, Inc.
47 #include "namespace.h"
48 #include <sys/types.h>
49 #include <sys/ioctl.h>
51 #include <sys/socket.h>
54 #include <netinet/in.h>
55 #include <arpa/inet.h>
65 #include <rpc/pmap_prot.h>
66 #include <rpc/pmap_clnt.h>
67 #include <rpc/pmap_rmt.h>
68 #include "un-namespace.h"
70 static const struct timeval timeout = { 3, 0 };
73 * pmapper remote-call-service interface.
74 * This routine is used to call the pmapper remote call service
75 * which will look up a service program in the port maps, and then
76 * remotely call that routine with the given parameters. This allows
77 * programs to do a lookup and call in one step.
80 pmap_rmtcall(addr, prog, vers, proc, xdrargs, argsp, xdrres, resp, tout,
82 struct sockaddr_in *addr;
83 u_long prog, vers, proc;
84 xdrproc_t xdrargs, xdrres;
96 assert(port_ptr != NULL);
98 addr->sin_port = htons(PMAPPORT);
99 client = clntudp_create(addr, PMAPPROG, PMAPVERS, timeout, &sock);
100 if (client != NULL) {
105 a.xdr_args = xdrargs;
106 r.port_ptr = port_ptr;
107 r.results_ptr = resp;
108 r.xdr_results = xdrres;
109 stat = CLNT_CALL(client, (rpcproc_t)PMAPPROC_CALLIT,
110 (xdrproc_t)xdr_rmtcall_args, &a, (xdrproc_t)xdr_rmtcallres,
112 CLNT_DESTROY(client);
122 * XDR remote call arguments
123 * written for XDR_ENCODE direction only
126 xdr_rmtcall_args(xdrs, cap)
128 struct rmtcallargs *cap;
130 u_int lenposition, argposition, position;
132 assert(xdrs != NULL);
135 if (xdr_u_long(xdrs, &(cap->prog)) &&
136 xdr_u_long(xdrs, &(cap->vers)) &&
137 xdr_u_long(xdrs, &(cap->proc))) {
138 lenposition = XDR_GETPOS(xdrs);
139 if (! xdr_u_long(xdrs, &(cap->arglen)))
141 argposition = XDR_GETPOS(xdrs);
142 if (! (*(cap->xdr_args))(xdrs, cap->args_ptr))
144 position = XDR_GETPOS(xdrs);
145 cap->arglen = (u_long)position - (u_long)argposition;
146 XDR_SETPOS(xdrs, lenposition);
147 if (! xdr_u_long(xdrs, &(cap->arglen)))
149 XDR_SETPOS(xdrs, position);
156 * XDR remote call results
157 * written for XDR_DECODE direction only
160 xdr_rmtcallres(xdrs, crp)
162 struct rmtcallres *crp;
166 assert(xdrs != NULL);
169 port_ptr = (caddr_t)(void *)crp->port_ptr;
170 if (xdr_reference(xdrs, &port_ptr, sizeof (u_long),
171 (xdrproc_t)xdr_u_long) && xdr_u_long(xdrs, &crp->resultslen)) {
172 crp->port_ptr = (u_long *)(void *)port_ptr;
173 return ((*(crp->xdr_results))(xdrs, crp->results_ptr));