source: rtems-libbsd/services/librpc/src/rpc/clnt_raw.c @ e599318

4.115-freebsd-12freebsd-9.3
Last change on this file since e599318 was e599318, checked in by Sebastian Huber <sebastian.huber@…>, on Oct 9, 2013 at 8:52:54 PM

Update files to match FreeBSD layout

Add compatibility with Newlib header files. Some FreeBSD header files
are mapped by the translation script:

o rtems/bsd/sys/_types.h
o rtems/bsd/sys/errno.h
o rtems/bsd/sys/lock.h
o rtems/bsd/sys/param.h
o rtems/bsd/sys/resource.h
o rtems/bsd/sys/time.h
o rtems/bsd/sys/timespec.h
o rtems/bsd/sys/types.h
o rtems/bsd/sys/unistd.h

It is now possible to include <sys/socket.h> directly for example.

Generate one Makefile which builds everything including tests.

  • Property mode set to 100644
File size: 6.2 KB
Line 
1/*
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.
8 *
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.
12 *
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.
16 *
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.
20 *
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.
24 *
25 * Sun Microsystems, Inc.
26 * 2550 Garcia Avenue
27 * Mountain View, California  94043
28 */
29
30#if defined(LIBC_SCCS) && !defined(lint)
31/*static char *sccsid = "from: @(#)clnt_raw.c 1.22 87/08/11 Copyr 1984 Sun Micro";*/
32/*static char *sccsid = "from: @(#)clnt_raw.c   2.2 88/08/01 4.0 RPCSRC";*/
33static char *rcsid = "$FreeBSD: src/lib/libc/rpc/clnt_raw.c,v 1.10 1999/08/28 00:00:36 peter Exp $";
34#endif
35
36/*
37 * clnt_raw.c
38 *
39 * Copyright (C) 1984, Sun Microsystems, Inc.
40 *
41 * Memory based rpc for simple testing and timing.
42 * Interface to create an rpc client and server in the same process.
43 * This lets us similate rpc and get round trip overhead, without
44 * any interference from the kernel.
45 */
46
47#ifdef HAVE_CONFIG_H
48#include "config.h"
49#endif
50
51#include <rpc/rpc.h>
52#include <stdlib.h>
53#include <stdio.h>
54#ifdef __rtems__
55#include <rpc/rpc_rtems.h>
56#endif
57
58#define MCALL_MSG_SIZE 24
59
60/*
61 * This is the "network" we will be moving stuff over.
62 */
63struct clnt_raw_private {
64        CLIENT  client_object;
65        XDR     xdr_stream;
66        char    _raw_buf[UDPMSGSIZE];
67        union {
68            struct rpc_msg      mashl_rpcmsg;
69            char                mashl_callmsg[MCALL_MSG_SIZE];
70        } u;
71        u_int   mcnt;
72};
73#define clntraw_private (rtems_rpc_task_variables->clnt_raw_private)
74
75static enum clnt_stat   clntraw_call(CLIENT *h, rpcproc_t proc, xdrproc_t xargs, void *argsp, xdrproc_t xresults, void *resultsp, struct timeval timeout);
76static void             clntraw_abort(void);
77static void             clntraw_geterr(CLIENT *h, struct rpc_err*);
78static bool_t           clntraw_freeres(CLIENT *, xdrproc_t, void*);
79static bool_t           clntraw_control(CLIENT *, int, char *);
80static void             clntraw_destroy(CLIENT *);
81
82static struct clnt_ops client_ops = {
83        clntraw_call,
84        clntraw_abort,
85        clntraw_geterr,
86        clntraw_freeres,
87        clntraw_destroy,
88        clntraw_control
89};
90
91/*
92 * Create a client handle for memory based rpc.
93 */
94CLIENT *
95clntraw_create(
96        u_long prog,
97        u_long vers )
98{
99        struct clnt_raw_private *clp = clntraw_private;
100        struct rpc_msg call_msg;
101        XDR *xdrs = &clp->xdr_stream;
102        CLIENT  *client = &clp->client_object;
103
104        if (clp == 0) {
105                clp = (struct clnt_raw_private *)calloc(1, sizeof (*clp));
106                if (clp == 0)
107                        return (0);
108                clntraw_private = clp;
109        }
110        /*
111         * pre-serialize the static part of the call msg and stash it away
112         */
113        call_msg.rm_direction = CALL;
114        call_msg.rm_call.cb_rpcvers = RPC_MSG_VERSION;
115        call_msg.rm_call.cb_prog = prog;
116        call_msg.rm_call.cb_vers = vers;
117        xdrmem_create(xdrs, clp->u.mashl_callmsg, MCALL_MSG_SIZE, XDR_ENCODE);
118        if (! xdr_callhdr(xdrs, &call_msg)) {
119                perror("clnt_raw.c - Fatal header serialization error.");
120        }
121        clp->mcnt = XDR_GETPOS(xdrs);
122        XDR_DESTROY(xdrs);
123
124        /*
125         * Set xdrmem for client/server shared buffer
126         */
127        xdrmem_create(xdrs, clp->_raw_buf, UDPMSGSIZE, XDR_FREE);
128
129        /*
130         * create client handle
131         */
132        client->cl_ops = &client_ops;
133        client->cl_auth = authnone_create();
134        return (client);
135}
136
137static enum clnt_stat
138clntraw_call(
139        CLIENT *h,
140        rpcproc_t proc,
141        xdrproc_t xargs,
142        void *argsp,
143        xdrproc_t xresults,
144        void *resultsp,
145        struct timeval timeout )
146{
147        struct clnt_raw_private *clp = clntraw_private;
148        XDR *xdrs = &clp->xdr_stream;
149        struct rpc_msg msg;
150        enum clnt_stat status;
151        struct rpc_err error;
152
153        if (clp == 0)
154                return (RPC_FAILED);
155call_again:
156        /*
157         * send request
158         */
159        xdrs->x_op = XDR_ENCODE;
160        XDR_SETPOS(xdrs, 0);
161        clp->u.mashl_rpcmsg.rm_xid ++ ;
162        if ((! XDR_PUTBYTES(xdrs, clp->u.mashl_callmsg, clp->mcnt)) ||
163            (! XDR_PUTLONG(xdrs, (long *)&proc)) ||
164            (! AUTH_MARSHALL(h->cl_auth, xdrs)) ||
165            (! (*xargs)(xdrs, argsp))) {
166                return (RPC_CANTENCODEARGS);
167        }
168        (void)XDR_GETPOS(xdrs);  /* called just to cause overhead */
169
170        /*
171         * We have to call server input routine here because this is
172         * all going on in one process. Yuk.
173         */
174        svc_getreq(1);
175
176        /*
177         * get results
178         */
179        xdrs->x_op = XDR_DECODE;
180        XDR_SETPOS(xdrs, 0);
181        msg.acpted_rply.ar_verf = _null_auth;
182        msg.acpted_rply.ar_results.where = resultsp;
183        msg.acpted_rply.ar_results.proc = xresults;
184        if (! xdr_replymsg(xdrs, &msg))
185                return (RPC_CANTDECODERES);
186        _seterr_reply(&msg, &error);
187        status = error.re_status;
188
189        if (status == RPC_SUCCESS) {
190                if (! AUTH_VALIDATE(h->cl_auth, &msg.acpted_rply.ar_verf)) {
191                        status = RPC_AUTHERROR;
192                }
193        }  /* end successful completion */
194        else {
195                if (AUTH_REFRESH(h->cl_auth, &msg))
196                        goto call_again;
197        }  /* end of unsuccessful completion */
198
199        if (status == RPC_SUCCESS) {
200                if (! AUTH_VALIDATE(h->cl_auth, &msg.acpted_rply.ar_verf)) {
201                        status = RPC_AUTHERROR;
202                }
203                if (msg.acpted_rply.ar_verf.oa_base != NULL) {
204                        xdrs->x_op = XDR_FREE;
205                        (void)xdr_opaque_auth(xdrs, &(msg.acpted_rply.ar_verf));
206                }
207        }
208
209        return (status);
210}
211
212static void
213clntraw_geterr(CLIENT *cl, struct rpc_err *err)
214{
215}
216
217
218static bool_t
219clntraw_freeres(
220        CLIENT *cl,
221        xdrproc_t xdr_res,
222        void *res_ptr )
223{
224        struct clnt_raw_private *clp = clntraw_private;
225        XDR *xdrs = &clp->xdr_stream;
226        bool_t rval;
227
228        if (clp == 0)
229        {
230                rval = (bool_t) RPC_FAILED;
231                return (rval);
232        }
233        xdrs->x_op = XDR_FREE;
234        return ((*xdr_res)(xdrs, res_ptr));
235}
236
237static void
238clntraw_abort(void)
239{
240}
241
242static bool_t
243clntraw_control(CLIENT *cl, int request, char *info)
244{
245        return (FALSE);
246}
247
248static void
249clntraw_destroy(CLIENT *cl)
250{
251}
Note: See TracBrowser for help on using the repository browser.