Main Page | File List | Globals

libnet-macros.h

00001 /*
00002  *  $Id: libnet-macros.h,v 1.2 2003/09/23 22:36:54 mike Exp $
00003  *
00004  *  libnet-macros.h - Network routine library macro header file
00005  *
00006  *  Copyright (c) 1998 - 2002 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 
00035 /* for systems without snprintf */
00036 #if defined(NO_SNPRINTF)
00037 #define snprintf(buf, len, args...) sprintf(buf, ##args)
00038 #endif
00039 
00040 
00041 /* for name/address resolutions functions */
00042 #define LIBNET_DONT_RESOLVE 0
00043 #define LIBNET_RESOLVE      1
00044 
00045 /* for libnet_toggle_checksum */
00046 #define LIBNET_ON   0
00047 #define LIBNET_OFF  1
00048 
00049 /* IPv6 error code */
00050 #ifndef IN6ADDR_ERROR_INIT
00051 #define IN6ADDR_ERROR_INIT { { { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, \
00052                                  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, \
00053                                  0xff, 0xff } } }
00054 #endif
00055 
00056 /* prand constants */
00057 #define LIBNET_PR2          0
00058 #define LIBNET_PR8          1
00059 #define LIBNET_PR16         2
00060 #define LIBNET_PRu16        3
00061 #define LIBNET_PR32         4
00062 #define LIBNET_PRu32        5
00063 #define LIBNET_PRAND_MAX    0xffffffff
00064 
00065 #define LIBNET_MAX_PACKET   0xffff          /* as big as we can get */
00066 #ifndef IP_MAXPACKET
00067 #define IP_MAXPACKET        0xffff
00068 #endif
00069 #ifndef ETHER_ADDR_LEN
00070 #define ETHER_ADDR_LEN      0x6
00071 #endif
00072 
00073 #define FDDI_ADDR_LEN       0x6
00074 #define TOKEN_RING_ADDR_LEN 0x6
00075 
00076 /* For LLC Organization Code. */
00077 #define LIBNET_ORG_CODE_SIZE  0x3
00078 
00079 #define LIBNET_ERRBUF_SIZE      0x100
00080 #define LIBNET_MAXOPTION_SIZE   0x28
00081 
00082 /* some BSD variants have this endianess problem */
00083 #if (LIBNET_BSD_BYTE_SWAP)
00084 #define FIX(n)      ntohs(n)
00085 #define UNFIX(n)    htons(n)
00086 #else
00087 #define FIX(n)      (n)
00088 #define UNFIX(n)    (n)
00089 #endif
00090 
00091 /* checksum stuff */
00092 #define LIBNET_CKSUM_CARRY(x) \
00093     (x = (x >> 16) + (x & 0xffff), (~(x + (x >> 16)) & 0xffff))
00094 
00095 /* OSPF stuff */
00096 #define LIBNET_OSPF_AUTHCPY(x, y)  memcpy((u_int8_t *)x, (u_int8_t *)y, sizeof(y))
00097 #define LIBNET_OSPF_CKSUMBUF(x, y) memcpy((u_int8_t *)x, (u_int8_t *)y, sizeof(y))  
00098 
00099 /* NTP leap indicator, version, and mode */
00100 #define LIBNET_NTP_DO_LI_VN_MODE(li, vn, md) \
00101         ((u_int8_t)((((li) << 6) & 0xc0) | (((vn) << 3) & 0x38) | ((md) & 0x7)))
00102 
00103 /* not all systems have IFF_LOOPBACK */
00104 #ifdef IFF_LOOPBACK
00105 #define LIBNET_ISLOOPBACK(p) ((p)->ifr_flags & IFF_LOOPBACK)
00106 #else
00107 #define LIBNET_ISLOOPBACK(p) (strcmp((p)->ifr_name, "lo0") == 0)
00108 #endif
00109 
00110 /* advanced mode check */
00111 #define LIBNET_ISADVMODE(x) (x & 0x08)
00112 
00113 /* context queue macros and constants */
00114 #define LIBNET_LABEL_SIZE   64
00115 #define LIBNET_LABEL_DEFAULT "cardshark"
00116 #define CQ_LOCK_UNLOCKED    (u_int)0x00000000
00117 #define CQ_LOCK_READ        (u_int)0x00000001
00118 #define CQ_LOCK_WRITE       (u_int)0x00000002
00119 
00120 /* cq loop */
00121 #define for_each_context_in_cq(l) \
00122     for (l = libnet_cq_head(); libnet_cq_last(); l = libnet_cq_next())
00123 
00124 /* return 1 if write lock is set on cq */
00125 #define cq_is_wlocked() (l_cqd.cq_lock & CQ_LOCK_WRITE)
00126 
00127 /* return 1 if read lock is set on cq */
00128 #define cq_is_rlocked() (l_cqd.cq_lock & CQ_LOCK_READ)
00129 
00130 /* return 1 if any lock is set on cq */
00131 #define cq_is_locked() (l_cqd.cq_lock & (CQ_LOCK_READ | CQ_LOCK_WRITE))
00132 
00133 #define check_cq_lock(x) (l_cqd.cq_lock & x)
00134 
00135 #endif  /* __LIBNET_MACROS_H */
00136 
00137 /* EOF */

Generated on Wed Nov 12 09:57:54 2003 for libnet by doxygen 1.3.2