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 messages
package syscall
import
// 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
}
The pages are generated with Golds v0.6.7. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |