2 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
3 * unrestricted use provided that this legend is included on all tape
4 * media and as a part of the software program in whole or part. Users
5 * may copy or modify Sun RPC without charge, but are not authorized
6 * to license or distribute it to anyone else except as part of a product or
7 * program developed by the user.
9 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
10 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
11 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
13 * Sun RPC is provided with no support and without any obligation on the
14 * part of Sun Microsystems, Inc. to assist in its use, correction,
15 * modification or enhancement.
17 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
18 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
19 * OR ANY PART THEREOF.
21 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
22 * or profits or other special, indirect and consequential damages, even if
23 * Sun has been advised of the possibility of such damages.
25 * Sun Microsystems, Inc.
27 * Mountain View, California 94043
29 * @(#)pmap_rmt.c 1.21 87/08/27 Copyr 1984 Sun Micro
30 * @(#)pmap_rmt.c 2.2 88/08/01 4.0 RPCSRC
31 * $NetBSD: pmap_rmt.c,v 1.29 2000/07/06 03:10:34 christos Exp $
32 * $FreeBSD: src/lib/libc/rpc/pmap_rmt.c,v 1.20 2004/10/16 06:11:35 obrien Exp $
33 * $DragonFly: src/lib/libc/rpc/pmap_rmt.c,v 1.5 2005/11/13 12:27:04 swildner Exp $
38 * Client interface to pmap rpc service.
39 * remote call and broadcast service
41 * Copyright (C) 1984, Sun Microsystems, Inc.
44 #include "namespace.h"
45 #include <sys/types.h>
46 #include <sys/ioctl.h>
48 #include <sys/socket.h>
51 #include <netinet/in.h>
52 #include <arpa/inet.h>
62 #include <rpc/pmap_prot.h>
63 #include <rpc/pmap_clnt.h>
64 #include <rpc/pmap_rmt.h>
65 #include "un-namespace.h"
67 static const struct timeval timeout = { 3, 0 };
70 * pmapper remote-call-service interface.
71 * This routine is used to call the pmapper remote call service
72 * which will look up a service program in the port maps, and then
73 * remotely call that routine with the given parameters. This allows
74 * programs to do a lookup and call in one step.
77 pmap_rmtcall(struct sockaddr_in *addr, u_long prog, u_long vers, u_long proc,
78 xdrproc_t xdrargs, caddr_t argsp, xdrproc_t xdrres, caddr_t resp,
79 struct timeval tout, u_long *port_ptr)
88 assert(port_ptr != NULL);
90 addr->sin_port = htons(PMAPPORT);
91 client = clntudp_create(addr, PMAPPROG, PMAPVERS, timeout, &sock);
98 r.port_ptr = port_ptr;
100 r.xdr_results = xdrres;
101 stat = CLNT_CALL(client, (rpcproc_t)PMAPPROC_CALLIT,
102 (xdrproc_t)xdr_rmtcall_args, &a, (xdrproc_t)xdr_rmtcallres,
104 CLNT_DESTROY(client);
114 * XDR remote call arguments
115 * written for XDR_ENCODE direction only
118 xdr_rmtcall_args(XDR *xdrs, struct rmtcallargs *cap)
120 u_int lenposition, argposition, position;
122 assert(xdrs != NULL);
125 if (xdr_u_long(xdrs, &(cap->prog)) &&
126 xdr_u_long(xdrs, &(cap->vers)) &&
127 xdr_u_long(xdrs, &(cap->proc))) {
128 lenposition = XDR_GETPOS(xdrs);
129 if (! xdr_u_long(xdrs, &(cap->arglen)))
131 argposition = XDR_GETPOS(xdrs);
132 if (! (*(cap->xdr_args))(xdrs, cap->args_ptr))
134 position = XDR_GETPOS(xdrs);
135 cap->arglen = (u_long)position - (u_long)argposition;
136 XDR_SETPOS(xdrs, lenposition);
137 if (! xdr_u_long(xdrs, &(cap->arglen)))
139 XDR_SETPOS(xdrs, position);
146 * XDR remote call results
147 * written for XDR_DECODE direction only
150 xdr_rmtcallres(XDR *xdrs, struct rmtcallres *crp)
154 assert(xdrs != NULL);
157 port_ptr = (caddr_t)(void *)crp->port_ptr;
158 if (xdr_reference(xdrs, &port_ptr, sizeof (u_long),
159 (xdrproc_t)xdr_u_long) && xdr_u_long(xdrs, &crp->resultslen)) {
160 crp->port_ptr = (u_long *)(void *)port_ptr;
161 return ((*(crp->xdr_results))(xdrs, crp->results_ptr));