Annotation of 43BSDReno/lib/librpc/clnt_raw.c, revision 1.1

1.1     ! root        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: #ifndef lint
        !            30: static char sccsid[] = "@(#)clnt_raw.c 1.4 85/03/17 Copyr 1984 Sun Micro";
        !            31: #endif
        !            32: 
        !            33: /*
        !            34:  * clnt_raw.c
        !            35:  *
        !            36:  * Copyright (C) 1984, Sun Microsystems, Inc.
        !            37:  *
        !            38:  * Memory based rpc for simple testing and timing.
        !            39:  * Interface to create an rpc client and server in the same process.
        !            40:  * This lets us similate rpc and get round trip overhead, without
        !            41:  * any interference from the kernal.
        !            42:  */
        !            43: 
        !            44: #include "types.h"
        !            45: #include <sys/time.h>
        !            46: #include <netinet/in.h>
        !            47: #include "xdr.h"
        !            48: #include "auth.h"
        !            49: #include "clnt.h"
        !            50: #include "rpc_msg.h"
        !            51: 
        !            52: #ifndef NULL
        !            53: #define NULL ((caddr_t)0)
        !            54: #endif
        !            55: #define MCALL_MSG_SIZE 24
        !            56: 
        !            57: /*
        !            58:  * This is the "network" we will be moving stuff over.
        !            59:  */
        !            60: char _raw_buf[UDPMSGSIZE];
        !            61: 
        !            62: static char    mashl_callmsg[MCALL_MSG_SIZE];
        !            63: static u_int   mcnt;
        !            64: 
        !            65: static enum clnt_stat  clntraw_call();
        !            66: static void            clntraw_abort();
        !            67: static void            clntraw_geterr();
        !            68: static bool_t          clntraw_freeres();
        !            69: static void            clntraw_destroy();
        !            70: 
        !            71: static struct clnt_ops client_ops = {
        !            72:        clntraw_call,
        !            73:        clntraw_abort,
        !            74:        clntraw_geterr,
        !            75:        clntraw_freeres,
        !            76:        clntraw_destroy
        !            77: };
        !            78: 
        !            79: static CLIENT  client_object;
        !            80: static CLIENT  *client = &client_object;
        !            81: static XDR     xdr_stream;
        !            82: 
        !            83: void   svc_getreq();
        !            84: 
        !            85: /*
        !            86:  * Create a client handle for memory based rpc.
        !            87:  */
        !            88: CLIENT *
        !            89: clntraw_create(prog, vers)
        !            90:        u_long prog;
        !            91:        u_long vers;
        !            92: {
        !            93:        struct rpc_msg call_msg;
        !            94:        XDR *xdrs = &xdr_stream;
        !            95: 
        !            96:        /*
        !            97:         * pre-serialize the staic part of the call msg and stash it away
        !            98:         */
        !            99:        call_msg.rm_direction = CALL;
        !           100:        call_msg.rm_call.cb_rpcvers = RPC_MSG_VERSION;
        !           101:        call_msg.rm_call.cb_prog = prog;
        !           102:        call_msg.rm_call.cb_vers = vers;
        !           103:        xdrmem_create(xdrs, mashl_callmsg, MCALL_MSG_SIZE, XDR_ENCODE); 
        !           104:        if (! xdr_callhdr(xdrs, &call_msg)) {
        !           105:                perror("clnt_raw.c - Fatal header serialization error.");
        !           106:        }
        !           107:        mcnt = XDR_GETPOS(xdrs);
        !           108:        XDR_DESTROY(xdrs);
        !           109: 
        !           110:        /*
        !           111:         * Set xdrmem for client/server shared buffer
        !           112:         */
        !           113:        xdrmem_create(xdrs, _raw_buf, UDPMSGSIZE, XDR_FREE);
        !           114: 
        !           115:        /*
        !           116:         * create client handle
        !           117:         */
        !           118:        client->cl_ops = &client_ops;
        !           119:        client->cl_auth = authnone_create();
        !           120:        return (client);
        !           121: }
        !           122: 
        !           123: static enum clnt_stat 
        !           124: clntraw_call(h, proc, xargs, argsp, xresults, resultsp, timeout)
        !           125:        CLIENT *h;
        !           126:        u_long proc;
        !           127:        xdrproc_t xargs;
        !           128:        caddr_t argsp;
        !           129:        xdrproc_t xresults;
        !           130:        caddr_t resultsp;
        !           131:        struct timeval timeout;
        !           132: {
        !           133:        register XDR *xdrs = &xdr_stream;
        !           134:        struct rpc_msg msg;
        !           135:        enum clnt_stat status;
        !           136:        struct rpc_err error;
        !           137: 
        !           138: call_again:
        !           139:        /*
        !           140:         * send request
        !           141:         */
        !           142:        xdrs->x_op = XDR_ENCODE;
        !           143:        XDR_SETPOS(xdrs, 0);
        !           144:        ((struct rpc_msg *)mashl_callmsg)->rm_xid ++ ;
        !           145:        if ((! XDR_PUTBYTES(xdrs, mashl_callmsg, mcnt)) ||
        !           146:            (! XDR_PUTLONG(xdrs, (long *)&proc)) ||
        !           147:            (! AUTH_MARSHALL(h->cl_auth, xdrs)) ||
        !           148:            (! (*xargs)(xdrs, argsp))) {
        !           149:                return (RPC_CANTENCODEARGS);
        !           150:        }
        !           151:        (void)XDR_GETPOS(xdrs);  /* called just to cause overhead */
        !           152: 
        !           153:        /*
        !           154:         * We have to call server input routine here because this is
        !           155:         * all going on in one process. Yuk.
        !           156:         */
        !           157:        svc_getreq(1);
        !           158: 
        !           159:        /*
        !           160:         * get results
        !           161:         */
        !           162:        xdrs->x_op = XDR_DECODE;
        !           163:        XDR_SETPOS(xdrs, 0);
        !           164:        msg.acpted_rply.ar_verf = _null_auth;
        !           165:        msg.acpted_rply.ar_results.where = resultsp;
        !           166:        msg.acpted_rply.ar_results.proc = xresults;
        !           167:        if (! xdr_replymsg(xdrs, &msg))
        !           168:                return (RPC_CANTDECODERES);
        !           169:        _seterr_reply(&msg, &error);
        !           170:        status = error.re_status;
        !           171: 
        !           172:        if (status == RPC_SUCCESS) {
        !           173:                if (! AUTH_VALIDATE(h->cl_auth, &msg.acpted_rply.ar_verf)) {
        !           174:                        status = RPC_AUTHERROR;
        !           175:                }
        !           176:        }  /* end successful completion */
        !           177:        else {
        !           178:                if (AUTH_REFRESH(h->cl_auth))
        !           179:                        goto call_again;
        !           180:        }  /* end of unsuccessful completion */
        !           181: 
        !           182:        if (status == RPC_SUCCESS) {
        !           183:                if (! AUTH_VALIDATE(h->cl_auth, &msg.acpted_rply.ar_verf)) {
        !           184:                        status = RPC_AUTHERROR;
        !           185:                }
        !           186:                if (msg.acpted_rply.ar_verf.oa_base != NULL) {
        !           187:                        xdrs->x_op = XDR_FREE;
        !           188:                        (void)xdr_opaque_auth(xdrs, &(msg.acpted_rply.ar_verf));
        !           189:                }
        !           190:        }
        !           191: 
        !           192:        return (status);
        !           193: }
        !           194: 
        !           195: static void
        !           196: clntraw_geterr()
        !           197: {
        !           198: }
        !           199: 
        !           200: 
        !           201: static bool_t
        !           202: clntraw_freeres(cl, xdr_res, res_ptr)
        !           203:        CLIENT *cl;
        !           204:        xdrproc_t xdr_res;
        !           205:        caddr_t res_ptr;
        !           206: {
        !           207:        register XDR *xdrs = &xdr_stream;
        !           208: 
        !           209:        xdrs->x_op = XDR_FREE;
        !           210:        return ((*xdr_res)(xdrs, res_ptr));
        !           211: }
        !           212: 
        !           213: static void
        !           214: clntraw_abort()
        !           215: {
        !           216: }
        !           217: 
        !           218: static void
        !           219: clntraw_destroy()
        !           220: {
        !           221: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.