home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / amiga / os / bsdss4.tz / bsdss4 / bsdss / server / net / bpf.h < prev    next >
Encoding:
C/C++ Source or Header  |  1992-04-22  |  7.8 KB  |  254 lines

  1. /* 
  2.  * Mach Operating System
  3.  * Copyright (c) 1992 Carnegie Mellon University
  4.  * All Rights Reserved.
  5.  * 
  6.  * Permission to use, copy, modify and distribute this software and its
  7.  * documentation is hereby granted, provided that both the copyright
  8.  * notice and this permission notice appear in all copies of the
  9.  * software, derivative works or modified versions, and any portions
  10.  * thereof, and that both notices appear in supporting documentation.
  11.  * 
  12.  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
  13.  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
  14.  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
  15.  * 
  16.  * Carnegie Mellon requests users of this software to return to
  17.  * 
  18.  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
  19.  *  School of Computer Science
  20.  *  Carnegie Mellon University
  21.  *  Pittsburgh PA 15213-3890
  22.  * 
  23.  * any improvements or extensions that they make and grant Carnegie Mellon 
  24.  * the rights to redistribute these changes.
  25.  */
  26. /*
  27.  * HISTORY
  28.  * $Log:    bpf.h,v $
  29.  * Revision 2.1  92/04/21  17:14:06  rwd
  30.  * BSDSS
  31.  * 
  32.  *
  33.  */
  34.  
  35. /*-
  36.  * Copyright (c) 1990 The Regents of the University of California.
  37.  * All rights reserved.
  38.  *
  39.  * This code is derived from the Stanford/CMU enet packet filter,
  40.  * (net/enet.c) distributed as part of 4.3BSD, and code contributed
  41.  * to Berkeley by Steven McCanne of Lawrence Berkeley Laboratory.
  42.  *
  43.  * Redistribution and use in source and binary forms, with or without
  44.  * modification, are permitted provided that the following conditions
  45.  * are met:
  46.  * 1. Redistributions of source code must retain the above copyright
  47.  *    notice, this list of conditions and the following disclaimer.
  48.  * 2. Redistributions in binary form must reproduce the above copyright
  49.  *    notice, this list of conditions and the following disclaimer in the
  50.  *    documentation and/or other materials provided with the distribution.
  51.  * 3. All advertising materials mentioning features or use of this software
  52.  *    must display the following acknowledgement:
  53.  *    This product includes software developed by the University of
  54.  *    California, Berkeley and its contributors.
  55.  * 4. Neither the name of the University nor the names of its contributors
  56.  *    may be used to endorse or promote products derived from this software
  57.  *    without specific prior written permission.
  58.  *
  59.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  60.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  61.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  62.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  63.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  64.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  65.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  66.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  67.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  68.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  69.  * SUCH DAMAGE.
  70.  *
  71.  *    @(#)bpf.h    7.1 (Berkeley) 5/7/91
  72.  *
  73.  * @(#) $Header: /afs/cs.cmu.edu/project/mach/mach3/rcs/bsdss/server/net/bpf.h,v 2.1 92/04/21 17:14:06 rwd Exp $ (LBL)
  74.  */
  75.  
  76. /*
  77.  * Alignment macros.  BPF_WORDALIGN rounds up to the next 
  78.  * even multiple of BPF_ALIGNMENT. 
  79.  */
  80. #define BPF_ALIGNMENT sizeof(long)
  81. #define BPF_WORDALIGN(x) (((x)+(BPF_ALIGNMENT-1))&~(BPF_ALIGNMENT-1))
  82.  
  83. #define BPF_MAXINSNS 512
  84. #define BPF_MAXBUFSIZE 0x8000
  85.  
  86. /*
  87.  *  Structure for BIOCSETF.
  88.  */
  89. struct bpf_program {
  90.     u_int bf_len;
  91.     struct bpf_insn *bf_insns;
  92. };
  93.  
  94. /*
  95.  * Struct returned by BIOCGSTATS.
  96.  */
  97. struct bpf_stat {
  98.     u_int bs_recv;        /* number of packets received */
  99.     u_int bs_drop;        /* number of packets dropped */
  100. };
  101.  
  102. /*
  103.  * BPF ioctls
  104.  *
  105.  * The first set is for compatibility with Sun's pcc style
  106.  * header files.  If your using gcc, we assume that you
  107.  * have run fixincludes so the latter set should work.
  108.  */
  109. #if defined(sun) && !defined(__GNUC__)
  110. #define    BIOCGFLEN    _IOR(B,101, u_int)
  111. #define    BIOCGBLEN    _IOR(B,102, u_int)
  112. #define    BIOCSETF    _IOW(B,103, struct bpf_program)
  113. #define    BIOCFLUSH    _IO(B,104)
  114. #define BIOCPROMISC    _IO(B,105)
  115. #define    BIOCGDLT    _IOR(B,106, u_int)
  116. #define BIOCGETIF    _IOR(B,107, struct ifreq)
  117. #define BIOCSETIF    _IOW(B,108, struct ifreq)
  118. #define BIOCSRTIMEOUT    _IOW(B,109, struct timeval)
  119. #define BIOCGRTIMEOUT    _IOR(B,110, struct timeval)
  120. #define BIOCGSTATS    _IOR(B,111, struct bpf_stat)
  121. #define BIOCIMMEDIATE    _IOW(B,112, u_int)
  122. #else
  123. #define    BIOCGFLEN    _IOR('B',101, u_int)
  124. #define    BIOCGBLEN    _IOR('B',102, u_int)
  125. #define    BIOCSETF    _IOW('B',103, struct bpf_program)
  126. #define    BIOCFLUSH    _IO('B',104)
  127. #define BIOCPROMISC    _IO('B',105)
  128. #define    BIOCGDLT    _IOR('B',106, u_int)
  129. #define BIOCGETIF    _IOR('B',107, struct ifreq)
  130. #define BIOCSETIF    _IOW('B',108, struct ifreq)
  131. #define BIOCSRTIMEOUT    _IOW('B',109, struct timeval)
  132. #define BIOCGRTIMEOUT    _IOR('B',110, struct timeval)
  133. #define BIOCGSTATS    _IOR('B',111, struct bpf_stat)
  134. #define BIOCIMMEDIATE    _IOW('B',112, u_int)
  135. #endif
  136.  
  137. /*
  138.  * Structure prepended to each packet.
  139.  */
  140. struct bpf_hdr {
  141.     struct timeval    bh_tstamp;    /* time stamp */
  142.     u_long        bh_caplen;    /* length of captured portion */
  143.     u_long        bh_datalen;    /* original length of packet */
  144.     u_short        bh_hdrlen;    /* length of bpf header (this struct
  145.                        plus alignment padding) */
  146. };
  147. /*
  148.  * Because the structure above is not a multiple of 4 bytes, some compilers
  149.  * will insist on inserting padding; hence, sizeof(struct bpf_hdr) won't work.
  150.  * Only the kernel needs to know about it; applications use bh_hdrlen.
  151.  */
  152. #ifdef KERNEL
  153. #define SIZEOF_BPF_HDR 18
  154. #endif
  155.  
  156. /*
  157.  * Data-link level type codes.
  158.  * Currently, only DLT_EN10MB and DLT_SLIP are supported.
  159.  */
  160. #define DLT_EN10MB    1    /* Ethernet (10Mb) */
  161. #define DLT_EN3MB    2    /* Experimental Ethernet (3Mb) */
  162. #define DLT_AX25    3    /* Amateur Radio AX.25 */
  163. #define DLT_PRONET    4    /* Proteon ProNET Token Ring */
  164. #define DLT_CHAOS    5    /* Chaos */
  165. #define DLT_IEEE802    6    /* IEEE 802 Networks */
  166. #define DLT_ARCNET    7    /* ARCNET */
  167. #define DLT_SLIP    8    /* Serial Line IP */
  168. #define DLT_PPP        9    /* Point-to-point Protocol */
  169. #define DLT_FDDI    10    /* FDDI */
  170.  
  171. /*
  172.  * The instruction encondings.
  173.  */
  174. /* classes <2:0> */
  175. #define BPF_CLASS(code) ((code) & 0x07)
  176. #define        BPF_LD        0x00
  177. #define        BPF_LDX        0x01
  178. #define        BPF_ST        0x02
  179. #define        BPF_STX        0x03
  180. #define        BPF_ALU        0x04
  181. #define        BPF_JMP        0x05
  182. #define        BPF_RET        0x06
  183. #define        BPF_MISC    0x07
  184.  
  185. /* ld/ldx fields */
  186. #define BPF_SIZE(code)    ((code) & 0x18)
  187. #define        BPF_W        0x00
  188. #define        BPF_H        0x08
  189. #define        BPF_B        0x10
  190. #define BPF_MODE(code)    ((code) & 0xe0)
  191. #define        BPF_IMM     0x00
  192. #define        BPF_ABS        0x20
  193. #define        BPF_IND        0x40
  194. #define        BPF_MEM        0x60
  195. #define        BPF_LEN        0x80
  196. #define        BPF_MSH        0xa0
  197.  
  198. /* alu/jmp fields */
  199. #define BPF_OP(code)    ((code) & 0xf0)
  200. #define        BPF_ADD        0x00
  201. #define        BPF_SUB        0x10
  202. #define        BPF_MUL        0x20
  203. #define        BPF_DIV        0x30
  204. #define        BPF_OR        0x40
  205. #define        BPF_AND        0x50
  206. #define        BPF_LSH        0x60
  207. #define        BPF_RSH        0x70
  208. #define        BPF_NEG        0x80
  209. #define        BPF_JA        0x00
  210. #define        BPF_JEQ        0x10
  211. #define        BPF_JGT        0x20
  212. #define        BPF_JGE        0x30
  213. #define        BPF_JSET    0x40
  214. #define BPF_SRC(code)    ((code) & 0x08)
  215. #define        BPF_K        0x00
  216. #define        BPF_X        0x08
  217.  
  218. /* ret - BPF_K and BPF_X also apply */
  219. #define BPF_RVAL(code)    ((code) & 0x18)
  220. #define        BPF_A        0x10
  221.  
  222. /* misc */
  223. #define BPF_MISCOP(code) ((code) & 0xf8)
  224. #define        BPF_TAX        0x00
  225. #define        BPF_TXA        0x80
  226.  
  227. /*
  228.  * The instruction data structure.
  229.  */
  230. struct bpf_insn {
  231.     u_short    code;
  232.     u_char     jt;
  233.     u_char     jf;
  234.     long    k;
  235. };
  236.  
  237. /*
  238.  * Macros for insn array initializers.
  239.  */
  240. #define BPF_STMT(code, k) { (u_short)(code), 0, 0, k }
  241. #define BPF_JUMP(code, k, jt, jf) { (u_short)(code), jt, jf, k }
  242.  
  243. #ifdef KERNEL
  244. extern u_int bpf_filter();
  245. extern void bpfattach();
  246. extern void bpf_tap();
  247. extern void bpf_mtap();
  248. #endif
  249.  
  250. /*
  251.  * Number of scratch memory words (for BPF_LD|BPF_MEM and BPF_ST).
  252.  */
  253. #define BPF_MEMWORDS 16
  254.