qemu

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package qemu implements QEMU's userspace network socket protocol.

QEMU's -netdev socket (and the newer -netdev stream) uses a simple L2 framing protocol over stream sockets: each Ethernet frame is prefixed with a 4-byte big-endian uint32 length. There is no handshake.

This package provides Conn, an pktkit.L2Device that wraps any stream-oriented net.Conn (TCP or Unix). Use Dial and Listen for TCP/Unix client-server setups, or Socketpair for an in-process pair connected via OS socketpair(2).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Conn

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

Conn wraps a stream connection and implements pktkit.L2Device. Each Ethernet frame is length-prefixed with a 4-byte big-endian uint32.

func Dial

func Dial(network, address string) (*Conn, error)

Dial connects to a QEMU socket netdev at the given address and returns a Conn implementing pktkit.L2Device. Network must be "tcp", "tcp4", "tcp6", or "unix".

func Socketpair

func Socketpair() (a, b *Conn, err error)

Socketpair creates a pair of connected Conn values using OS socketpair(2). Both ends implement pktkit.L2Device.

func (*Conn) Close

func (c *Conn) Close() error

Close shuts down the connection and stops the read goroutine.

func (*Conn) Done

func (c *Conn) Done() <-chan struct{}

Done returns a channel that is closed when the connection is closed. This allows pktkit.Serve to detect disconnection and trigger cleanup.

func (*Conn) HWAddr

func (c *Conn) HWAddr() net.HardwareAddr

HWAddr returns the connection's MAC address.

func (*Conn) Send

func (c *Conn) Send(f pktkit.Frame) error

Send writes an Ethernet frame to the connection, prefixed with its 4-byte big-endian length. Safe for concurrent use.

func (*Conn) SetHandler

func (c *Conn) SetHandler(h func(pktkit.Frame) error)

SetHandler sets the callback invoked for each received Ethernet frame. The Frame is only valid for the duration of the callback.

type Listener

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

Listener accepts incoming QEMU socket connections.

func Listen

func Listen(network, address string) (*Listener, error)

Listen creates a Listener on the given network and address. Network must be "tcp", "tcp4", "tcp6", or "unix".

func (*Listener) Accept

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

Accept waits for and returns the next connection as a Conn implementing pktkit.L2Device.

func (*Listener) AcceptL2

func (l *Listener) AcceptL2() (pktkit.L2Device, error)

AcceptL2 implements pktkit.L2Acceptor. It accepts a connection and returns it as an pktkit.L2Device.

func (*Listener) Addr

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

Addr returns the listener's network address.

func (*Listener) Close

func (l *Listener) Close() error

Close closes the listener.

Jump to

Keyboard shortcuts

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