vclient

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2026 License: MIT Imports: 13 Imported by: 1

Documentation

Overview

Package vclient implements a virtual network client with a user-space TCP/IP stack. It operates at the IP packet level and can be connected to a slirp Stack for testing, or used on any IP-based network.

The client supports DNS, TCP (with retransmission), and UDP, and exposes standard Go interfaces such as Dial, net.Conn, and net.Resolver.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client is a virtual network client operating at the IP packet level.

func New

func New(w slirp.Writer) *Client

New creates a new virtual network client with the given packet writer. The writer is called whenever the client needs to send an IP packet.

func Pipe

func Pipe(stack *slirp.Stack, namespace uintptr) *Client

Pipe creates a Client wired to a slirp Stack. IP packets sent by the client are fed directly to the stack's HandlePacket. Responses from the stack are delivered to the client's HandlePacket.

Use SetIP/SetDNS after Pipe to configure the client's network.

func (*Client) Close

func (c *Client) Close() error

Close shuts down the client and all active connections.

func (*Client) Dial

func (c *Client) Dial(network, address string) (net.Conn, error)

Dial connects to the address on the named network. Supported networks are "tcp", "tcp4", "udp", "udp4".

func (*Client) DialContext

func (c *Client) DialContext(ctx context.Context, network, address string) (net.Conn, error)

DialContext connects to the address on the named network using the provided context.

func (*Client) HTTPClient

func (c *Client) HTTPClient() *http.Client

HTTPClient returns an *http.Client configured to route all traffic through this virtual network client, including DNS resolution via DialContext which internally calls LookupHost.

func (*Client) HandlePacket added in v0.1.3

func (c *Client) HandlePacket(packet []byte) error

HandlePacket processes an incoming IP packet. This is the entry point for packets received from the network (or from a slirp Stack's Writer).

func (*Client) IP

func (c *Client) IP() net.IP

IP returns the client's current IP address.

func (*Client) Listen added in v0.1.2

func (c *Client) Listen(network, address string) (net.Listener, error)

Listen announces on the virtual network address and returns a net.Listener. The network must be "tcp" or "tcp4". The address is "host:port" where host is the client's virtual IP (or empty/"0.0.0.0" for any).

func (*Client) LookupHost

func (c *Client) LookupHost(ctx context.Context, host string) ([]string, error)

LookupHost resolves a hostname to IP addresses using the configured DNS servers.

func (*Client) Resolver

func (c *Client) Resolver() *net.Resolver

Resolver returns a *net.Resolver that uses this client's DNS resolution.

func (*Client) SetDNS

func (c *Client) SetDNS(servers []net.IP)

SetDNS configures the DNS server addresses.

func (*Client) SetIP

func (c *Client) SetIP(ip net.IP, mask net.IPMask, gw net.IP)

SetIP configures a static IP address, subnet mask, and default gateway.

func (*Client) SetWriter

func (c *Client) SetWriter(w slirp.Writer)

SetWriter sets or replaces the packet writer.

type Listener added in v0.1.2

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

Listener is a virtual TCP listener that accepts connections from the virtual network. It implements net.Listener.

func (*Listener) Accept added in v0.1.2

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

Accept waits for and returns the next connection to the listener.

func (*Listener) Addr added in v0.1.2

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

Addr returns the listener's network address.

func (*Listener) Close added in v0.1.2

func (l *Listener) Close() error

Close closes the listener.

type TCPConn

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

TCPConn is a virtual TCP connection implementing net.Conn. It wraps a vtcp.Conn and handles registration/unregistration with the parent Client.

func (*TCPConn) Close

func (tc *TCPConn) Close() error

func (*TCPConn) LocalAddr

func (tc *TCPConn) LocalAddr() net.Addr

func (*TCPConn) Read

func (tc *TCPConn) Read(b []byte) (int, error)

func (*TCPConn) RemoteAddr

func (tc *TCPConn) RemoteAddr() net.Addr

func (*TCPConn) SetDeadline

func (tc *TCPConn) SetDeadline(t time.Time) error

func (*TCPConn) SetReadDeadline

func (tc *TCPConn) SetReadDeadline(t time.Time) error

func (*TCPConn) SetWriteDeadline

func (tc *TCPConn) SetWriteDeadline(t time.Time) error

func (*TCPConn) Write

func (tc *TCPConn) Write(b []byte) (int, error)

type UDPConn

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

UDPConn is a virtual UDP connection implementing net.Conn.

func (*UDPConn) Close

func (u *UDPConn) Close() error

func (*UDPConn) LocalAddr

func (u *UDPConn) LocalAddr() net.Addr

func (*UDPConn) Read

func (u *UDPConn) Read(b []byte) (int, error)

func (*UDPConn) RemoteAddr

func (u *UDPConn) RemoteAddr() net.Addr

func (*UDPConn) SetDeadline

func (u *UDPConn) SetDeadline(t time.Time) error

func (*UDPConn) SetReadDeadline

func (u *UDPConn) SetReadDeadline(t time.Time) error

func (*UDPConn) SetWriteDeadline

func (u *UDPConn) SetWriteDeadline(t time.Time) error

func (*UDPConn) Write

func (u *UDPConn) Write(b []byte) (int, error)

Jump to

Keyboard shortcuts

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