Main Page | Data Structures | File List | Data Fields | Globals

# libnet-macros.h

Go to the documentation of this file.

    00001 /*
    00002  *  $Id: libnet-macros.h,v 1.6 2004/03/01 20:26:12 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 checksum stuff */
    00134 #define LIBNET_CKSUM_CARRY(x) \
    00135     (x = (x >> 16) + (x & 0xffff), (~(x + (x >> 16)) & 0xffff))
    00136
    00137 /* used interally for OSPF stuff */
    00138 #define LIBNET_OSPF_AUTHCPY(x, y) \
    00139     memcpy((u_int8_t *)x, (u_int8_t *)y, sizeof(y))
    00140 #define LIBNET_OSPF_CKSUMBUF(x, y) \
    00141     memcpy((u_int8_t *)x, (u_int8_t *)y, sizeof(y))
    00142
    00143 /* used internally for NTP leap indicator, version, and mode */
    00144 #define LIBNET_NTP_DO_LI_VN_MODE(li, vn, md) \
    00145     ((u_int8_t)((((li) << 6) & 0xc0) | (((vn) << 3) & 0x38) | ((md) & 0x7)))
    00146
    00147 /* Not all systems have IFF_LOOPBACK */
    00148 #ifdef IFF_LOOPBACK
    00149 #define LIBNET_ISLOOPBACK(p) ((p)->ifr_flags & IFF_LOOPBACK)
    00150 #else
    00151 #define LIBNET_ISLOOPBACK(p) (strcmp((p)->ifr_name, "lo0") == 0)
    00152 #endif
    00153
    00154 /* advanced mode check */
    00155 #define LIBNET_ISADVMODE(x) (x & 0x08)
    00156
    00157 /* context queue macros and constants */
    00158 #define LIBNET_LABEL_SIZE   64
    00159 #define LIBNET_LABEL_DEFAULT "cardshark"
    00160 #define CQ_LOCK_UNLOCKED    (u_int)0x00000000
    00161 #define CQ_LOCK_READ        (u_int)0x00000001
    00162 #define CQ_LOCK_WRITE       (u_int)0x00000002
    00163
    00169 #define for_each_context_in_cq(l) \
    00170     for (l = libnet_cq_head(); libnet_cq_last(); l = libnet_cq_next())
    00171
    00172 /* return 1 if write lock is set on cq */
    00173 #define cq_is_wlocked() (l_cqd.cq_lock & CQ_LOCK_WRITE)
    00174
    00175 /* return 1 if read lock is set on cq */
    00176 #define cq_is_rlocked() (l_cqd.cq_lock & CQ_LOCK_READ)
    00177
    00178 /* return 1 if any lock is set on cq */
    00179 #define cq_is_locked() (l_cqd.cq_lock & (CQ_LOCK_READ | CQ_LOCK_WRITE))
    00180
    00181 /* check if a context queue is locked */
    00182 #define check_cq_lock(x) (l_cqd.cq_lock & x)
    00183
    00184 #endif  /* __LIBNET_MACROS_H */
    00185
    00186 /* EOF */