tun

package
v0.0.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 18, 2026 License: MIT Imports: 4 Imported by: 2

Documentation

Overview

Package tun implements TUN interface operations on system level.

Example (Create)
package main

import (
	"log"
	"net"

	"github.com/goxray/core/network/tun"
)

func main() {
	ifc, err := tun.New("utun123", 1500)
	if err != nil {
		log.Fatal(err)
	}
	defer ifc.Close()

	addr := &net.IPNet{IP: net.IPv4(192, 18, 0, 1)}

	if err := ifc.Up(addr, addr.IP); err != nil {
		log.Fatal(err)
	}

	// Interface will be destroyed upon exiting the program...
}

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Interface

type Interface struct {
	// contains filtered or unexported fields
}

Interface is a TUN/TAP interface.

func New

func New(name string, MTU int) (*Interface, error)

New creates a new TUN interface.

On macOS the device name will be assigned dynamically if you pass an empty name string.

func (*Interface) Close

func (i *Interface) Close() error

Close closes fd. Close call is recommended to close the socket and destroy the interface.

func (*Interface) Name

func (i *Interface) Name() string

Name returns the interface name of ifce, e.g. tun0, tap1, tun0, etc..

func (*Interface) Read

func (i *Interface) Read(p []byte) (n int, err error)

Read reads p bytes from the interface fd.

func (*Interface) Up

func (i *Interface) Up(local *net.IPNet, gw net.IP) error

Up brings the TUN interface up and assign addresses for it.

Basically mimics "ifconfig {tun} {local} {gateway} up". But is implemented via system calls.

func (*Interface) Write

func (i *Interface) Write(p []byte) (n int, err error)

Write writes p bytes to the interface fd.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL