
This parameter is initialized to zero by bpf_open(), indicating no timeout. The argument specifies the length of time to wait before timing out on a read request. (struct timeval) Set or get the read timeout parameter. Additionally, performs the actions of BIOCFLUSH. The device is indicated by name using the ifr_name field of the ifreq structure. This command must be performed before any packets can be read. (struct ifreq) Sets the hardware interface associate with the file. The name is returned in the ifr_name field of the ifreq structure. (struct ifreq) Returns the name of the hardware interface that the file is listening on. This problem can be remedied with an appropriate filter.įlushes the buffer of incoming packets, and resets the statistics that are returned by BIOCGSTATS. Since more than one file can be listening on a given interface, a listener that opened its interface non-promiscuously may receive packets promiscuously. All packets, not just those destined for the local host, are processed. įorces the interface into promiscuous mode. The device types, prefixed with 'DLT_', are defined in. EINVAL is returned if no interface has been specified. (u_int) Returns the type of the data link layer underlying the attached interface. A read call will result in EIO if it is passed a buffer that is not this size. If the requested buffer size cannot be accommodated, the closest allowable size will be set and returned in the argument. The buffer must be set before the file is attached to an interface with BIOCSETIF. (u_int) Sets the buffer length for reads on bpf files. (u_int) Returns the required buffer length for reads on bpf files. The (third) argument to ioctl(2) should be a pointer to the type indicated. In addition to FIONREAD and SIOCGIFADDR, the following commands may be applied to any open bpf file. All commands require these includes: #include Īdditionally, BIOCGETIF and BIOCSETIF require and. The ioctl(2) command codes below are defined in. The bpf_open() mode and flags are as defined for open() IOCTLS Currently, only writes to Ethernets and SLIP links are supported.


The writes are unbuffered, meaning only one packet can be processed per write. Since packet data is in network byte order, applications should use the byteorder(3) macros to extract multi-byte values.Ī packet can be sent out on the network by writing to a bpf file descriptor.
ISTAT MENUS DAEMON BERKELEY PACKET FILTER DRIVERS
Currently, only Ethernet, SLIP, and PPP drivers have been modified to interact with bpf. The packet filter will support any link level protocol that has fixed length headers.

Note that an individual packet larger than this size is necessarily truncated.
This size is returned by the BIOCGBLEN ioctl (see below), and can be set with BIOCSBLEN. To improve performance, the buffer passed to read must be the same size as the buffers used internally by bpf. Reads from these files return the next group of packets that have matched the filter. Each descriptor that accepts the packet receives its own copy. Whenever a packet is received by an interface, all file descriptors listening on that interface apply their filter. If a file is in use, the bpf_open will fail and errno will be set to EBUSY.Īssociated with each open instance of a bpf file is a user-settable packet filter. A given interface can be shared by multiple listeners, and the filter underlying each descriptor will see an identical packet stream.Ī separate device file is required for each minor device. After opening the device, the file descriptor must be bound to a specific network interface with the BIOCSETIF ioctl. The packet filter appears as a character special device, /dev/bpf0, /dev/bpf1, etc. All packets on the network, even those destined for other hosts, are accessible through this mechanism. The Berkeley Packet Filter provides a raw interface to data link layers in a protocol independent fashion. Bpf_open(char * name, int flags, int mode) Overview
