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

1.1       misho       1: /*
                      2:  *  libnet
                      3:  *  libnet_build_hsrp.c - HSRP packet assembler
                      4:  *
                      5:  *  Copyright (c) 2004 David Barroso Berrueta <tomac@wasahero.org>
                      6:  *  Copyright (c) 1998 - 2004 Mike D. Schiffman <mike@infonexus.com>
                      7:  *  All rights reserved.
                      8:  *
                      9:  * Redistribution and use in source and binary forms, with or without
                     10:  * modification, are permitted provided that the following conditions
                     11:  * are met:
                     12:  * 1. Redistributions of source code must retain the above copyright
                     13:  *    notice, this list of conditions and the following disclaimer.
                     14:  * 2. Redistributions in binary form must reproduce the above copyright
                     15:  *    notice, this list of conditions and the following disclaimer in the
                     16:  *    documentation and/or other materials provided with the distribution.
                     17:  *
                     18:  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
                     19:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     20:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     21:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
                     22:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     23:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     24:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     25:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     26:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     27:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     28:  * SUCH DAMAGE.
                     29:  *
                     30:  */
                     31: 
1.1.1.2 ! misho      32: #include "common.h"
1.1       misho      33: 
                     34: libnet_ptag_t
                     35: libnet_build_hsrp(uint8_t version, uint8_t opcode, uint8_t state, 
                     36: uint8_t hello_time, uint8_t hold_time, uint8_t priority, uint8_t group,
                     37: uint8_t reserved, uint8_t authdata[HSRP_AUTHDATA_LENGTH], uint32_t virtual_ip,
                     38: const uint8_t *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag)
                     39: {
                     40:     uint32_t n;
                     41:     libnet_pblock_t *p;
                     42:     struct libnet_hsrp_hdr hsrp_hdr;
                     43: 
                     44:     if (l == NULL)
                     45:     { 
                     46:         return (-1);
                     47:     } 
                     48: 
                     49:     /*
                     50:      *  Find the existing protocol block if a ptag is specified, or create
                     51:      *  a new one.
                     52:      */
                     53:     p = libnet_pblock_probe(l, ptag, LIBNET_HSRP_H + payload_s, LIBNET_PBLOCK_HSRP_H);
                     54:     if (p == NULL)
                     55:     {
                     56:         return (-1);
                     57:     }
                     58: 
                     59:     memset(&hsrp_hdr, 0, sizeof(hsrp_hdr));
                     60:     hsrp_hdr.version = version;
                     61:     hsrp_hdr.opcode = opcode;
                     62:     hsrp_hdr.state = state;
                     63:     hsrp_hdr.hello_time = hello_time;
                     64:     hsrp_hdr.hold_time = hold_time;
                     65:     hsrp_hdr.priority = priority;
                     66:     hsrp_hdr.group = group;
                     67:     hsrp_hdr.reserved = reserved;
                     68:     memcpy(hsrp_hdr.authdata, authdata, HSRP_AUTHDATA_LENGTH*sizeof(uint8_t));
                     69:     hsrp_hdr.virtual_ip = virtual_ip;
                     70: 
                     71:     n = libnet_pblock_append(l, p, (uint8_t *)&hsrp_hdr, LIBNET_HSRP_H);
                     72:     if (n == -1)
                     73:     {
                     74:         goto bad;
                     75:     }
                     76: 
                     77:     if (payload_s && !payload)
                     78:     {
                     79:         snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,
1.1.1.2 ! misho      80:                 "%s(): payload inconsistency", __func__);
1.1       misho      81:         goto bad;
                     82:     }
                     83:  
                     84:     if (payload_s)
                     85:     {
                     86:         n = libnet_pblock_append(l, p, payload, payload_s);
                     87:         if (n == -1)
                     88:         {
                     89:             goto bad;
                     90:         }
                     91:     }
                     92:  
                     93:     return (ptag ? ptag : libnet_pblock_update(l, p, 0, LIBNET_PBLOCK_HSRP_H));
                     94: bad:
                     95:     libnet_pblock_delete(l, p);
                     96:     return (-1);
                     97: }
1.1.1.2 ! misho      98: 
        !            99: /**
        !           100:  * Local Variables:
        !           101:  *  indent-tabs-mode: nil
        !           102:  *  c-file-style: "stroustrup"
        !           103:  * End:
        !           104:  */

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