mirror of https://github.com/subgraph/fw-daemon
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
516 B
26 lines
516 B
package ipc
|
|
|
|
import (
|
|
"reflect"
|
|
"syscall"
|
|
)
|
|
|
|
func setPassCred(c interface{}) error {
|
|
fd := reflectFD(c)
|
|
return syscall.SetsockoptInt(fd, syscall.SOL_SOCKET, syscall.SO_PASSCRED, 1)
|
|
}
|
|
|
|
func reflectFD(c interface{}) int {
|
|
sysfd := extractField(c, "fd", "sysfd")
|
|
return int(sysfd.Int())
|
|
}
|
|
|
|
func extractField(ob interface{}, fieldNames ...string) reflect.Value {
|
|
v := reflect.Indirect(reflect.ValueOf(ob))
|
|
for _, fn := range fieldNames {
|
|
field := v.FieldByName(fn)
|
|
v = reflect.Indirect(field)
|
|
}
|
|
return v
|
|
}
|