source: rtems-libbsd/freebsd/lib/libc/rpc/pmap_rmt.c

6-freebsd-12
Last change on this file was bb80d9d, checked in by Sebastian Huber <sebastian.huber@…>, on 08/09/18 at 12:02:09

Update to FreeBSD head 2017-12-01

Git mirror commit e724f51f811a4b2bd29447f8b85ab5c2f9b88266.

Update #3472.

  • Property mode set to 100644
File size: 5.0 KB
Line 
1#include <machine/rtems-bsd-user-space.h>
2
3/*      $NetBSD: pmap_rmt.c,v 1.29 2000/07/06 03:10:34 christos Exp $   */
4
5/*-
6 * SPDX-License-Identifier: BSD-3-Clause
7 *
8 * Copyright (c) 2009, Sun Microsystems, Inc.
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions are met:
13 * - Redistributions of source code must retain the above copyright notice,
14 *   this list of conditions and the following disclaimer.
15 * - Redistributions in binary form must reproduce the above copyright notice,
16 *   this list of conditions and the following disclaimer in the documentation
17 *   and/or other materials provided with the distribution.
18 * - Neither the name of Sun Microsystems, Inc. nor the names of its
19 *   contributors may be used to endorse or promote products derived
20 *   from this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
26 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
33 */
34
35#if defined(LIBC_SCCS) && !defined(lint)
36static char *sccsid2 = "@(#)pmap_rmt.c 1.21 87/08/27 Copyr 1984 Sun Micro";
37static char *sccsid = "@(#)pmap_rmt.c   2.2 88/08/01 4.0 RPCSRC";
38#endif
39#include <sys/cdefs.h>
40__FBSDID("$FreeBSD$");
41
42/*
43 * pmap_rmt.c
44 * Client interface to pmap rpc service.
45 * remote call and broadcast service
46 *
47 * Copyright (C) 1984, Sun Microsystems, Inc.
48 */
49
50#include "namespace.h"
51#include <sys/types.h>
52#include <sys/ioctl.h>
53#include <sys/poll.h>
54#include <sys/socket.h>
55
56#include <net/if.h>
57#include <netinet/in.h>
58#include <arpa/inet.h>
59
60#include <assert.h>
61#include <err.h>
62#include <errno.h>
63#include <stdio.h>
64#include <string.h>
65#include <unistd.h>
66
67#include <rpc/rpc.h>
68#include <rpc/pmap_prot.h>
69#include <rpc/pmap_clnt.h>
70#include <rpc/pmap_rmt.h>
71#include "un-namespace.h"
72
73static const struct timeval timeout = { 3, 0 };
74
75/*
76 * pmapper remote-call-service interface.
77 * This routine is used to call the pmapper remote call service
78 * which will look up a service program in the port maps, and then
79 * remotely call that routine with the given parameters.  This allows
80 * programs to do a lookup and call in one step.
81*/
82enum clnt_stat
83pmap_rmtcall(struct sockaddr_in *addr, u_long prog, u_long vers, u_long proc,
84    xdrproc_t xdrargs, caddr_t argsp, xdrproc_t xdrres, caddr_t resp,
85    struct timeval tout, u_long *port_ptr)
86{
87        int sock = -1;
88        CLIENT *client;
89        struct rmtcallargs a;
90        struct rmtcallres r;
91        enum clnt_stat stat;
92
93        assert(addr != NULL);
94        assert(port_ptr != NULL);
95
96        addr->sin_port = htons(PMAPPORT);
97        client = clntudp_create(addr, PMAPPROG, PMAPVERS, timeout, &sock);
98        if (client != NULL) {
99                a.prog = prog;
100                a.vers = vers;
101                a.proc = proc;
102                a.args_ptr = argsp;
103                a.xdr_args = xdrargs;
104                r.port_ptr = port_ptr;
105                r.results_ptr = resp;
106                r.xdr_results = xdrres;
107                stat = CLNT_CALL(client, (rpcproc_t)PMAPPROC_CALLIT,
108                    (xdrproc_t)xdr_rmtcall_args, &a, (xdrproc_t)xdr_rmtcallres,
109                    &r, tout);
110                CLNT_DESTROY(client);
111        } else {
112                stat = RPC_FAILED;
113        }
114        addr->sin_port = 0;
115        return (stat);
116}
117
118
119/*
120 * XDR remote call arguments
121 * written for XDR_ENCODE direction only
122 */
123bool_t
124xdr_rmtcall_args(XDR *xdrs, struct rmtcallargs *cap)
125{
126        u_int lenposition, argposition, position;
127
128        assert(xdrs != NULL);
129        assert(cap != NULL);
130
131        if (xdr_u_long(xdrs, &(cap->prog)) &&
132            xdr_u_long(xdrs, &(cap->vers)) &&
133            xdr_u_long(xdrs, &(cap->proc))) {
134                lenposition = XDR_GETPOS(xdrs);
135                if (! xdr_u_long(xdrs, &(cap->arglen)))
136                    return (FALSE);
137                argposition = XDR_GETPOS(xdrs);
138                if (! (*(cap->xdr_args))(xdrs, cap->args_ptr))
139                    return (FALSE);
140                position = XDR_GETPOS(xdrs);
141                cap->arglen = (u_long)position - (u_long)argposition;
142                XDR_SETPOS(xdrs, lenposition);
143                if (! xdr_u_long(xdrs, &(cap->arglen)))
144                    return (FALSE);
145                XDR_SETPOS(xdrs, position);
146                return (TRUE);
147        }
148        return (FALSE);
149}
150
151/*
152 * XDR remote call results
153 * written for XDR_DECODE direction only
154 */
155bool_t
156xdr_rmtcallres(XDR *xdrs, struct rmtcallres *crp)
157{
158        caddr_t port_ptr;
159
160        assert(xdrs != NULL);
161        assert(crp != NULL);
162
163        port_ptr = (caddr_t)(void *)crp->port_ptr;
164        if (xdr_reference(xdrs, &port_ptr, sizeof (u_long),
165            (xdrproc_t)xdr_u_long) && xdr_u_long(xdrs, &crp->resultslen)) {
166                crp->port_ptr = (u_long *)(void *)port_ptr;
167                return ((*(crp->xdr_results))(xdrs, crp->results_ptr));
168        }
169        return (FALSE);
170}
Note: See TracBrowser for help on using the repository browser.