xref: /netbsd-src/lib/libc/rpc/svc_raw.c (revision 2a399c6883d870daece976daec6ffa7bb7f934ce)
1 /*	$NetBSD: svc_raw.c,v 1.5 1997/07/21 14:08:39 jtc Exp $	*/
2 
3 /*
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.
10  *
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.
14  *
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.
18  *
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.
22  *
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.
26  *
27  * Sun Microsystems, Inc.
28  * 2550 Garcia Avenue
29  * Mountain View, California  94043
30  */
31 
32 #include <sys/cdefs.h>
33 #if defined(LIBC_SCCS) && !defined(lint)
34 #if 0
35 static char *sccsid = "@(#)svc_raw.c 1.15 87/08/11 Copyr 1984 Sun Micro";
36 static char *sccsid = "@(#)svc_raw.c	2.1 88/07/29 4.0 RPCSRC";
37 #else
38 __RCSID("$NetBSD: svc_raw.c,v 1.5 1997/07/21 14:08:39 jtc Exp $");
39 #endif
40 #endif
41 
42 /*
43  * svc_raw.c,   This a toy for simple testing and timing.
44  * Interface to create an rpc client and server in the same UNIX process.
45  * This lets us similate rpc and get rpc (round trip) overhead, without
46  * any interference from the kernal.
47  *
48  * Copyright (C) 1984, Sun Microsystems, Inc.
49  */
50 
51 #include "namespace.h"
52 #include <stdlib.h>
53 #include <rpc/rpc.h>
54 
55 #ifdef __weak_alias
56 __weak_alias(svcraw_create,_svcraw_create);
57 #endif
58 
59 /*
60  * This is the "network" that we will be moving data over
61  */
62 static struct svcraw_private {
63 	char	_raw_buf[UDPMSGSIZE];
64 	SVCXPRT	server;
65 	XDR	xdr_stream;
66 	char	verf_body[MAX_AUTH_BYTES];
67 } *svcraw_private;
68 
69 static enum xprt_stat svcraw_stat __P((SVCXPRT *));
70 static bool_t svcraw_recv __P((SVCXPRT *, struct rpc_msg *));
71 static bool_t svcraw_reply __P((SVCXPRT *, struct rpc_msg *));
72 static bool_t svcraw_getargs __P((SVCXPRT *, xdrproc_t, caddr_t));
73 static bool_t svcraw_freeargs __P((SVCXPRT *, xdrproc_t, caddr_t));
74 static void svcraw_destroy __P((SVCXPRT *));
75 
76 static struct xp_ops server_ops = {
77 	svcraw_recv,
78 	svcraw_stat,
79 	svcraw_getargs,
80 	svcraw_reply,
81 	svcraw_freeargs,
82 	svcraw_destroy
83 };
84 
85 SVCXPRT *
86 svcraw_create()
87 {
88 	register struct svcraw_private *srp = svcraw_private;
89 
90 	if (srp == 0) {
91 		srp = (struct svcraw_private *)calloc(1, sizeof (*srp));
92 		if (srp == 0)
93 			return (0);
94 	}
95 	srp->server.xp_sock = 0;
96 	srp->server.xp_port = 0;
97 	srp->server.xp_ops = &server_ops;
98 	srp->server.xp_verf.oa_base = srp->verf_body;
99 	xdrmem_create(&srp->xdr_stream, srp->_raw_buf, UDPMSGSIZE, XDR_FREE);
100 	return (&srp->server);
101 }
102 
103 /*ARGSUSED*/
104 static enum xprt_stat
105 svcraw_stat(xprt)
106 	SVCXPRT *xprt;
107 {
108 
109 	return (XPRT_IDLE);
110 }
111 
112 static bool_t
113 svcraw_recv(xprt, msg)
114 	SVCXPRT *xprt;
115 	struct rpc_msg *msg;
116 {
117 	register struct svcraw_private *srp = svcraw_private;
118 	register XDR *xdrs;
119 
120 	if (srp == 0)
121 		return (0);
122 	xdrs = &srp->xdr_stream;
123 	xdrs->x_op = XDR_DECODE;
124 	XDR_SETPOS(xdrs, 0);
125 	if (! xdr_callmsg(xdrs, msg))
126 	       return (FALSE);
127 	return (TRUE);
128 }
129 
130 static bool_t
131 svcraw_reply(xprt, msg)
132 	SVCXPRT *xprt;
133 	struct rpc_msg *msg;
134 {
135 	register struct svcraw_private *srp = svcraw_private;
136 	register XDR *xdrs;
137 
138 	if (srp == 0)
139 		return (FALSE);
140 	xdrs = &srp->xdr_stream;
141 	xdrs->x_op = XDR_ENCODE;
142 	XDR_SETPOS(xdrs, 0);
143 	if (! xdr_replymsg(xdrs, msg))
144 	       return (FALSE);
145 	(void)XDR_GETPOS(xdrs);  /* called just for overhead */
146 	return (TRUE);
147 }
148 
149 static bool_t
150 svcraw_getargs(xprt, xdr_args, args_ptr)
151 	SVCXPRT *xprt;
152 	xdrproc_t xdr_args;
153 	caddr_t args_ptr;
154 {
155 	register struct svcraw_private *srp = svcraw_private;
156 
157 	if (srp == 0)
158 		return (FALSE);
159 	return ((*xdr_args)(&srp->xdr_stream, args_ptr));
160 }
161 
162 static bool_t
163 svcraw_freeargs(xprt, xdr_args, args_ptr)
164 	SVCXPRT *xprt;
165 	xdrproc_t xdr_args;
166 	caddr_t args_ptr;
167 {
168 	register struct svcraw_private *srp = svcraw_private;
169 	register XDR *xdrs;
170 
171 	if (srp == 0)
172 		return (FALSE);
173 	xdrs = &srp->xdr_stream;
174 	xdrs->x_op = XDR_FREE;
175 	return ((*xdr_args)(xdrs, args_ptr));
176 }
177 
178 /*ARGSUSED*/
179 static void
180 svcraw_destroy(xprt)
181 	SVCXPRT *xprt;
182 {
183 }
184