Documentation ¶
Overview ¶
The tun package creates, reads and writes to/from tun devices.
Index ¶
Constants ¶
const ( SizeofPtr = 0x8 SizeofLong = 0x8 )
const (
DEV_NET_TUN string = "/dev/net/tun"
)
Variables ¶
var (
ErrInvalidAddress error = errors.New("invalid address")
)
Functions ¶
func ByteSliceToString ¶
ByteSliceToString returns a string form of the text represented by the slice s, with a terminating NUL and any bytes after the NUL removed.
Types ¶
type Ifreq ¶
An Ifreq is a type-safe wrapper around the raw ifreq struct. An Ifreq contains an interface name and a union of arbitrary data which can be accessed using the Ifreq's methods. To create an Ifreq, use the NewIfreq function.
Use the Name method to access the stored interface name. The union data fields can be get and set using the following methods:
- Uint16/SetUint16: flags
- Uint32/SetUint32: ifindex, metric, mtu
func NewIfreq ¶
NewIfreq creates an Ifreq with the input network interface name after validating the name does not exceed IFNAMSIZ-1 (trailing NULL required) bytes.
func (*Ifreq) Clear ¶
func (ifr *Ifreq) Clear()
clear zeroes the ifreq's union field to prevent trailing garbage data from being sent to the kernel if an ifreq is reused.
func (*Ifreq) Inet4Addr ¶
Inet4Addr returns the Ifreq union data from an embedded sockaddr as a C in_addr/Go []byte (4-byte IPv4 address) value. If the sockaddr family is not AF_INET, an error is returned.
func (*Ifreq) SetInet4Addr ¶
SetInet4Addr sets a C in_addr/Go []byte (4-byte IPv4 address) value in an embedded sockaddr within the Ifreq's union data. v must be 4 bytes in length or an error will be returned.
type TUN ¶
func CreateTUN ¶
CreateTUN creates a new tun device with name. If mtu is above 0 it attempts to set the MTU. If uid is above 0 it attempts to set the owner, same with gid. Returns a TUN which should be closed with receiver function Close() when you want to terminate the tunnel.