dsnet / udptunnel

Daemon for creating a simple VPN over UDP.
BSD 3-Clause "New" or "Revised" License
172 stars 31 forks source link

Support OSX #1

Closed BirkhoffLee closed 6 years ago

BirkhoffLee commented 6 years ago
birkhoff at Birkhoff-MBPR in ~/dev
$ go get -u github.com/dsnet/udptunnel
# github.com/dsnet/udptunnel
go/src/github.com/dsnet/udptunnel/tunnel.go:63: undefined: water.NewTUN
dsnet commented 6 years ago

The issue is that I only developed this for Linux to suite my needs. It seems the API for water is slightly different on darwin. This block of code currently makes a lot of assumptions about Linux:

conf := water.Config{DeviceType: water.TUN}
conf.Name = t.tunDev
iface, err := water.New(conf)
if err != nil {
    t.log.Fatalf("error creating tun device: %v", err)
}
defer iface.Close()
if err := exec.Command("/sbin/ip", "link", "set", "dev", t.tunDev, "mtu", "1300").Run(); err != nil {
    t.log.Fatalf("ip link error: %v", err)
}
if err := exec.Command("/sbin/ip", "addr", "add", t.tunAddr+"/24", "dev", t.tunDev).Run(); err != nil {
    t.log.Fatalf("ip addr error: %v", err)
}
if err := exec.Command("/sbin/ip", "link", "set", "dev", t.tunDev, "up").Run(); err != nil {
    t.log.Fatalf("ip link error: %v", err)
}

You're welcome to make a pull request to switch all that over to darwin specific functionality. For example, the ip command doesn't exist on darwin.