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 specify an unexistant device, a new device will be created, otherwise, the interface
devname will be opened.
no_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
group if supported by your OS (currently MacOSX 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
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.
val get_macaddr : string -> Macaddr.t
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.
val getifaddrs_v4 : unit -> (string * Ipaddr.V4.Prefix.t) list
getifaddrs but only return interfaces that have an IPv4 assigned.
val getifaddrs_v6 : unit -> (string * Ipaddr.V6.Prefix.t) list
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
val v4_of_ifname : string -> Ipaddr.V4.Prefix.t list
v4_of_ifname ifname is the list of IPv4 addresses and their prefixes associated to interface
val v6_of_ifname : string -> Ipaddr.V6.Prefix.t list
v6_of_ifname ifname is the list of IPv6 addresses and their prefixes associated to interface