class Tuntap::Interface

Overview

Control class for network interfaces

Direct Known Subclasses

Defined in:

tuntap/interface.cr

Constant Summary

DEFAULT_METRIC = 100
DEFAULT_MTU = 1500

Default value for the MTU

UNSET_ADDR = "0.0.0.0"

Constructors

Class Method Summary

Instance Method Summary

Constructor Detail

def self.new(fd : IO::FileDescriptor, name : String) #

[View source]

Class Method Detail

def self.names : Array(String) #

Acquires the list of available interfaces


[View source]
def self.open(name : String) #

Opens the interface name


[View source]

Instance Method Detail

def add_address(address : String) : Nil #

Adds an IP address to the interface. For this to work, the interface has to be up.


[View source]
def add_address(address : LibC::Sockaddr) : Nil #

ditto


[View source]
def add_netmask(address : String) : Nil #

Sets the netmask of the interface


[View source]
def add_netmask(address : LibC::Sockaddr) : Nil #

ditto


[View source]
def add_route(destination : String, gateway : String = UNSET_ADDR, mask : String = UNSET_ADDR, metric = DEFAULT_METRIC, mtu = DEFAULT_MTU, window = 0, flags : LibC::RtEntryFlags = LibC::RtEntryFlags::Up) #

Adds a network route to this interface. Most arguments are optional.


[View source]
def close #

Closes the device. If it is not persistent, the system will remove the device entirely.


[View source]
def down! : Nil #

Disables the network interface ("Brings it down").


[View source]
def fd : IO::FileDescriptor #

The file descriptor controlling the device


[View source]
def ioctl(command, argument) : Int32 #

Runs an ioctl(3) on the device. Raises Errno on failure.


[View source]
def mtu : Int32 #

The MTU


[View source]
def mtu=(mtu : Int32) #

The MTU


[View source]
def name : String #

The device name


[View source]
def up! : Nil #

Enables the network interface ("Brings it up").


[View source]