1 /* $NetBSD: svc_raw.c,v 1.10 1998/11/15 17:32:45 christos 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.10 1998/11/15 17:32:45 christos 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 53 #include <stdlib.h> 54 55 #include <rpc/rpc.h> 56 57 #ifdef __weak_alias 58 __weak_alias(svcraw_create,_svcraw_create); 59 #endif 60 61 /* 62 * This is the "network" that we will be moving data over 63 */ 64 static struct svcraw_private { 65 char _raw_buf[UDPMSGSIZE]; 66 SVCXPRT server; 67 XDR xdr_stream; 68 char verf_body[MAX_AUTH_BYTES]; 69 } *svcraw_private; 70 71 static enum xprt_stat svcraw_stat __P((SVCXPRT *)); 72 static bool_t svcraw_recv __P((SVCXPRT *, struct rpc_msg *)); 73 static bool_t svcraw_reply __P((SVCXPRT *, struct rpc_msg *)); 74 static bool_t svcraw_getargs __P((SVCXPRT *, xdrproc_t, caddr_t)); 75 static bool_t svcraw_freeargs __P((SVCXPRT *, xdrproc_t, caddr_t)); 76 static void svcraw_destroy __P((SVCXPRT *)); 77 78 static const struct xp_ops server_ops = { 79 svcraw_recv, 80 svcraw_stat, 81 svcraw_getargs, 82 svcraw_reply, 83 svcraw_freeargs, 84 svcraw_destroy 85 }; 86 87 SVCXPRT * 88 svcraw_create() 89 { 90 struct svcraw_private *srp = svcraw_private; 91 92 if (srp == 0) { 93 srp = (struct svcraw_private *)calloc(1, sizeof (*srp)); 94 if (srp == 0) 95 return (0); 96 } 97 srp->server.xp_sock = 0; 98 srp->server.xp_port = 0; 99 srp->server.xp_ops = &server_ops; 100 srp->server.xp_verf.oa_base = srp->verf_body; 101 xdrmem_create(&srp->xdr_stream, srp->_raw_buf, UDPMSGSIZE, XDR_FREE); 102 return (&srp->server); 103 } 104 105 /*ARGSUSED*/ 106 static enum xprt_stat 107 svcraw_stat(xprt) 108 SVCXPRT *xprt; 109 { 110 111 return (XPRT_IDLE); 112 } 113 114 /* ARGSUSED */ 115 static bool_t 116 svcraw_recv(xprt, msg) 117 SVCXPRT *xprt; 118 struct rpc_msg *msg; 119 { 120 struct svcraw_private *srp = svcraw_private; 121 XDR *xdrs; 122 123 if (srp == 0) 124 return (0); 125 xdrs = &srp->xdr_stream; 126 xdrs->x_op = XDR_DECODE; 127 XDR_SETPOS(xdrs, 0); 128 if (! xdr_callmsg(xdrs, msg)) 129 return (FALSE); 130 return (TRUE); 131 } 132 133 /* ARGSUSED */ 134 static bool_t 135 svcraw_reply(xprt, msg) 136 SVCXPRT *xprt; 137 struct rpc_msg *msg; 138 { 139 struct svcraw_private *srp = svcraw_private; 140 XDR *xdrs; 141 142 if (srp == 0) 143 return (FALSE); 144 xdrs = &srp->xdr_stream; 145 xdrs->x_op = XDR_ENCODE; 146 XDR_SETPOS(xdrs, 0); 147 if (! xdr_replymsg(xdrs, msg)) 148 return (FALSE); 149 (void)XDR_GETPOS(xdrs); /* called just for overhead */ 150 return (TRUE); 151 } 152 153 /* ARGSUSED */ 154 static bool_t 155 svcraw_getargs(xprt, xdr_args, args_ptr) 156 SVCXPRT *xprt; 157 xdrproc_t xdr_args; 158 caddr_t args_ptr; 159 { 160 struct svcraw_private *srp = svcraw_private; 161 162 if (srp == 0) 163 return (FALSE); 164 return ((*xdr_args)(&srp->xdr_stream, args_ptr)); 165 } 166 167 /* ARGSUSED */ 168 static bool_t 169 svcraw_freeargs(xprt, xdr_args, args_ptr) 170 SVCXPRT *xprt; 171 xdrproc_t xdr_args; 172 caddr_t args_ptr; 173 { 174 struct svcraw_private *srp = svcraw_private; 175 XDR *xdrs; 176 177 if (srp == 0) 178 return (FALSE); 179 xdrs = &srp->xdr_stream; 180 xdrs->x_op = XDR_FREE; 181 return ((*xdr_args)(xdrs, args_ptr)); 182 } 183 184 /*ARGSUSED*/ 185 static void 186 svcraw_destroy(xprt) 187 SVCXPRT *xprt; 188 { 189 } 190