Skip to content
forked from Kr328/tun2socket

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

License

Notifications You must be signed in to change notification settings

mor9x/tun2socket

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

91 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

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

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 100.0%