VxWorks Reference Manual : Libraries
bpfDrv - Berkeley Packet Filter (BPF) I/O driver library
bpfDrv( ) - initialize the BPF driver
bpfDevCreate( ) - create Berkeley Packet Filter device
bpfDevDelete( ) - destroy Berkeley Packet Filter device
This library provides a driver which supports the customized retrieval of incoming network data that meets the criteria imposed by a user-specified filter.
The bpfDrv( ) routine initializes the driver and the bpfDevCreate( ) routine creates a packet filter device. Each BPF device allows direct access to the incoming data from one or more network interfaces.
In order to retrieve incoming network data, a BPF device must be created by calling the bpfDevCreate( ) routine:
STATUS bpfDevCreate ( char * pDevName, /* I/O system device name */ int numUnits, /* number of device units */ int bufSize /* block size for the BPF device */ )The numUnits parameter specifies the maximum number of BPF units for the device. Each unit is accessed through a separate file descriptor for use with a unique filter and/or a different network interface. For example, the following call creates the "/bpf0" and "/bpf1" units:bpfDevCreate ("/bpf", 2, 4096);
After opening a device unit, the associated file descriptor must be bound to a specific network interface with the BIOCSETIF ioctl( ) option. The BIOCSETF ioctl( ) option adds any filter instructions. Each file descriptor receives a copy of any data which matches the filter. Different file descriptors may share the same interface. The underlying filters will receive an identical data stream.
The BPF driver supports the following ioctl( ) functions:
When reading data from BPF units, the supplied buffer must be able to accept an entire block of data as defined by the bufSize parameter to the bpfDevCreate( ) routine. That value is also available with the BIOCGBLEN ioctl( ) option described above.
bpfDrv.h
bpfDrv( ) - initialize the BPF driver
STATUS bpfDrv (void)
This routine installs the Berkeley Packet Filter driver for access through the I/O system. It is required before performing any I/O operations and is executed automatically if INCLUDE_BPF is defined at the time the system is built. Subsequent calls to the routine just count the number of users with BPF access.
OK, or ERROR if initialization fails.
N/A
bpfDevCreate( ) - create Berkeley Packet Filter device
STATUS bpfDevCreate ( char * pDevName, /* I/O system device name */ int numUnits, /* number of device units */ int bufSize /* BPF device block size (0 for default) */ )
This routine creates a Berkeley Packet Filter device. Each of the numUnits units corresponds to a single available file descriptor for monitoring a network device. The pDevName parameter provides the name of the BPF device to the I/O system. The default name of "/bpf" (assigned if pDevName is NULL) produces units named "/bpf0", "/bpf1", etc., up to the numUnits limit.
OK, or ERROR if device creation failed.
S_ioLib_NO_DRIVER
bpfDevDelete( ) - destroy Berkeley Packet Filter device
STATUS bpfDevDelete ( char * pDevName /* name of BPF device to remove */ )
This routine removes a Berkeley Packet Filter device and releases all allocated memory. It will close any open files using the device.
OK, or ERROR if device not found
S_ioLib_NO_DRIVER