Source File
sockcmsg_linux.go
Belonging Package
syscall
// Copyright 2011 The Go Authors. All rights reserved.// Use of this source code is governed by a BSD-style// license that can be found in the LICENSE file.// Socket control messagespackage syscallimport// UnixCredentials encodes credentials into a socket control message// for sending to another process. This can be used for// authentication.func ( *Ucred) []byte {:= make([]byte, CmsgSpace(SizeofUcred)):= (*Cmsghdr)(unsafe.Pointer(&[0])).Level = SOL_SOCKET.Type = SCM_CREDENTIALS.SetLen(CmsgLen(SizeofUcred))*(*Ucred)(.data(0)) = *return}// 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.func ( *SocketControlMessage) (*Ucred, error) {if .Header.Level != SOL_SOCKET {return nil, EINVAL}if .Header.Type != SCM_CREDENTIALS {return nil, EINVAL}if uintptr(len(.Data)) < unsafe.Sizeof(Ucred{}) {return nil, EINVAL}:= *(*Ucred)(unsafe.Pointer(&.Data[0]))return &, nil}