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