vsock

package
v0.1.9 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// AF_VSOCK is the address family for vsock
	AF_VSOCK = 40

	// VMADDR_CID_ANY accepts connections from any CID
	VMADDR_CID_ANY = 0xFFFFFFFF
	// VMADDR_CID_HYPERVISOR is the CID for the hypervisor (host from guest perspective)
	VMADDR_CID_HYPERVISOR = 0
	// VMADDR_CID_LOCAL is the CID for local communication
	VMADDR_CID_LOCAL = 1
	// VMADDR_CID_HOST is the CID for the host
	VMADDR_CID_HOST = 2

	// VMADDR_PORT_ANY accepts connections on any port
	VMADDR_PORT_ANY = 0xFFFFFFFF

	// IOCTL_VM_SOCKETS_GET_LOCAL_CID gets the local CID
	IOCTL_VM_SOCKETS_GET_LOCAL_CID = 0x7B9
)
View Source
const (
	MsgTypeExec       uint8 = 1
	MsgTypeExecResult uint8 = 2
	MsgTypeStdout     uint8 = 3
	MsgTypeStderr     uint8 = 4
	MsgTypeSignal     uint8 = 5
	MsgTypeReady      uint8 = 6
	MsgTypeStdin      uint8 = 7  // TTY: stdin data from host
	MsgTypeResize     uint8 = 8  // TTY: window resize
	MsgTypeExecTTY    uint8 = 9  // TTY: exec with PTY
	MsgTypeExit       uint8 = 10 // TTY: process exited
	MsgTypeExecStream uint8 = 11 // Streaming batch: stdout/stderr sent as chunks, then ExecResult
)

Protocol for command execution over vsock

Variables

This section is empty.

Functions

func GetLocalCID

func GetLocalCID() (uint32, error)

GetLocalCID returns the local CID of the machine

func ReadMessage

func ReadMessage(conn *Conn) (uint8, []byte, error)

ReadMessage reads a length-prefixed message from the connection

func WriteMessage

func WriteMessage(conn *Conn, msgType uint8, data []byte) error

WriteMessage writes a length-prefixed message to the connection

Types

type Addr

type Addr struct {
	CID  uint32
	Port uint32
}

Addr represents a vsock address

func (*Addr) Network

func (a *Addr) Network() string

func (*Addr) String

func (a *Addr) String() string

type Conn

type Conn struct {
	// contains filtered or unexported fields
}

Conn represents a vsock connection

func Dial

func Dial(cid, port uint32) (*Conn, error)

Dial connects to a vsock address

func (*Conn) Close

func (c *Conn) Close() error

func (*Conn) File

func (c *Conn) File() *os.File

func (*Conn) LocalAddr

func (c *Conn) LocalAddr() net.Addr

func (*Conn) Read

func (c *Conn) Read(b []byte) (int, error)

func (*Conn) RemoteAddr

func (c *Conn) RemoteAddr() net.Addr

func (*Conn) SetDeadline

func (c *Conn) SetDeadline(t interface{}) error

func (*Conn) SetReadDeadline

func (c *Conn) SetReadDeadline(t interface{}) error

func (*Conn) SetWriteDeadline

func (c *Conn) SetWriteDeadline(t interface{}) error

func (*Conn) Write

func (c *Conn) Write(b []byte) (int, error)

type ExecRequest

type ExecRequest struct {
	Command    string            `json:"command"`
	Args       []string          `json:"args,omitempty"`
	WorkingDir string            `json:"working_dir,omitempty"`
	Env        map[string]string `json:"env,omitempty"`
	Stdin      []byte            `json:"stdin,omitempty"`
}

ExecRequest is sent from host to guest to execute a command

type ExecResponse

type ExecResponse struct {
	ExitCode int    `json:"exit_code"`
	Stdout   []byte `json:"stdout,omitempty"`
	Stderr   []byte `json:"stderr,omitempty"`
	Error    string `json:"error,omitempty"`
}

ExecResponse is sent from guest to host with execution results

type ExecTTYRequest

type ExecTTYRequest struct {
	Command    string            `json:"command"`
	Args       []string          `json:"args,omitempty"`
	WorkingDir string            `json:"working_dir,omitempty"`
	Env        map[string]string `json:"env,omitempty"`
	Rows       uint16            `json:"rows"`
	Cols       uint16            `json:"cols"`
}

ExecTTYRequest is sent from host to guest for interactive execution

type Listener

type Listener struct {
	// contains filtered or unexported fields
}

Listener represents a vsock listener

func Listen

func Listen(port uint32) (*Listener, error)

Listen creates a vsock listener on the given port

func ListenCID

func ListenCID(cid, port uint32) (*Listener, error)

ListenCID creates a vsock listener on the given CID and port

func (*Listener) Accept

func (l *Listener) Accept() (*Conn, error)

func (*Listener) Addr

func (l *Listener) Addr() net.Addr

func (*Listener) Close

func (l *Listener) Close() error

type WindowSize

type WindowSize struct {
	Rows uint16 `json:"rows"`
	Cols uint16 `json:"cols"`
}

WindowSize represents terminal dimensions

Jump to

Keyboard shortcuts

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