// Use of this source code is governed by a BSD-style// license that can be found in the LICENSE file.// Socket control messagespackageuniximport"unsafe"// UnixCredentials encodes credentials into a socket control message// for sending to another process. This can be used for// authentication.funcUnixCredentials(ucred*Ucred)[]byte{b:=make([]byte,CmsgSpace(SizeofUcred))h:=(*Cmsghdr)(unsafe.Pointer(&b[0]))h.Level=SOL_SOCKETh.Type=SCM_CREDENTIALSh.SetLen(CmsgLen(SizeofUcred))*((*Ucred)(cmsgData(h)))=*ucredreturnb}// ParseUnixCredentials decodes a socket control message that contains// credentials in a Ucred structure. To receive such a message, the// SO_PASSCRED option must be enabled on the socket.funcParseUnixCredentials(m*SocketControlMessage)(*Ucred,error){ifm.Header.Level!=SOL_SOCKET{returnnil,EINVAL}ifm.Header.Type!=SCM_CREDENTIALS{returnnil,EINVAL}ucred:=*(*Ucred)(unsafe.Pointer(&m.Data[0]))return&ucred,nil}