Ejemplo n.º 1
0
func (t *Tun) GetNetmask() (mask net.IPMask, err error) {
	var c_addr *C.char
	c_name := C.CString(t.Name)
	defer C.free(unsafe.Pointer(c_name))
	if C.if_getaddr(C.SIOCGIFNETMASK, c_name, &c_addr) < 0 {
		err = fmt.Errorf("get netmask fail")
		return
	}
	return net.IPMask(net.ParseIP(C.GoString(c_addr))), nil
}
Ejemplo n.º 2
0
func (t *Tun) GetDestAddr() (ip net.IP, err error) {
	var c_addr *C.char
	c_name := C.CString(t.Name)
	defer C.free(unsafe.Pointer(c_name))
	if C.if_getaddr(C.SIOCGIFDSTADDR, c_name, &c_addr) < 0 {
		err = fmt.Errorf("get dest addr fail")
		return
	}
	return net.ParseIP(C.GoString(c_addr)), nil
}