Source file
src/syscall/sockcmsg_linux.go
1
2
3
4
5
6
7 package syscall
8
9 import "unsafe"
10
11
12
13
14 func UnixCredentials(ucred *Ucred) []byte {
15 b := make([]byte, CmsgSpace(SizeofUcred))
16 h := (*Cmsghdr)(unsafe.Pointer(&b[0]))
17 h.Level = SOL_SOCKET
18 h.Type = SCM_CREDENTIALS
19 h.SetLen(CmsgLen(SizeofUcred))
20 *(*Ucred)(h.data(0)) = *ucred
21 return b
22 }
23
24
25
26
27 func ParseUnixCredentials(m *SocketControlMessage) (*Ucred, error) {
28 if m.Header.Level != SOL_SOCKET {
29 return nil, EINVAL
30 }
31 if m.Header.Type != SCM_CREDENTIALS {
32 return nil, EINVAL
33 }
34 if uintptr(len(m.Data)) < unsafe.Sizeof(Ucred{}) {
35 return nil, EINVAL
36 }
37 ucred := *(*Ucred)(unsafe.Pointer(&m.Data[0]))
38 return &ucred, nil
39 }
40
View as plain text