github.com/lianghucheng/zrddz@v0.0.0-20200923083010-c71f680932e2/src/golang.org/x/net/route/syscall.go (about)

     1  // Copyright 2016 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  // +build dragonfly freebsd netbsd openbsd
     6  
     7  package route
     8  
     9  import (
    10  	"syscall"
    11  	"unsafe"
    12  )
    13  
    14  var zero uintptr
    15  
    16  func sysctl(mib []int32, old *byte, oldlen *uintptr, new *byte, newlen uintptr) error {
    17  	var p unsafe.Pointer
    18  	if len(mib) > 0 {
    19  		p = unsafe.Pointer(&mib[0])
    20  	} else {
    21  		p = unsafe.Pointer(&zero)
    22  	}
    23  	_, _, errno := syscall.Syscall6(syscall.SYS___SYSCTL, uintptr(p), uintptr(len(mib)), uintptr(unsafe.Pointer(old)), uintptr(unsafe.Pointer(oldlen)), uintptr(unsafe.Pointer(new)), newlen)
    24  	if errno != 0 {
    25  		return error(errno)
    26  	}
    27  	return nil
    28  }