Library
Module
Module type
Parameter
Class
Class type
A portable API to send and receive raw packets.
There are times when one needs to construct the full ethernet frame to send/receive. Most unixes support BPF (BSD Packet Filter) to achieve it, but linux provides the same functionality via AF_SOCKET. This API works with either a BPF or AF_SOCKET backend, so it should work on every usable UNIX, as well as linux out there.
val open_link :
?filter:string ->
?promisc:bool ->
string ->
sw:Eio.Switch.t ->
t
open_link ~filter ~promisc interface sw
. Creates a rawlink on the specified interface
, a BPF program filter
can be passed to filter out incoming packets. If promisc
is true, sets interface
to promiscuous mode, defaults to false.
val close_link : t -> unit
close_link
. Closes a rawlink.
val read_packet : t -> Cstruct.t
read_packet t
. Reads a full packet, may raise Unix.Unix_error.
val send_packet : t -> Cstruct.t -> unit
send_packet t
. Sends a full packet, may raise Unix.Unix_error.
dhcp_server_filter
. Returns a BPF program suitable to be passed in open_link ~filter
, it accepts UDP packets destined to port 67 (DHCP server).