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 ¶
- type Client
- func (c *Client) Addr() netip.Prefix
- func (c *Client) Close() error
- func (c *Client) Dial(network, address string) (net.Conn, error)
- func (c *Client) DialContext(ctx context.Context, network, address string) (net.Conn, error)
- func (c *Client) HTTPClient() *http.Client
- func (c *Client) IP() net.IP
- func (c *Client) Listen(network, address string) (net.Listener, error)
- func (c *Client) LookupHost(ctx context.Context, host string) ([]string, error)
- func (c *Client) Resolver() *net.Resolver
- func (c *Client) Send(pkt pktkit.Packet) error
- func (c *Client) SetAddr(p netip.Prefix) error
- func (c *Client) SetDNS(servers []net.IP)
- func (c *Client) SetDNS6(servers []net.IP)
- func (c *Client) SetHandler(h func(pktkit.Packet) error)
- func (c *Client) SetIP(ip net.IP, mask net.IPMask, gw net.IP)
- func (c *Client) SetIPv6(ip net.IP)
- type Listener
- type TCPConn
- func (tc *TCPConn) Close() error
- func (tc *TCPConn) LocalAddr() net.Addr
- func (tc *TCPConn) Read(b []byte) (int, error)
- func (tc *TCPConn) RemoteAddr() net.Addr
- func (tc *TCPConn) SetDeadline(t time.Time) error
- func (tc *TCPConn) SetReadDeadline(t time.Time) error
- func (tc *TCPConn) SetWriteDeadline(t time.Time) error
- func (tc *TCPConn) Write(b []byte) (int, error)
- type UDPConn
- func (u *UDPConn) Close() error
- func (u *UDPConn) LocalAddr() net.Addr
- func (u *UDPConn) Read(b []byte) (int, error)
- func (u *UDPConn) RemoteAddr() net.Addr
- func (u *UDPConn) SetDeadline(t time.Time) error
- func (u *UDPConn) SetReadDeadline(t time.Time) error
- func (u *UDPConn) SetWriteDeadline(t time.Time) error
- func (u *UDPConn) Write(b []byte) (int, error)
- type UDPConn6
- func (u *UDPConn6) Close() error
- func (u *UDPConn6) LocalAddr() net.Addr
- func (u *UDPConn6) Read(b []byte) (int, error)
- func (u *UDPConn6) RemoteAddr() net.Addr
- func (u *UDPConn6) SetDeadline(t time.Time) error
- func (u *UDPConn6) SetReadDeadline(t time.Time) error
- func (u *UDPConn6) SetWriteDeadline(t time.Time) error
- func (u *UDPConn6) Write(b []byte) (int, error)
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. It implements pktkit.L3Device.
func New ¶
func New() *Client
New creates a new virtual network client. Use SetHandler to wire it for packet delivery before use.
func (*Client) Addr ¶
Addr returns the client's current IP prefix. Implements pktkit.L3Device.
func (*Client) Dial ¶
Dial connects to the address on the named network. Supported networks are "tcp", "tcp4", "udp", "udp4".
func (*Client) DialContext ¶
DialContext connects to the address on the named network using the provided context.
func (*Client) HTTPClient ¶
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) Listen ¶
Listen announces on the virtual network address and returns a net.Listener. The network must be "tcp", "tcp4", or "tcp6". The address is "host:port" where host is the client's virtual IP (or empty/"0.0.0.0"/"::" for any).
func (*Client) LookupHost ¶
LookupHost resolves a hostname to IP addresses using the configured DNS servers.
func (*Client) Send ¶
Send delivers an IP packet to the client for processing. Implements pktkit.L3Device.
func (*Client) SetAddr ¶
SetAddr configures the client's IP prefix (updates IP and mask). Implements pktkit.L3Device.
func (*Client) SetHandler ¶
SetHandler sets the callback for packets produced by this client. Implements pktkit.L3Device.
type Listener ¶
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.
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) RemoteAddr ¶
type UDPConn ¶
type UDPConn struct {
// contains filtered or unexported fields
}
UDPConn is a virtual UDP connection implementing net.Conn.
func (*UDPConn) RemoteAddr ¶
type UDPConn6 ¶
type UDPConn6 struct {
// contains filtered or unexported fields
}
UDPConn6 is a virtual IPv6 UDP connection implementing net.Conn.