File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / libnet / src / libnet_build_rpc.c
Revision 1.1.1.3 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Wed Sep 27 11:11:38 2023 UTC (9 months, 1 week ago) by misho
Branches: libnet, MAIN
CVS tags: v1_2p1, HEAD
Version 1.2p1

    1: /*
    2:  *
    3:  *  libnet
    4:  *  libnet_build_rpc.c - RPC packet assembler
    5:  *
    6:  *  Copyright (c) 1998 - 2004 Mike D. Schiffman <mike@infonexus.com>
    7:  *                            Jason Damron <jdamron@stackheap.org>
    8:  *  All rights reserved.
    9:  *
   10:  * Redistribution and use in source and binary forms, with or without
   11:  * modification, are permitted provided that the following conditions
   12:  * are met:
   13:  * 1. Redistributions of source code must retain the above copyright
   14:  *    notice, this list of conditions and the following disclaimer.
   15:  * 2. Redistributions in binary form must reproduce the above copyright
   16:  *    notice, this list of conditions and the following disclaimer in the
   17:  *    documentation and/or other materials provided with the distribution.
   18:  *
   19:  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
   20:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   21:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   22:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
   23:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   24:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   25:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   26:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   27:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   28:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   29:  * SUCH DAMAGE.
   30:  *
   31:  */
   32: 
   33: #include "common.h"
   34: 
   35: libnet_ptag_t
   36: libnet_build_rpc_call(uint32_t rm, uint32_t xid, uint32_t prog_num, 
   37: uint32_t prog_vers, uint32_t procedure, uint32_t cflavor, uint32_t clength, 
   38: uint8_t *cdata, uint32_t vflavor, uint32_t vlength, const uint8_t *vdata, 
   39: const uint8_t *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
   40: {
   41:     uint32_t n, h;
   42:     libnet_pblock_t *p;
   43:     struct libnet_rpc_call_tcp_hdr rpc_hdr;
   44: 
   45:     if (l == NULL)
   46:     { 
   47:         return (-1);
   48:     } 
   49: 
   50:     /* Credential and Verifier buffers not yet implemented.
   51:      * n = LIBNET_RPC_CALL_H + clength + vlength + payload_s;
   52:      */
   53: 
   54:     if (rm)
   55:     {
   56:         n = LIBNET_RPC_CALL_TCP_H + payload_s;
   57:     } 
   58:     else
   59:     {
   60:         n = LIBNET_RPC_CALL_H + payload_s;
   61:     }
   62:  
   63:     h = 0;
   64: 
   65:     /*
   66:      *  Find the existing protocol block if a ptag is specified, or create
   67:      *  a new one.
   68:      */
   69:     p = libnet_pblock_probe(l, ptag, n, LIBNET_PBLOCK_RPC_CALL_H);
   70:     if (p == NULL)
   71:     {
   72:         return (-1);
   73:     }
   74: 
   75:     memset(&rpc_hdr, 0, sizeof(rpc_hdr));
   76:     if (rm)
   77:     {
   78:        rpc_hdr.rpc_record_marking                 = htonl(rm + payload_s);
   79:     }
   80:     rpc_hdr.rpc_common.rpc_xid                    = htonl(xid);
   81:     rpc_hdr.rpc_common.rpc_type                   = LIBNET_RPC_CALL;
   82:     rpc_hdr.rpc_common.rpc_call.rpc_rpcvers       = htonl(LIBNET_RPC_VERS);
   83:     rpc_hdr.rpc_common.rpc_call.rpc_prognum       = htonl(prog_num);
   84:     rpc_hdr.rpc_common.rpc_call.rpc_vers          = htonl(prog_vers);
   85:     rpc_hdr.rpc_common.rpc_call.rpc_procedure     = htonl(procedure);
   86:     /*  XXX Eventually should allow for opaque auth data. */
   87:     rpc_hdr.rpc_common.rpc_call.rpc_credentials.rpc_auth_flavor= htonl(cflavor);
   88:     rpc_hdr.rpc_common.rpc_call.rpc_credentials.rpc_auth_length= htonl(clength);
   89:     rpc_hdr.rpc_common.rpc_call.rpc_verifier.rpc_auth_flavor   = htonl(vflavor);
   90:     rpc_hdr.rpc_common.rpc_call.rpc_verifier.rpc_auth_length   = htonl(vlength);
   91: 
   92:     if (rm)
   93:     {
   94:         n = libnet_pblock_append(l, p, (uint8_t *)&rpc_hdr, 
   95:                 LIBNET_RPC_CALL_TCP_H);
   96:     }
   97:     else
   98:     {
   99:         n = libnet_pblock_append(l, p, (uint8_t *)&rpc_hdr.rpc_common, 
  100:                 LIBNET_RPC_CALL_H);
  101:     }
  102: 
  103:     if (n == -1)
  104:     {
  105:         goto bad;
  106:     }
  107:  
  108:     /* boilerplate payload sanity check / append macro */
  109:     LIBNET_DO_PAYLOAD(l, p);
  110: 
  111:     return (ptag ? ptag : libnet_pblock_update(l, p, h,
  112:             LIBNET_PBLOCK_RPC_CALL_H));
  113: bad:
  114:     libnet_pblock_delete(l, p);
  115:     return (-1);
  116: }
  117: 
  118: /**
  119:  * Local Variables:
  120:  *  indent-tabs-mode: nil
  121:  *  c-file-style: "stroustrup"
  122:  * End:
  123:  */

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>