diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-10-09 18:26:21 +0200 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-10-09 19:46:48 +0200 |
commit | 33fd5b4634a946073930bdfcfd3189bf870e9748 (patch) | |
tree | 8c1c807fe8e051ad723019ed1a8f648304fcd568 /app/tools/libwg-go/src/tun | |
parent | 91647978e69000e223c5f1daef89ad3d8e4ce66e (diff) |
Update to go modules
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'app/tools/libwg-go/src/tun')
-rw-r--r-- | app/tools/libwg-go/src/tun/api-android.go | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/app/tools/libwg-go/src/tun/api-android.go b/app/tools/libwg-go/src/tun/api-android.go new file mode 100644 index 00000000..90986c4d --- /dev/null +++ b/app/tools/libwg-go/src/tun/api-android.go @@ -0,0 +1,31 @@ +/* SPDX-License-Identifier: Apache-2.0 + * + * Copyright (C) 2017-2018 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved. + */ + +package tun + +import ( + "git.zx2c4.com/wireguard-go/rwcancel" + "os" +) + +func CreateTUNFromFD(tun_fd int) (TUNDevice, string, error) { + tun := &nativeTun{ + fd: os.NewFile(uintptr(tun_fd), "/dev/tun"), + events: make(chan TUNEvent, 5), + errors: make(chan error, 5), + nopi: true, + } + var err error + tun.fdCancel, err = rwcancel.NewRWCancel(tun_fd) + if err != nil { + return nil, "", err + } + name, err := tun.Name() + if err != nil { + tun.fdCancel.Cancel() + return nil, "", err + } + return tun, name, nil +} |