Main Page | Modules | Class List | Directories | File List | Class Members | File Members | Related Pages

libnet-macros.h

Go to the documentation of this file.
00001 /*
00002  *  $Id$
00003  *
00004  *  libnet-macros.h - Network routine library macro header file
00005  *
00006  *  Copyright (c) 1998, 1999, 2000 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 /*
00036  *  for libnet_hostlookup
00037  */
00038 #define LIBNET_DONT_RESOLVE 0
00039 #define LIBNET_RESOLVE      1
00040 
00041 /*
00042  *  prand constants
00043  */
00044 #define LIBNET_PR2          0
00045 #define LIBNET_PR8          1
00046 #define LIBNET_PR16         2
00047 #define LIBNET_PRu16        3
00048 #define LIBNET_PR32         4
00049 #define LIBNET_PRu32        5
00050 #define LIBNET_PRAND_MAX    0xffffffff
00051 
00052 /*
00053  *  Concession to legacy naming scheme
00054  */
00055 #define PR2         LIBNET_PR2
00056 #define PR8         LIBNET_PR8
00057 #define PR16        LIBNET_PR16
00058 #define PRu16       LIBNET_PRu16
00059 #define PR32        LIBNET_PR32
00060 #define PRu32       LIBNET_PRu32
00061 #define PRAND_MAX   LIBNET_PRAND_MAX
00062 
00063 /*
00064  *  Misc packet sizes for malloc
00065  */
00066 #define LIBNET_PACKET       LIBNET_IP_H + LIBNET_TCP_H  /* IP, UDP or TCP */
00067 #define LIBNET_OPTS         0x34            /* options! options! options! */
00068 #define LIBNET_MAX_PACKET   0xffff          /* as big as we can get */
00069 
00070 
00071 /*
00072  *  Error handling constants.
00073  */
00074 #define LIBNET_ERR_WARNING  1
00075 #define LIBNET_ERR_CRITICAL 2
00076 #define LIBNET_ERR_FATAL    3
00077 
00078 /*
00079  *  Concession to legacy naming scheme
00080  */
00081 #define LN_ERR_WARNING  LIBNET_ERR_WARNING
00082 #define LN_ERR_CRITICAL LIBNET_ERR_CRITICAL
00083 #define LN_ERR_FATAL    LIBNET_ERR_FATAL
00084 
00085 
00086 #define LIBNET_ERRBUF_SIZE  256
00087 
00088 
00089 /*
00090  *  Some BSD variants have this endianess problem.
00091  */
00092 #if (LIBNET_BSD_BYTE_SWAP)
00093 #define FIX(n)      ntohs(n)
00094 #define UNFIX(n)    htons(n)
00095 #else
00096 #define FIX(n)      (n)
00097 #define UNFIX(n)    (n)
00098 #endif
00099 
00100 /*
00101  *  Arena stuff
00102  */
00103 #define LIBNET_GET_ARENA_SIZE(a)               (a.size)
00104 #define LIBNET_GET_ARENA_REMAINING_BYTES(a)    (a.size - a.current)
00105 
00106 
00107 /*
00108  *  Checksum stuff
00109  */
00110 #define LIBNET_CKSUM_CARRY(x) \
00111     (x = (x >> 16) + (x & 0xffff), (~(x + (x >> 16)) & 0xffff))
00112 
00113 
00114 /*
00115  *  OSPF stuff
00116  */
00117 #define LIBNET_OSPF_AUTHCPY(x,y)  memcpy((u_char *)x, (u_char *)y, sizeof(y))
00118 #define LIBNET_OSPF_CKSUMBUF(x,y) memcpy((u_char *)x, (u_char *)y, sizeof(y))  
00119 
00120 /*
00121  *  Not all systems have IFF_LOOPBACK
00122  *  Used by if_addr.c
00123  */
00124 #ifdef IFF_LOOPBACK
00125 #define LIBNET_ISLOOPBACK(p) ((p)->ifr_flags & IFF_LOOPBACK)
00126 #else
00127 #define LIBNET_ISLOOPBACK(p) (strcmp((p)->ifr_name, "lo0") == 0)
00128 #endif
00129 
00130 #define LIBNET_PRINT_ETH_ADDR(e) \
00131 { \
00132     int i = 0; \
00133     for (i = 0; i < 6; i++) \
00134     { \
00135         printf("%x", e.ether_addr_octet[i]); \
00136         if (i != 5) \
00137         { \
00138             printf(":"); \
00139         } \
00140     } \
00141     printf("\n"); \
00142 }
00143 
00144 #endif  /* __LIBNET_MACROS_H */
00145 
00146 /* EOF */

Generated on Sun May 14 14:51:19 2006 by  doxygen 1.4.2