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

bpf.h

00001 /*-
00002  * Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
00003  *  The Regents of the University of California.  All rights reserved.
00004  *
00005  * This code is derived from the Stanford/CMU enet packet filter,
00006  * (net/enet.c) distributed as part of 4.3BSD, and code contributed
00007  * to Berkeley by Steven McCanne and Van Jacobson both of Lawrence 
00008  * Berkeley Laboratory.
00009  *
00010  * Redistribution and use in source and binary forms, with or without
00011  * modification, are permitted provided that the following conditions
00012  * are met:
00013  * 1. Redistributions of source code must retain the above copyright
00014  *    notice, this list of conditions and the following disclaimer.
00015  * 2. Redistributions in binary form must reproduce the above copyright
00016  *    notice, this list of conditions and the following disclaimer in the
00017  *    documentation and/or other materials provided with the distribution.
00018  * 3. All advertising materials mentioning features or use of this software
00019  *    must display the following acknowledgement:
00020  *      This product includes software developed by the University of
00021  *      California, Berkeley and its contributors.
00022  * 4. Neither the name of the University nor the names of its contributors
00023  *    may be used to endorse or promote products derived from this software
00024  *    without specific prior written permission.
00025  *
00026  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
00027  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00028  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00029  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
00030  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00031  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00032  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00033  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00034  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00035  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00036  * SUCH DAMAGE.
00037  *
00038  *      @(#)bpf.h       7.1 (Berkeley) 5/7/91
00039  *
00040  * @(#) $Header: /usr/local/www/users/anoncvs/cvs/embedaddon/libnet/doc/html/bpf_8h-source.html,v 1.1.1.1 2012/02/21 22:14:23 misho Exp $ (LBL)
00041  */
00042 
00043 #ifndef BPF_MAJOR_VERSION
00044 
00045 /* BSD style release date */
00046 #define BPF_RELEASE 199606
00047 
00048 typedef int bpf_int32;
00049 typedef u_int bpf_u_int32;
00050 
00051 /*
00052  * Alignment macros.  BPF_WORDALIGN rounds up to the next 
00053  * even multiple of BPF_ALIGNMENT. 
00054  */
00055 #define BPF_ALIGNMENT sizeof(bpf_int32)
00056 #define BPF_WORDALIGN(x) (((x)+(BPF_ALIGNMENT-1))&~(BPF_ALIGNMENT-1))
00057 
00058 #define BPF_MAXINSNS 512
00059 #define BPF_MAXBUFSIZE 0x8000
00060 #define BPF_MINBUFSIZE 32
00061 
00062 /*
00063  *  Structure for BIOCSETF.
00064  */
00065 struct bpf_program {
00066     u_int bf_len;
00067     struct bpf_insn *bf_insns;
00068 };
00069  
00070 /*
00071  * Struct returned by BIOCGSTATS.
00072  */
00073 struct bpf_stat {
00074     u_int bs_recv;      /* number of packets received */
00075     u_int bs_drop;      /* number of packets dropped */
00076 };
00077 
00078 /*
00079  * Struct return by BIOCVERSION.  This represents the version number of 
00080  * the filter language described by the instruction encodings below.
00081  * bpf understands a program iff kernel_major == filter_major &&
00082  * kernel_minor >= filter_minor, that is, if the value returned by the
00083  * running kernel has the same major number and a minor number equal
00084  * equal to or less than the filter being downloaded.  Otherwise, the
00085  * results are undefined, meaning an error may be returned or packets
00086  * may be accepted haphazardly.
00087  * It has nothing to do with the source code version.
00088  */
00089 struct bpf_version {
00090     u_short bv_major;
00091     u_short bv_minor;
00092 };
00093 /* Current version number of filter architecture. */
00094 #define BPF_MAJOR_VERSION 1
00095 #define BPF_MINOR_VERSION 1
00096 
00097 /*
00098  * BPF ioctls
00099  *
00100  * The first set is for compatibility with Sun's pcc style
00101  * header files.  If your using gcc, we assume that you
00102  * have run fixincludes so the latter set should work.
00103  */
00104 #if (defined(sun) || defined(ibm032)) && !defined(__GNUC__)
00105 #define BIOCGBLEN   _IOR(B,102, u_int)
00106 #define BIOCSBLEN   _IOWR(B,102, u_int)
00107 #define BIOCSETF    _IOW(B,103, struct bpf_program)
00108 #define BIOCFLUSH   _IO(B,104)
00109 #define BIOCPROMISC _IO(B,105)
00110 #define BIOCGDLT    _IOR(B,106, u_int)
00111 #define BIOCGETIF   _IOR(B,107, struct ifreq)
00112 #define BIOCSETIF   _IOW(B,108, struct ifreq)
00113 #define BIOCSRTIMEOUT   _IOW(B,109, struct timeval)
00114 #define BIOCGRTIMEOUT   _IOR(B,110, struct timeval)
00115 #define BIOCGSTATS  _IOR(B,111, struct bpf_stat)
00116 #define BIOCIMMEDIATE   _IOW(B,112, u_int)
00117 #define BIOCVERSION _IOR(B,113, struct bpf_version)
00118 #define BIOCSTCPF   _IOW(B,114, struct bpf_program)
00119 #define BIOCSUDPF   _IOW(B,115, struct bpf_program)
00120 #else
00121 #define BIOCGBLEN   _IOR('B',102, u_int)
00122 #define BIOCSBLEN   _IOWR('B',102, u_int)
00123 #define BIOCSETF    _IOW('B',103, struct bpf_program)
00124 #define BIOCFLUSH   _IO('B',104)
00125 #define BIOCPROMISC _IO('B',105)
00126 #define BIOCGDLT    _IOR('B',106, u_int)
00127 #define BIOCGETIF   _IOR('B',107, struct ifreq)
00128 #define BIOCSETIF   _IOW('B',108, struct ifreq)
00129 #define BIOCSRTIMEOUT   _IOW('B',109, struct timeval)
00130 #define BIOCGRTIMEOUT   _IOR('B',110, struct timeval)
00131 #define BIOCGSTATS  _IOR('B',111, struct bpf_stat)
00132 #define BIOCIMMEDIATE   _IOW('B',112, u_int)
00133 #define BIOCVERSION _IOR('B',113, struct bpf_version)
00134 #define BIOCSTCPF   _IOW('B',114, struct bpf_program)
00135 #define BIOCSUDPF   _IOW('B',115, struct bpf_program)
00136 #endif
00137 
00138 /*
00139  * Structure prepended to each packet.
00140  */
00141 struct bpf_hdr {
00142     struct timeval  bh_tstamp;  /* time stamp */
00143     bpf_u_int32 bh_caplen;  /* length of captured portion */
00144     bpf_u_int32 bh_datalen; /* original length of packet */
00145     u_short     bh_hdrlen;  /* length of bpf header (this struct
00146                        plus alignment padding) */
00147 };
00148 /*
00149  * Because the structure above is not a multiple of 4 bytes, some compilers
00150  * will insist on inserting padding; hence, sizeof(struct bpf_hdr) won't work.
00151  * Only the kernel needs to know about it; applications use bh_hdrlen.
00152  */
00153 #ifdef KERNEL
00154 #define SIZEOF_BPF_HDR 18
00155 #endif
00156 
00157 /*
00158  * Data-link level type codes.
00159  */
00160 #define DLT_NULL    0   /* no link-layer encapsulation */
00161 #define DLT_EN10MB  1   /* Ethernet (10Mb) */
00162 #define DLT_EN3MB   2   /* Experimental Ethernet (3Mb) */
00163 #define DLT_AX25    3   /* Amateur Radio AX.25 */
00164 #define DLT_PRONET  4   /* Proteon ProNET Token Ring */
00165 #define DLT_CHAOS   5   /* Chaos */
00166 #define DLT_IEEE802 6   /* IEEE 802 Networks */
00167 #define DLT_ARCNET  7   /* ARCNET */
00168 #define DLT_SLIP    8   /* Serial Line IP */
00169 #define DLT_PPP     9   /* Point-to-point Protocol */
00170 #define DLT_FDDI    10  /* FDDI */
00171 #define DLT_ATM_RFC1483 11  /* LLC/SNAP encapsulated atm */
00172 #define DLT_RAW     12  /* raw IP */
00173 #define DLT_SLIP_BSDOS  13  /* BSD/OS Serial Line IP */
00174 #define DLT_PPP_BSDOS   14  /* BSD/OS Point-to-point Protocol */
00175 
00176 /*
00177  * The instruction encondings.
00178  */
00179 /* instruction classes */
00180 #define BPF_CLASS(code) ((code) & 0x07)
00181 #define     BPF_LD      0x00
00182 #define     BPF_LDX     0x01
00183 #define     BPF_ST      0x02
00184 #define     BPF_STX     0x03
00185 #define     BPF_ALU     0x04
00186 #define     BPF_JMP     0x05
00187 #define     BPF_RET     0x06
00188 #define     BPF_MISC    0x07
00189 
00190 /* ld/ldx fields */
00191 #define BPF_SIZE(code)  ((code) & 0x18)
00192 #define     BPF_W       0x00
00193 #define     BPF_H       0x08
00194 #define     BPF_B       0x10
00195 #define BPF_MODE(code)  ((code) & 0xe0)
00196 #define     BPF_IMM     0x00
00197 #define     BPF_ABS     0x20
00198 #define     BPF_IND     0x40
00199 #define     BPF_MEM     0x60
00200 #define     BPF_LEN     0x80
00201 #define     BPF_MSH     0xa0
00202 
00203 /* alu/jmp fields */
00204 #define BPF_OP(code)    ((code) & 0xf0)
00205 #define     BPF_ADD     0x00
00206 #define     BPF_SUB     0x10
00207 #define     BPF_MUL     0x20
00208 #define     BPF_DIV     0x30
00209 #define     BPF_OR      0x40
00210 #define     BPF_AND     0x50
00211 #define     BPF_LSH     0x60
00212 #define     BPF_RSH     0x70
00213 #define     BPF_NEG     0x80
00214 #define     BPF_JA      0x00
00215 #define     BPF_JEQ     0x10
00216 #define     BPF_JGT     0x20
00217 #define     BPF_JGE     0x30
00218 #define     BPF_JSET    0x40
00219 #define BPF_SRC(code)   ((code) & 0x08)
00220 #define     BPF_K       0x00
00221 #define     BPF_X       0x08
00222 
00223 /* ret - BPF_K and BPF_X also apply */
00224 #define BPF_RVAL(code)  ((code) & 0x18)
00225 #define     BPF_A       0x10
00226 
00227 /* misc */
00228 #define BPF_MISCOP(code) ((code) & 0xf8)
00229 #define     BPF_TAX     0x00
00230 #define     BPF_TXA     0x80
00231 
00232 /*
00233  * The instruction data structure.
00234  */
00235 struct bpf_insn {
00236     u_short code;
00237     u_char  jt;
00238     u_char  jf;
00239     bpf_int32 k;
00240 };
00241 
00242 /*
00243  * Macros for insn array initializers.
00244  */
00245 #define BPF_STMT(code, k) { (u_short)(code), 0, 0, k }
00246 #define BPF_JUMP(code, k, jt, jf) { (u_short)(code), jt, jf, k }
00247 
00248 #ifdef KERNEL
00249 extern u_int bpf_filter();
00250 extern void bpfattach();
00251 extern void bpf_tap();
00252 extern void bpf_mtap();
00253 #else
00254 #if __STDC__
00255 extern u_int bpf_filter(struct bpf_insn *, u_char *, u_int, u_int);
00256 #endif
00257 #endif
00258 
00259 /*
00260  * Number of scratch memory words (for BPF_LD|BPF_MEM and BPF_ST).
00261  */
00262 #define BPF_MEMWORDS 16
00263 
00264 #endif

Generated on Wed Mar 10 13:23:37 2004 for libnet by doxygen 1.3.4