libnet: libnet-macros.h Source File

libnet 1.1

- Main Page
- Files

- File List
- Globals

libnet-macros.h
Go to the documentation of this file.

    00001 /*
    00002  *  $Id: libnet-macros.h,v 1.7 2004/04/13 17:32:28 mike Exp $
    00003  *
    00004  *  libnet-macros.h - Network routine library macro header file
    00005  *
    00006  *  Copyright (c) 1998 - 2004 Mike D. Schiffman <mike@infonexus.com>
    00007  *  All rights reserved.
    00008  *
    00009  * Redistribution and use in source and binary forms, with or without
    00010  * modification, are permitted provided that the following conditions
    00011  * are met:
    00012  * 1. Redistributions of source code must retain the above copyright
    00013  *    notice, this list of conditions and the following disclaimer.
    00014  * 2. Redistributions in binary form must reproduce the above copyright
    00015  *    notice, this list of conditions and the following disclaimer in the
    00016  *    documentation and/or other materials provided with the distribution.
    00017  *
    00018  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
    00019  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    00020  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    00021  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
    00022  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
    00023  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
    00024  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
    00025  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
    00026  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
    00027  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
    00028  * SUCH DAMAGE.
    00029  *
    00030  */
    00031
    00032 #ifndef __LIBNET_MACROS_H
    00033 #define __LIBNET_MACROS_H
    00034
    00039 /* for systems without snprintf */
    00040 #if defined(NO_SNPRINTF)
    00041 #define snprintf(buf, len, args...) sprintf(buf, ##args)
    00042 #endif
    00043
    00044
    00049 #define LIBNET_DONT_RESOLVE 0
    00050
    00055 #define LIBNET_RESOLVE      1
    00056
    00060 #define LIBNET_ON   0
    00061
    00065 #define LIBNET_OFF  1
    00066
    00070 #ifndef IN6ADDR_ERROR_INIT
    00071 #define IN6ADDR_ERROR_INIT { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, \
    00072                                  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, \
    00073                                  0xff, 0xff } } }
    00074 #endif
    00075
    00079 #define LIBNET_PR2          0
    00080 #define LIBNET_PR8          1
    00081 #define LIBNET_PR16         2
    00082 #define LIBNET_PRu16        3
    00083 #define LIBNET_PR32         4
    00084 #define LIBNET_PRu32        5
    00085 #define LIBNET_PRAND_MAX    0xffffffff
    00086
    00090 #define LIBNET_MAX_PACKET   0xffff
    00091 #ifndef IP_MAXPACKET
    00092 #define IP_MAXPACKET        0xffff
    00093 #endif
    00094
    00095
    00096 /* ethernet addresses are 6 octets long */
    00097 #ifndef ETHER_ADDR_LEN
    00098 #define ETHER_ADDR_LEN      0x6
    00099 #endif
    00100
    00101 /* FDDI addresses are 6 octets long */
    00102 #ifndef FDDI_ADDR_LEN
    00103 #define FDDI_ADDR_LEN       0x6
    00104 #endif
    00105
    00106 /* token ring addresses are 6 octets long */
    00107 #ifndef TOKEN_RING_ADDR_LEN
    00108 #define TOKEN_RING_ADDR_LEN 0x6
    00109 #endif
    00110
    00111 /* LLC Organization Code is 3 bytes long */
    00112 #define LIBNET_ORG_CODE_SIZE  0x3
    00113
    00117 #define LIBNET_ERRBUF_SIZE      0x100
    00118
    00122 #define LIBNET_MAXOPTION_SIZE   0x28
    00123
    00124 /* some BSD variants have this endianess problem */
    00125 #if (LIBNET_BSD_BYTE_SWAP)
    00126 #define FIX(n)      ntohs(n)
    00127 #define UNFIX(n)    htons(n)
    00128 #else
    00129 #define FIX(n)      (n)
    00130 #define UNFIX(n)    (n)
    00131 #endif
    00132
    00133 /* used internally for packet builders */
    00134 #define LIBNET_DO_PAYLOAD(l, p)                                              \
    00135 if (payload_s && !payload)                                                   \
    00136 {                                                                            \
    00137     snprintf(l->err_buf, LIBNET_ERRBUF_SIZE,                                 \
    00138             "%s(): payload inconsistency\n", __func__);                      \
    00139     goto bad;                                                                \
    00140 }                                                                            \
    00141 if (payload_s)                                                               \
    00142 {                                                                            \
    00143     n = libnet_pblock_append(l, p, payload, payload_s);                      \
    00144     if (n == (uint32_t) - 1)                                                 \
    00145     {                                                                        \
    00146         goto bad;                                                            \
    00147     }                                                                        \
    00148 }                                                                            \
    00149
    00150
    00151 /* used internally for checksum stuff */
    00152 #define LIBNET_CKSUM_CARRY(x) \
    00153     (x = (x >> 16) + (x & 0xffff), (~(x + (x >> 16)) & 0xffff))
    00154
    00155 /* used interally for OSPF stuff */
    00156 #define LIBNET_OSPF_AUTHCPY(x, y) \
    00157     memcpy((uint8_t *)x, (uint8_t *)y, sizeof(y))
    00158 #define LIBNET_OSPF_CKSUMBUF(x, y) \
    00159     memcpy((uint8_t *)x, (uint8_t *)y, sizeof(y))
    00160
    00161 /* used internally for NTP leap indicator, version, and mode */
    00162 #define LIBNET_NTP_DO_LI_VN_MODE(li, vn, md) \
    00163     ((uint8_t)((((li) << 6) & 0xc0) | (((vn) << 3) & 0x38) | ((md) & 0x7)))
    00164
    00165 /* Not all systems have IFF_LOOPBACK */
    00166 #ifdef IFF_LOOPBACK
    00167 #define LIBNET_ISLOOPBACK(p) ((p)->ifr_flags & IFF_LOOPBACK)
    00168 #else
    00169 #define LIBNET_ISLOOPBACK(p) (strcmp((p)->ifr_name, "lo") == 0)
    00170 #endif
    00171
    00172 /* advanced mode check */
    00173 #define LIBNET_ISADVMODE(x) (x & 0x08)
    00174
    00175 /* context queue macros and constants */
    00176 #define LIBNET_LABEL_SIZE   64
    00177 #define LIBNET_LABEL_DEFAULT "cardshark"
    00178 #define CQ_LOCK_UNLOCKED    (u_int)0x00000000
    00179 #define CQ_LOCK_READ        (u_int)0x00000001
    00180 #define CQ_LOCK_WRITE       (u_int)0x00000002
    00181
    00187 #define for_each_context_in_cq(l) \
    00188     for (l = libnet_cq_head(); libnet_cq_last(); l = libnet_cq_next())
    00189
    00190 /* return 1 if write lock is set on cq */
    00191 #define cq_is_wlocked() (l_cqd.cq_lock & CQ_LOCK_WRITE)
    00192
    00193 /* return 1 if read lock is set on cq */
    00194 #define cq_is_rlocked() (l_cqd.cq_lock & CQ_LOCK_READ)
    00195
    00196 /* return 1 if any lock is set on cq */
    00197 #define cq_is_locked() (l_cqd.cq_lock & (CQ_LOCK_READ | CQ_LOCK_WRITE))
    00198
    00199 /* check if a context queue is locked */
    00200 #define check_cq_lock(x) (l_cqd.cq_lock & x)
    00201
    00202 #endif  /* __LIBNET_MACROS_H */
    00203
    00204 /* EOF */