#include <net/bpf.h>
net/bpf.h
macroBPF_ALIGN
#define BPF_ALIGN 1
macroEXTRACT_SHORT
#define EXTRACT_SHORT(p) ((u_int16_t) ((u_int16_t)*((u_char *)p+0)<<8| (u_int16_t)*((u_char *)p+1)<<0))
macroEXTRACT_LONG
#define EXTRACT_LONG(p) ((u_int32_t)*((u_char *)p+0)<<24| (u_int32_t)*((u_char *)p+1)<<16| (u_int32_t)*((u_char *)p+2)<<8| (u_int32_t)*((u_char *)p+3)<<0)
macroSIZEOF_BPF_HDR
Because the structure above is not a multiple of 4 bytes, some compilers
will insist on inserting padding; hence, sizeof(struct bpf_hdr) won't work.
Only the kernel needs to know about it; applications use bh_hdrlen.
#define SIZEOF_BPF_HDR (sizeof(struct bpf_hdr) <= 20 ? 18 : sizeof(struct bpf_hdr))
structbpf_dltlist
Structure to retrieve available DLTs for the interface.
| u_int32_t | bfl_len | number of bfd_list array | ||||||
| unnamed union at Kernel/net/bpf.h:1227:2 | bfl_u | |||||||
| ||||||||
typedefbpf_send_func
@typedef bpf_send_func
@discussion bpf_send_func is called when a bpf file descriptor is
used to send a raw packet on the interface. The mbuf and data
link type are specified. The callback is responsible for
releasing the mbuf whether or not it returns an error.
@param interface The interface the packet is being sent on.
@param data_link_type The data link type the bpf device is attached to.
@param packet The packet to be sent.
typedef errno_t (*)(ifnet_t, u_int32_t, mbuf_t) bpf_send_func;
typedefbpf_tap_func
@typedef bpf_tap_func
@discussion bpf_tap_func is called when the tap state of the
interface changes. This happens when a bpf device attaches to an
interface or detaches from an interface. The tap mode will join
together (bit or) the modes of all bpf devices using that
interface for that dlt. If you return an error from this
function, the bpf device attach attempt that triggered the tap
will fail. If this function was called bacuse the tap state was
decreasing (tap in or out is stopping), the error will be
ignored.
@param interface The interface being tapped.
@param data_link_type The data link type being tapped.
@param direction The direction of the tap.
typedef errno_t (*)(ifnet_t, u_int32_t, bpf_tap_mode) bpf_tap_func;
functionbpfattach
extern void bpfattach(ifnet_t interface, u_int data_link_type, u_int header_length)
@function bpfattach
@discussion Registers an interface with BPF. This allows bpf devices
to attach to your interface to capture packets. Your interface
will be unregistered automatically when your interface is
detached.
@param interface The interface to register with BPF.
@param data_link_type The data link type of the interface. See the
DLT_* defines in bpf.h.
@param header_length The length, in bytes, of the data link header.
functionbpf_attach
extern errno_t bpf_attach( ifnet_t interface, u_int32_t data_link_type, u_int32_t header_length, bpf_send_func send, bpf_tap_func tap )
@function bpf_attach
@discussion Registers an interface with BPF. This allows bpf devices
to attach to your interface to capture and transmit packets.
Your interface will be unregistered automatically when your
interface is detached. You may register multiple times with
different data link types. An 802.11 interface would use this to
allow clients to pick whether they want just an ethernet style
frame or the 802.11 wireless headers as well. The first dlt you
register will be considered the default. Any bpf device attaches
that do not specify a data link type will use the default.
@param interface The interface to register with BPF.
@param data_link_type The data link type of the interface. See the
DLT_* defines in bpf.h.
@param header_length The length, in bytes, of the data link header.
@param send See the bpf_send_func described above.
@param tap See the bpf_tap_func described above.
functionbpf_tap_in
extern void bpf_tap_in( ifnet_t interface, u_int32_t dlt, mbuf_t packet, void *__sized_by(header_len) header, size_t header_len )
@function bpf_tap_in
@discussion Call this function when your interface receives a
packet. This function will check if any bpf devices need a
a copy of the packet.
@param interface The interface the packet was received on.
@param dlt The data link type of the packet.
@param packet The packet received.
@param header An optional pointer to a header that will be prepended.
@param header_len If the header was specified, the length of the header.
functionbpf_tap_out
extern void bpf_tap_out( ifnet_t interface, u_int32_t dlt, mbuf_t packet, void *__sized_by(header_len) header, size_t header_len )
@function bpf_tap_out
@discussion Call this function when your interface transmits a
packet. This function will check if any bpf devices need a
a copy of the packet.
@param interface The interface the packet was or will be transmitted on.
@param dlt The data link type of the packet.
@param packet The packet received.
@param header An optional pointer to a header that will be prepended.
@param header_len If the header was specified, the length of the header.