Any possibility to run wireguard-go with android vpnservice?

KeXianbin(http://diyism.com) kexianbin at diyism.com
Tue Mar 9 13:44:56 UTC 2021


Sorry for bothering,
I'm trying to run wireguard-go with android vpnservice:

first, I started a vpnservice and got the fd integer:

vpnConn=builder.establish();
int fd=vpnConn.getFd();

The key icon showed on the right-top corner of android phone and the
fd  value is 114.

then, I modify tun_linux.go of wireguard-go:
func CreateUnmonitoredTUNFromFD1(fd int) (Device, error) {
    err := unix.SetNonblock(fd, true)
    if err != nil {
        return nil, err
    }
    file := os.NewFile(uintptr(fd), "/dev/tun")
    tun := &NativeTun{
        tunFile: file,
        events:  make(chan Event, 5),
        errors:  make(chan error, 5),
        nopi:    true,
    }
    //name, err := tun.Name()
    if err != nil {
        return nil, err
    }
    return tun, nil
}

and modify main.go :

    tun, err := func() (tun.Device, error) {
        tunFdStr := os.Getenv(ENV_WG_TUN_FD)
        if tunFdStr == "" {
            return tun.CreateTUN(interfaceName, device.DefaultMTU)
        }
        fd, err := strconv.Atoi(tunFdStr);
        return tun.CreateUnmonitoredTUNFromFD1(fd);

But when I run this in android directory /local/data/tmp:

WG_TUN_FD=114 ./wireguard-go wg0

It gives me: Failed to create TUN device: bad file descriptor


It seems that my try is nonsense,
but is there any possibility to run wireguard-go with vpn service
without gomobile jni?


Thanks.

Malcolm Ke


More information about the WireGuard mailing list