tun2socket

package module
v0.0.0-...-370f53a Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2021 License: MIT Imports: 3 Imported by: 0

README

Tun2Socket

A utilize that use kernel tcpip stack to forward packet from tun device.

Feature
  • IPv4
  • TCP/UDP
  • Ping Echo
Usage
tun := openTunDevice() // Open tun device by your self
mtu := tun.getMtu() // mtu of tun device
gateway := tun.getAddress()              // address of tun device
mirror := gateway.getSingleFreeAddress() // a free ip in tun address range

tun2socket := tun2socket2.NewTun2Socket(tun, mtu, gateway, mirror)
tun2socket.SetTCPHandler(func (conn net.Conn, endpoint *binding.Endpoint) {
// fmt.Println("[TCP] " + endpoint.Source.IP.String() + " -> " + endpoint.Target.IP.String())

// handle new tcp connection here
// start a new goroutine if need
})
tun2socket.SetUDPHandler(func (payload []byte, endpoint *binding.Endpoint, sender redirect.UDPSender) {
// fmt.Println("[UDP] " + endpoint.Source.IP.String() + " -> " + endpoint.Target.IP.String())

// handle udp packet here
// start a new goroutine if need 
})

tun2socket.Start() // start now
TODO
  • IPv6 Supoort

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Tun2Socket

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

func StartTun2Socket

func StartTun2Socket(device io.ReadWriteCloser, gateway net.IP, portal net.IP) (*Tun2Socket, error)

noinspection GoUnusedExportedFunction

func (*Tun2Socket) Close

func (t *Tun2Socket) Close() error

func (*Tun2Socket) TCP

func (t *Tun2Socket) TCP() *nat.TCP

func (*Tun2Socket) UDP

func (t *Tun2Socket) UDP() *nat.UDP

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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