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