mirror of
https://github.com/yggdrasil-network/water.git
synced 2025-05-19 16:35:10 +03:00
initial commit
This commit is contained in:
parent
a9977e0a62
commit
4a028c3fe3
7 changed files with 377 additions and 0 deletions
34
syscalls_linux.go
Normal file
34
syscalls_linux.go
Normal file
|
@ -0,0 +1,34 @@
|
|||
// +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
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue