2 * Copyright (c) 2009, Sun Microsystems, Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * - Redistributions of source code must retain the above copyright notice,
8 * this list of conditions and the following disclaimer.
9 * - Redistributions in binary form must reproduce the above copyright notice,
10 * this list of conditions and the following disclaimer in the documentation
11 * and/or other materials provided with the distribution.
12 * - Neither the name of Sun Microsystems, Inc. nor the names of its
13 * contributors may be used to endorse or promote products derived
14 * from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
28 * @(#)pmap_rmt.c 1.21 87/08/27 Copyr 1984 Sun Micro
29 * @(#)pmap_rmt.c 2.2 88/08/01 4.0 RPCSRC
30 * $NetBSD: pmap_rmt.c,v 1.29 2000/07/06 03:10:34 christos Exp $
31 * $FreeBSD: src/lib/libc/rpc/pmap_rmt.c,v 1.20 2004/10/16 06:11:35 obrien Exp $
32 * $DragonFly: src/lib/libc/rpc/pmap_rmt.c,v 1.5 2005/11/13 12:27:04 swildner Exp $
37 * Client interface to pmap rpc service.
38 * remote call and broadcast service
40 * Copyright (C) 1984, Sun Microsystems, Inc.
43 #include "namespace.h"
44 #include <sys/types.h>
45 #include <sys/ioctl.h>
47 #include <sys/socket.h>
50 #include <netinet/in.h>
51 #include <arpa/inet.h>
61 #include <rpc/pmap_prot.h>
62 #include <rpc/pmap_clnt.h>
63 #include <rpc/pmap_rmt.h>
64 #include "un-namespace.h"
66 static const struct timeval timeout = { 3, 0 };
69 * pmapper remote-call-service interface.
70 * This routine is used to call the pmapper remote call service
71 * which will look up a service program in the port maps, and then
72 * remotely call that routine with the given parameters. This allows
73 * programs to do a lookup and call in one step.
76 pmap_rmtcall(struct sockaddr_in *addr, u_long prog, u_long vers, u_long proc,
77 xdrproc_t xdrargs, caddr_t argsp, xdrproc_t xdrres, caddr_t resp,
78 struct timeval tout, u_long *port_ptr)
87 assert(port_ptr != NULL);
89 addr->sin_port = htons(PMAPPORT);
90 client = clntudp_create(addr, PMAPPROG, PMAPVERS, timeout, &sock);
97 r.port_ptr = port_ptr;
99 r.xdr_results = xdrres;
100 stat = CLNT_CALL(client, (rpcproc_t)PMAPPROC_CALLIT,
101 (xdrproc_t)xdr_rmtcall_args, &a, (xdrproc_t)xdr_rmtcallres,
103 CLNT_DESTROY(client);
113 * XDR remote call arguments
114 * written for XDR_ENCODE direction only
117 xdr_rmtcall_args(XDR *xdrs, struct rmtcallargs *cap)
119 u_int lenposition, argposition, position;
121 assert(xdrs != NULL);
124 if (xdr_u_long(xdrs, &(cap->prog)) &&
125 xdr_u_long(xdrs, &(cap->vers)) &&
126 xdr_u_long(xdrs, &(cap->proc))) {
127 lenposition = XDR_GETPOS(xdrs);
128 if (! xdr_u_long(xdrs, &(cap->arglen)))
130 argposition = XDR_GETPOS(xdrs);
131 if (! (*(cap->xdr_args))(xdrs, cap->args_ptr))
133 position = XDR_GETPOS(xdrs);
134 cap->arglen = (u_long)position - (u_long)argposition;
135 XDR_SETPOS(xdrs, lenposition);
136 if (! xdr_u_long(xdrs, &(cap->arglen)))
138 XDR_SETPOS(xdrs, position);
145 * XDR remote call results
146 * written for XDR_DECODE direction only
149 xdr_rmtcallres(XDR *xdrs, struct rmtcallres *crp)
153 assert(xdrs != NULL);
156 port_ptr = (caddr_t)(void *)crp->port_ptr;
157 if (xdr_reference(xdrs, &port_ptr, sizeof (u_long),
158 (xdrproc_t)xdr_u_long) && xdr_u_long(xdrs, &crp->resultslen)) {
159 crp->port_ptr = (u_long *)(void *)port_ptr;
160 return ((*(crp->xdr_results))(xdrs, crp->results_ptr));