initial commit

This commit is contained in:
Song Gao 2013-03-25 14:49:39 -05:00
parent a9977e0a62
commit 4a028c3fe3
7 changed files with 377 additions and 0 deletions

34
syscalls_linux.go Normal file
View 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
}