Annotation of embedaddon/libnet/src/libnet_build_rpc.c, revision 1.1.1.2

1.1       misho       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: #if (HAVE_CONFIG_H)
                     34: #include "../include/config.h"
                     35: #endif
                     36: #if (!(_WIN32) || (__CYGWIN__)) 
                     37: #include "../include/libnet.h"
                     38: #else
                     39: #include "../include/win32/libnet.h"
                     40: #endif
                     41: 
                     42: libnet_ptag_t
1.1.1.2 ! misho      43: libnet_build_rpc_call(uint32_t rm, uint32_t xid, uint32_t prog_num, 
        !            44: uint32_t prog_vers, uint32_t procedure, uint32_t cflavor, uint32_t clength, 
        !            45: uint8_t *cdata, uint32_t vflavor, uint32_t vlength, const uint8_t *vdata, 
        !            46: const uint8_t *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
1.1       misho      47: {
1.1.1.2 ! misho      48:     uint32_t n, h;
1.1       misho      49:     libnet_pblock_t *p;
                     50:     struct libnet_rpc_call_tcp_hdr rpc_hdr;
                     51: 
                     52:     if (l == NULL)
                     53:     { 
                     54:         return (-1);
                     55:     } 
                     56: 
                     57:     /* Credential and Verifier buffers not yet implemented.
                     58:      * n = LIBNET_RPC_CALL_H + clength + vlength + payload_s;
                     59:      */
                     60: 
                     61:     if (rm)
                     62:     {
                     63:         n = LIBNET_RPC_CALL_TCP_H + payload_s;
                     64:     } 
                     65:     else
                     66:     {
                     67:         n = LIBNET_RPC_CALL_H + payload_s;
                     68:     }
                     69:  
                     70:     h = 0;
                     71: 
                     72:     /*
                     73:      *  Find the existing protocol block if a ptag is specified, or create
                     74:      *  a new one.
                     75:      */
                     76:     p = libnet_pblock_probe(l, ptag, n, LIBNET_PBLOCK_RPC_CALL_H);
                     77:     if (p == NULL)
                     78:     {
                     79:         return (-1);
                     80:     }
                     81: 
                     82:     memset(&rpc_hdr, 0, sizeof(rpc_hdr));
                     83:     if (rm)
                     84:     {
                     85:        rpc_hdr.rpc_record_marking                 = htonl(rm + payload_s);
                     86:     }
                     87:     rpc_hdr.rpc_common.rpc_xid                    = htonl(xid);
                     88:     rpc_hdr.rpc_common.rpc_type                   = LIBNET_RPC_CALL;
                     89:     rpc_hdr.rpc_common.rpc_call.rpc_rpcvers       = htonl(LIBNET_RPC_VERS);
                     90:     rpc_hdr.rpc_common.rpc_call.rpc_prognum       = htonl(prog_num);
                     91:     rpc_hdr.rpc_common.rpc_call.rpc_vers          = htonl(prog_vers);
                     92:     rpc_hdr.rpc_common.rpc_call.rpc_procedure     = htonl(procedure);
                     93:     /*  XXX Eventually should allow for opaque auth data. */
                     94:     rpc_hdr.rpc_common.rpc_call.rpc_credentials.rpc_auth_flavor= htonl(cflavor);
                     95:     rpc_hdr.rpc_common.rpc_call.rpc_credentials.rpc_auth_length= htonl(clength);
                     96:     rpc_hdr.rpc_common.rpc_call.rpc_verifier.rpc_auth_flavor   = htonl(vflavor);
                     97:     rpc_hdr.rpc_common.rpc_call.rpc_verifier.rpc_auth_length   = htonl(vlength);
                     98: 
                     99:     if (rm)
                    100:     {
1.1.1.2 ! misho     101:         n = libnet_pblock_append(l, p, (uint8_t *)&rpc_hdr, 
1.1       misho     102:                 LIBNET_RPC_CALL_TCP_H);
                    103:     }
                    104:     else
                    105:     {
1.1.1.2 ! misho     106:         n = libnet_pblock_append(l, p, (uint8_t *)&rpc_hdr.rpc_common, 
1.1       misho     107:                 LIBNET_RPC_CALL_H);
                    108:     }
                    109: 
                    110:     if (n == -1)
                    111:     {
                    112:         goto bad;
                    113:     }
                    114:  
1.1.1.2 ! misho     115:     /* boilerplate payload sanity check / append macro */
        !           116:     LIBNET_DO_PAYLOAD(l, p);
1.1       misho     117: 
                    118:     return (ptag ? ptag : libnet_pblock_update(l, p, h,
                    119:             LIBNET_PBLOCK_RPC_CALL_H));
                    120: bad:
                    121:     libnet_pblock_delete(l, p);
                    122:     return (-1);
                    123: }
                    124: 
                    125: /* EOF */

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