Tuntap
Module for dealing with TUN/TAP devices. TUN refers to layer 3 virtual interfaces whereas TAP refers to layer 2 ones.
val opentun :
?pi:bool ->
?persist:bool ->
?user:int ->
?group:int ->
?devname:string ->
unit ->
Unix.file_descr * string
opentun ~pi ~persist ~user ~group ~devname ()
will create a TUN interface. If devname
is specified, or if devname
specifies a nonexistent device, a new device will be created, otherwise, the interface devname
will be opened. pi
is to indicate if you want packet information associated with your frames (tap) or packets (tun) (defaults to no information). persist
will set the device persistent with permissions set to user
and group
if supported by your OS (currently macOS does not support it). The return value is a pair consisting of a fd opened on the freshly created interface, and its name as will be displayed by command ifconfig
for example.
val opentap :
?pi:bool ->
?persist:bool ->
?user:int ->
?group:int ->
?devname:string ->
unit ->
Unix.file_descr * string
Like opentun
, but open TAP interfaces instead of TUN ones.
get_ifnamsiz ()
is the value of the constant IFNAMSIZ, defined in <net/if.h>. Useful for allocating buffers that contain interface names.
get_hwaddr devname
is the MAC address of interface devname
, as a raw string (not hexa).
set_ipv4 ~netmask dev ipaddr
assigns an ipaddr
to interface dev
, with associated netmask netmask
if specified. If unspecified, the kernel will assign a default netmask automatically.
set_up_and_running devname
sets interface devname
up and running. Note that when using the set_ipv4
function, the interface will automatically be set up and running.
getifaddrs ()
is the list that associates interface names with IP addresses and prefix. Only interfaces that have an IP address assigned are returned.
Same as getifaddrs
but only return interfaces that have an IPv4 assigned.
Same as getifaddrs
but only return interfaces that have an IPv6 assigned.
addrs_of_ifname ifname
is the list of IP addresses and their prefixes associated to interface ifname
.
v4_of_ifname ifname
is the list of IPv4 addresses and their prefixes associated to interface ifname
.