Esempio n. 1
0
func NameToMIB(name string) (mib []_C_int, err error) {
	const siz = unsafe.Sizeof(mib[0])

	var buf [syscall.CTL_MAXNAME + 2]_C_int
	n := uintptr(syscall.CTL_MAXNAME) * siz

	p := (*byte)(unsafe.Pointer(&buf[0]))
	bytes, err := syscall.ByteSliceFromString(name)
	if err != nil {
		return nil, err
	}

	if err = sysctl([]_C_int{0, 3}, p, &n, &bytes[0], uintptr(len(name))); err != nil {
		return nil, err
	}
	return buf[0 : n/siz], nil
}
Esempio n. 2
0
func SetString(name string, value string) error {
	mib, err := NameToMIB(name)
	if err != nil {
		return err
	}

	valueslc, err := syscall.ByteSliceFromString(value)
	if err != nil {
		return err
	}

	if err := sysctl(mib, nil, nil, &valueslc[0], uintptr(len(value))); err != nil {
		return err
	}

	return nil

}