unixsocket

package
v0.7.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 30, 2021 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package unixsocket provides wrapper for Linux unix socket to send and recv oob messages including fd and user credential.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewSocketPair

func NewSocketPair() (*Socket, *Socket, error)

NewSocketPair creates connected unix socketpair using SOCK_SEQPACKET

Types

type Msg

type Msg struct {
	Fds  []int          // unix rights
	Cred *syscall.Ucred // unix credential
}

Msg is the oob msg with the message

type Socket

type Socket net.UnixConn

Socket wrappers a unix socket connection

func NewSocket

func NewSocket(fd int) (*Socket, error)

NewSocket creates Socket conn struct using existing unix socket fd creates by socketpair or net.DialUnix and mark it as close_on_exec (avoid fd leak) it need SOCK_SEQPACKET socket for reliable transfer it will need SO_PASSCRED to pass unix credential, Notice: in the documentation, if cred is not specified, self information will be sent

func (*Socket) RecvMsg

func (s *Socket) RecvMsg(b []byte) (int, Msg, error)

RecvMsg recvmsg from unix socket and parse possible unix right / credential

func (*Socket) SendMsg

func (s *Socket) SendMsg(b []byte, m Msg) error

SendMsg sendmsg to unix socket and encode possible unix right / credential

func (*Socket) SetPassCred

func (s *Socket) SetPassCred(option int) error

SetPassCred set sockopt for pass cred for unix socket

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL