vtun/tun/tun.go
2021-04-19 23:24:31 +08:00

29 lines
539 B
Go

package tun
import (
"log"
"runtime"
"github.com/net-byte/vtun/common/osutil"
"github.com/songgao/water"
)
func CreateTun(cidr string) (iface *water.Interface) {
c := water.Config{}
os := runtime.GOOS
if os == "darwin" {
c.DeviceType = water.TUN
c.Name = "utun007"
} else {
c.DeviceType = water.TAP
c.Name = "vtun"
}
iface, err := water.New(c)
if err != nil {
log.Fatalln("failed to allocate TUN interface:", err)
}
log.Println("interface allocated:", iface.Name())
osutil.ConfigTun(cidr, iface)
return iface
}