package tuntap
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Module TuntapSource
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 * stringopentun ~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 * stringLike opentun, but open TAP interfaces instead of TUN ones.
closetun devname kind will destroy devname, if it exists.
Like closetun, but for TAP interfaces.
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).
get_mtu devname is the MTU of interface devname.
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.
val getifaddrs :
unit ->
(string * [ `V4 of Ipaddr.V4.Prefix.t | `V6 of Ipaddr.V6.Prefix.t ]) listgetifaddrs () 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.
val addrs_of_ifname :
string ->
[ `V4 of Ipaddr.V4.Prefix.t | `V6 of Ipaddr.V6.Prefix.t ] listaddrs_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.
v6_of_ifname ifname is the list of IPv6 addresses and their prefixes associated to interface ifname.