Ejemplo n.º 1
0
func newTun(ifname, addr, mask string, mtu int) (t tunDev, err error) {
	fd := C.tundev_open(C.CString(ifname))

	if fd == -1 {
		err = errors.New("cannot open tun interface")
	} else {
		if C.tundev_up(C.CString(ifname), C.CString(addr), C.CString(mask), C.int(mtu)) < C.int(0) {
			err = errors.New("cannot put up interface")
		} else {
			t = tunDev{fd}
		}
	}
	return
}
Ejemplo n.º 2
0
func newTun(ifname, addr, dstaddr string, mtu int) (t tunDev, err error) {
	name := C.tundev_open(&t.fd)

	if t.fd == C.int(-1) {
		err = errors.New("cannot open tun interface")
	} else {
		res := C.tundev_up(name, C.CString(addr), C.CString(dstaddr), C.int(mtu))
		if res == C.int(-1) {
			err = errors.New("cannot put up interface")
			t.Close()
		}
	}
	C.tundev_free(name)
	return
}