bpfLibP.h
上传用户:luoyougen
上传日期:2008-05-12
资源大小:23136k
文件大小:7k
源码类别:

VxWorks

开发平台:

C/C++

  1. /* bpfLibP.h - Berkeley Packet Filter (BPF) private include file */
  2. /* Copyright 1999 - 2000 Wind River Systems, Inc. */
  3. #include "copyright_wrs.h"
  4. /*-
  5.  * Copyright (c) 1990, 1991, 1992, 1994, 1995, 1996
  6.  * The Regents of the University of California.  All rights reserved.
  7.  *
  8.  * This code is derived from the Stanford/CMU enet packet filter,
  9.  * (net/enet.c) distributed as part of 4.3BSD, and code contributed
  10.  * to Berkeley by Steven McCanne and Van Jacobson both of Lawrence 
  11.  * Berkeley Laboratory.
  12.  *
  13.  * Redistribution and use in source and binary forms, with or without
  14.  * modification, are permitted provided that the following conditions
  15.  * are met:
  16.  * 1. Redistributions of source code must retain the above copyright
  17.  *    notice, this list of conditions and the following disclaimer.
  18.  * 2. Redistributions in binary form must reproduce the above copyright
  19.  *    notice, this list of conditions and the following disclaimer in the
  20.  *    documentation and/or other materials provided with the distribution.
  21.  * 3. All advertising materials mentioning features or use of this software
  22.  *    must display the following acknowledgement:
  23.  * This product includes software developed by the University of
  24.  * California, Berkeley and its contributors.
  25.  * 4. Neither the name of the University nor the names of its contributors
  26.  *    may be used to endorse or promote products derived from this software
  27.  *    without specific prior written permission.
  28.  *
  29.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  30.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  31.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  32.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  33.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  34.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  35.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  36.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  37.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  38.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  39.  * SUCH DAMAGE.
  40.  *
  41.  * @(#)bpfdesc.h 7.1 (Berkeley) 5/7/91
  42.  *
  43.  * @(#) $Header: bpfdesc.h,v 1.14 96/06/16 22:28:07 leres Exp $ (LBL)
  44.  */
  45. /*
  46. modification history
  47. --------------------
  48. 01b,17nov00,spm  added support for BSD network devices
  49. 01a,24nov99,spm  created from BSD bpfdesc.h,v 1.14 96/06/16 22:28:07
  50. */
  51. #ifndef __INCbpfLibPh
  52. #define __INCbpfLibPh
  53. #ifdef __cplusplus
  54. extern "C" {
  55. #endif
  56. /* includes */
  57. #include "vxWorks.h"
  58. #include "lstLib.h"
  59. #include "iosLib.h"
  60. #include "selectLib.h"
  61. #include "endLib.h"
  62. #include "net/bpf.h"
  63. /* typedefs */
  64. /* Descriptor associated with each attached network interface. */
  65. typedef struct bpf_proto_ctrl {      /* BPF_PROTO_CTRL */
  66.     NODE  bpfProtoLstNode;               /* list of interface attachments */
  67.     BOOL  bsdFlag;                       /* BSD or END network device? */
  68.     void  * pCookie;                     /* identifies net device attachment */
  69.     LIST  bpfUnitList;                   /* list of attached BPF units */
  70.     u_int numShared;                     /* number of shared BPF devices */
  71.     LIST  bpfDevList;                    /* shared BPF device attachments */
  72.     u_int numPromisc;                    /* number of promiscuous listeners */
  73.     BOOL  bpfPromiscEnabled;             /* TRUE if BPF turned on promisc */
  74.     u_int dataLinkType;                  /* data link layer type */
  75.     int   mtuSize;                       /* Max device frame size */
  76.     char  devName [END_NAME_MAX + 1];    /* name of network interface */
  77.     int   devUnit;                       /* unit number of network interface */
  78. } BPF_PROTO_CTRL;
  79. /* Descriptor associated with each open bpf file. */
  80. typedef struct bpf_dev_ctrl {      /* BPF_DEV_CTRL */
  81.     NODE bpfDevLstNode; /* node in list of devices attached to an interface */
  82.     UINT32 bpfDevId;       /* unique identifier for all units of BPF device */
  83.     BOOL selectFlag;  /* tasks pending on select for device? */
  84.     BPF_PROTO_CTRL * pNetIfCtrl;  /* used for first attachment of BPF device */
  85.     BPF_PROTO_CTRL * pNetDev;     /* attachment for this unit, if any */
  86.     SEM_ID  lockSem;    /* provides mutual exclusion */
  87.     /*
  88.      * Buffer slots: two character buffers buffer the incoming packets.
  89.      *   The model has three slots. recvStoreBuf is always occupied.
  90.      *   recvStoreBuf (store) - Receive interrupt puts packets here.
  91.      *   readHoldBuf (hold) - When recvStoreBuf is full, put cluster here
  92.      *   and wakeup read (replace recvStoreBuf with freeBuf).
  93.      *   freeBuf (free) - When read is done, put cluster here.
  94.      * On receiving, if recvStoreBuf is full and freeBuf is NULL, 
  95.      * packet is dropped.
  96.      */
  97.     caddr_t  recvStoreBuf; /* store slot */
  98.     caddr_t  readHoldBuf;       /* hold slot */
  99.     caddr_t  freeBuf;         /* free slot */
  100.     int      recvStoreLen; /* current length of store buffer */
  101.     int      readHoldLen; /* current length of hold buffer */
  102.     u_int    bufSize;         /* absolute length of buffers */
  103.     u_long    readTimeout;      /* Read timeout in 'ticks' */
  104.     BPF_INSN  * pBpfInsnFilter; /* filter code */
  105.     int       filterLen;  /* number of instructions in filter */
  106.     u_long    pktRecvCount; /* number of packets received */
  107.     u_long    pktDropCount; /* number of packets dropped */
  108.     BOOL      promiscMode; /* true if listening promiscuously */
  109.     BOOL      immediateMode; /* true to return on packet arrival */
  110.     BOOL      nonBlockMode;     /* true if read is non-blocking */
  111.     SEM_ID    readWkupSem;      /* pended read sem. */
  112.     int       usrFlags;         /* file open flags */
  113.     BOOL      inUse;            /* TRUE if being used by a file desc */
  114.     SEL_WAKEUP_LIST selWkupList;/* select wakeup list */
  115. } BPF_DEV_CTRL;
  116. typedef struct {        /* BPF_DEV_HDR */
  117.     DEV_HDR      devHdr;        /* BPF device hdr */
  118.     BPF_DEV_CTRL * pBpfDevTbl;  /* Table of BPF device entries */
  119.     BPF_PROTO_CTRL * pBpfNetIfTbl;    /* Attachments to network interfaces */
  120.     int          numDevs;       /* number of BPF devices */
  121.     int          bufSize;       /* default BPF device buffer size */
  122.     SEM_ID   lockSem;  /* provides mutual exclusion */
  123.     } BPF_DEV_HDR;
  124. /* defines */
  125. #define BPF_LOCK_KEY   1   /* Key to release BPF lock */
  126. #define BPF_DUMMY_KEY  0   /* dummy key will not release lock */
  127. /* function declarations */
  128. #if defined(__STDC__) || defined(__cplusplus)
  129. IMPORT int  _bpfLock ();
  130. IMPORT BOOL _bpfUnlock (int lockKey); 
  131. IMPORT void _bpfPacketTap (LIST * pListBpfDev, long type, M_BLK_ID pMBlk, 
  132.    int netDataOffset);
  133. IMPORT STATUS _bpfDevDetach (BPF_DEV_CTRL * pBpfDev);
  134. IMPORT void _bpfProtoInit (void);
  135. IMPORT STATUS _bpfProtoAttach (BPF_DEV_CTRL *, char *, int, struct ifnet *);
  136. IMPORT STATUS _bpfProtoDetach (BPF_DEV_CTRL * pBpfDev);
  137. IMPORT STATUS _bpfProtoPromisc (BPF_PROTO_CTRL * pBpfProto, BOOL on); 
  138. IMPORT void _bpfTimeStamp (struct timeval * pTimeval);
  139. IMPORT STATUS _bpfProtoSend (BPF_PROTO_CTRL * pBpfProto, char * pBuf, 
  140.      int nBytes, BOOL nbIo);
  141. #else   /* __STDC__ */
  142. IMPORT int  _bpfLock ();
  143. IMPORT BOOL _bpfUnlock (); 
  144. IMPORT STATUS _bpfDevDetach ();
  145. IMPORT void _bpfProtoInit ();
  146. IMPORT BPF_PROTO_CTRL * _bpfProtoAttach ();
  147. IMPORT BPF_PROTO_CTRL * _bpfProtoDetach ();
  148. IMPORT STATUS _bpfProtoPromisc ();
  149. IMPORT void _bpfTimeStamp ();
  150. IMPORT STATUS _bpfProtoSend ();
  151. IMPORT void _bpfPacketTap ();
  152. #endif /* __STDC__ */
  153. #ifdef __cplusplus
  154. }
  155. #endif
  156. #endif /* __INCbpfLibPh */