Development discussion of WireGuard
 help / color / mirror / Atom feed
* Any possibility to run wireguard-go with android vpnservice?
@ 2021-03-09 13:44 KeXianbin(http://diyism.com)
  2021-03-09 21:26 ` Jason A. Donenfeld
  0 siblings, 1 reply; 4+ messages in thread
From: KeXianbin(http://diyism.com) @ 2021-03-09 13:44 UTC (permalink / raw)
  To: WireGuard mailing list

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-03-10  0:53 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-09 13:44 Any possibility to run wireguard-go with android vpnservice? KeXianbin(http://diyism.com)
2021-03-09 21:26 ` Jason A. Donenfeld
2021-03-10  0:31   ` KeXianbin(http://diyism.com)
2021-03-10  0:53     ` Jason A. Donenfeld

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).