mirror of
https://github.com/yggdrasil-network/water.git
synced 2025-05-19 16:35:10 +03:00
34 lines
619 B
Go
34 lines
619 B
Go
// +build linux
|
|
|
|
package water
|
|
|
|
import (
|
|
"strings"
|
|
"syscall"
|
|
"unsafe"
|
|
)
|
|
|
|
const (
|
|
cIFF_TUN = 0x0001
|
|
cIFF_TAP = 0x0002
|
|
cIFF_NO_PI = 0x1000
|
|
)
|
|
|
|
type ifReq struct {
|
|
Name [0x10]byte
|
|
Flags uint16
|
|
pad [0x28 - 0x10 - 2]byte
|
|
}
|
|
|
|
func createInterface(fd uintptr, ifName string, flags uint16) (createdIFName string, err error) {
|
|
var req ifReq
|
|
req.Flags = flags
|
|
copy(req.Name[:], ifName)
|
|
_, _, errno := syscall.Syscall(syscall.SYS_IOCTL, fd, uintptr(syscall.TUNSETIFF), uintptr(unsafe.Pointer(&req)))
|
|
if errno != 0 {
|
|
err = errno
|
|
return
|
|
}
|
|
createdIFName = strings.Trim(string(req.Name[:]), "\x00")
|
|
return
|
|
}
|