Documentation
¶
Index ¶
- Constants
- Variables
- func BaseOnBind(ctx context.Context, conn net.Conn, req *Request, ...) error
- func BaseOnConnect(ctx context.Context, conn net.Conn, req *Request, dialer socksnet.Dialer, ...) error
- func BaseOnHandshake(ctx context.Context, conn net.Conn, req *HandshakeRequest, ...) (byte, error)
- func BaseOnRequest(ctx context.Context, handler ServerHandler, conn net.Conn, req *Request) error
- func BaseOnResolve(ctx context.Context, conn net.Conn, req *Request, dialer socksnet.Dialer, ...) error
- func BaseOnUDPAssociate(ctx context.Context, conn net.Conn, req *Request, timeout time.Duration, ...) error
- func ListenAndServe(ctx context.Context, network, address string, handler ServerHandler) error
- func ResolveSelectBestIP(ips []net.IP, preferIPv4 bool) net.IP
- func Serve(ctx context.Context, listener net.Listener, handler ServerHandler) error
- func ServeConn(ctx context.Context, handler ServerHandler, conn net.Conn) error
- func WriteHandshake(conn net.Conn, code byte) error
- func WriteRejectReply(conn net.Conn, code byte)
- func WriteSuccessReply(conn net.Conn, addr net.Addr) error
- type Auth
- type BaseServerHandler
- func (d *BaseServerHandler) GetSupportedMethods() []byte
- func (d *BaseServerHandler) OnAccept(ctx context.Context, conn net.Conn) error
- func (d *BaseServerHandler) OnAuthGSSAPI(ctx context.Context, conn net.Conn, token []byte) ([]byte, bool, error)
- func (d *BaseServerHandler) OnAuthUserPass(ctx context.Context, conn net.Conn, username, password string) error
- func (d *BaseServerHandler) OnBind(ctx context.Context, conn net.Conn, req *Request) error
- func (d *BaseServerHandler) OnConnect(ctx context.Context, conn net.Conn, req *Request) error
- func (d *BaseServerHandler) OnError(ctx context.Context, conn net.Conn, err error)
- func (d *BaseServerHandler) OnHandshake(ctx context.Context, conn net.Conn, req *HandshakeRequest) (byte, error)
- func (d *BaseServerHandler) OnPanic(ctx context.Context, conn net.Conn, r any)
- func (d *BaseServerHandler) OnRequest(ctx context.Context, conn net.Conn, req *Request) error
- func (d *BaseServerHandler) OnResolve(ctx context.Context, conn net.Conn, req *Request) error
- func (d *BaseServerHandler) OnUDPAssociate(ctx context.Context, conn net.Conn, req *Request) error
- type Dialer
- func (d *Dialer) Bind(network, address string) (net.Conn, *net.TCPAddr, <-chan error, error)
- func (d *Dialer) BindContext(ctx context.Context, network, address string) (net.Conn, *net.TCPAddr, <-chan error, error)
- func (d *Dialer) Dial(network, address string) (net.Conn, error)
- func (d *Dialer) DialConn(conn net.Conn, network, address string) (net.Conn, error)
- func (d *Dialer) DialConnContext(ctx context.Context, conn net.Conn, network, address string) (net.Conn, error)
- func (d *Dialer) DialContext(ctx context.Context, network, address string) (net.Conn, error)
- func (d *Dialer) ListenPacket(ctx context.Context, network string, laddr *net.UDPAddr) (net.PacketConn, error)
- func (d *Dialer) ProxyAddress() string
- func (d *Dialer) ResolveContext(ctx context.Context, network, host string) (net.IP, error)
- func (d *Dialer) UDPAssociate(network string, clientAddr *net.UDPAddr) (net.Conn, *net.UDPAddr, error)
- func (d *Dialer) UDPAssociateContext(ctx context.Context, network string, clientAddr *net.UDPAddr) (net.Conn, *net.UDPAddr, error)
- type GSSAPIAuth
- type GSSAPIContext
- type GSSAPIReply
- type GSSAPIRequest
- type HandshakeReply
- type HandshakeRequest
- type Reply
- func (r *Reply) Addr() string
- func (r *Reply) GetHost() string
- func (r *Reply) Init(version, rep, reserved, addrType byte, ip net.IP, domain string, port uint16)
- func (r *Reply) ReadFrom(src io.Reader) (int64, error)
- func (r *Reply) String() string
- func (r *Reply) Validate() error
- func (r *Reply) ValidateHeader() error
- func (r *Reply) WriteTo(dst io.Writer) (int64, error)
- type Request
- func (r *Request) Addr() string
- func (r *Request) GetHost() string
- func (r *Request) Init(version byte, command byte, reserved byte, addrType byte, ip net.IP, ...)
- func (r *Request) ReadFrom(src io.Reader) (int64, error)
- func (r *Request) String() string
- func (r *Request) Validate() error
- func (r *Request) ValidateHeader() error
- func (r *Request) WriteTo(dst io.Writer) (int64, error)
- type ServerHandler
- type UDPConn
- func (c *UDPConn) Close() error
- func (c *UDPConn) LocalAddr() net.Addr
- func (c *UDPConn) ReadFrom(p []byte) (int, net.Addr, error)
- func (c *UDPConn) SetDeadline(t time.Time) error
- func (c *UDPConn) SetReadDeadline(t time.Time) error
- func (c *UDPConn) SetWriteDeadline(t time.Time) error
- func (c *UDPConn) WriteTo(p []byte, addr net.Addr) (int, error)
- type UDPPacket
- func (p *UDPPacket) Init(reserved [2]byte, frag byte, addrType byte, ip net.IP, domain string, ...)
- func (p *UDPPacket) MarshalTo(b []byte) (int, error)
- func (p *UDPPacket) Size() int
- func (p *UDPPacket) String() string
- func (p *UDPPacket) UnmarshalFrom(b []byte) (int, error)
- func (p *UDPPacket) Validate() error
- func (p *UDPPacket) ValidateHeader() error
- type UserPassReply
- type UserPassRequest
Constants ¶
const ( CmdConnect = 1 CmdBind = 2 CmdUDPAssociate = 3 CmdResolve = 0xF0 CmdResolvePTR = 0xF1 )
Command codes (CMD) for client requests.
const ( AddrTypeIPv4 = 1 AddrTypeDomain = 3 AddrTypeIPv6 = 4 )
Address types (ATYP) used in requests and responses.
const ( RepSuccess = 0 RepGeneralFailure = 1 RepConnectionNotAllowed = 2 RepNetworkUnreachable = 3 RepHostUnreachable = 4 RepConnectionRefused = 5 RepTTLExpired = 6 RepCommandNotSupported = 7 RepAddrTypeNotSupported = 8 )
Reply codes (REP) for server responses.
const ( MethodNoAuth = 0x00 MethodGSSAPI = 0x01 MethodUserPass = 0x02 MethodNoAcceptable = 0xFF )
Authentication methods (METHOD) for initial greeting.
const ( GSSAPITypeInit = 0x01 GSSAPITypeReply = 0x02 GSSAPITypeAbort = 0xFF )
GSS-API message types (MTYP)
const ( UserPassStatusSuccess = 0x00 UserPassStatusFailure = 0x01 )
Username/password authentication status codes.
const ( GSSAPIStatusSuccess = GSSAPITypeReply // 0x02 GSSAPIStatusFailure = GSSAPITypeAbort // 0xFF )
GSSAPI authentication status (using MsgType values).
const (
AuthVersionUserPass = 1
)
Authentication sub-negotiation versions.
const (
GSSAPIVersion = 1
)
GSS-API protocol version. (VER)
const (
SocksVersion = 5
)
Protocol version.
Variables ¶
var ( ErrInvalidGSSAPIReplyVersion = errors.New("invalid GSSAPI reply version (must be 1)") ErrInvalidGSSAPIMsgType = errors.New("invalid GSSAPI message type") ErrGSSAPIReplyTooLong = errors.New("GSSAPI reply token too long (max 65535)") )
Errors for GSSAPI authentication replies.
var ( ErrInvalidGSSAPIVersion = errors.New("invalid GSSAPI version (must be 1)") ErrGSSAPITokenTooLong = errors.New("GSSAPI token too long (max 65535)") )
Errors for GSSAPI authentication requests.
var ( ErrInvalidHandshakeVersion = errors.New("invalid SOCKS version (must be 5)") ErrTooManyMethods = errors.New("too many authentication methods") ErrNoMethodsProvided = errors.New("no authentication methods provided") )
Errors for SOCKS5 handshake requests.
var ( ErrInvalidReplyVersion = errors.New("invalid SOCKS version in reply (must be 5)") ErrInvalidReplyRSV = errors.New("invalid reserved byte in reply (must be 0x00)") ErrInvalidReplyAddr = errors.New("invalid address or address type in reply") ErrInvalidReplyDomain = errors.New("invalid domain in reply (empty or too long)") )
Common validation errors for replies.
var ( ErrInvalidVersion = errors.New("invalid SOCKS version (must be 5)") ErrInvalidCommand = errors.New("invalid command (must be 1=CONNECT, 2=BIND, 3=UDP ASSOCIATE, F0=RESOLVE, or F1=RESOLVE_PTR)") ErrInvalidAddr = errors.New("invalid address or address type") ErrInvalidDomain = errors.New("invalid domain (empty or too long)") ErrInvalidRSV = errors.New("invalid reserved byte (must be 0x00)") )
Common validation errors.
var ( ErrInvalidUDPReserved = errors.New("invalid UDP reserved bytes (must be 0x0000)") ErrUnsupportedFrag = errors.New("unsupported UDP fragmentation (FRAG must be 0x00)") ErrInvalidUDPAddrType = errors.New("invalid UDP address type") ErrInvalidUDPDomain = errors.New("invalid UDP domain (empty or too long)") ErrMissingUDPData = errors.New("missing UDP payload data") )
Common validation errors for UDP packets.
var ( ErrInvalidUserPassVersion = errors.New("invalid user/password auth version (must be 1)") ErrEmptyUserPassUsername = errors.New("username cannot be empty") ErrEmptyUserPassPassword = errors.New("password cannot be empty") ErrUserPassTooLong = errors.New("username or password too long (max 255)") )
Errors for username/password authentication requests.
var (
ErrInvalidHandshakeReplyVersion = errors.New("invalid SOCKS version in handshake reply (must be 5)")
)
Errors for SOCKS5 handshake replies.
var (
ErrInvalidUserPassReplyVersion = errors.New("invalid user/password reply version (must be 1)")
)
Errors for username/password authentication replies.
Functions ¶
func BaseOnBind ¶
func BaseOnBind(ctx context.Context, conn net.Conn, req *Request, acceptTimeout, connTimeout time.Duration, bufferSize int) error
BaseOnBind provides BIND implementation
func BaseOnConnect ¶
func BaseOnConnect(ctx context.Context, conn net.Conn, req *Request, dialer socksnet.Dialer, connTimeout time.Duration, bufferSize int) error
BaseOnConnect provides CONNECT implementation
func BaseOnHandshake ¶
func BaseOnHandshake(ctx context.Context, conn net.Conn, req *HandshakeRequest, supportedMethods []byte) (byte, error)
BaseOnHandshake provides a default handshake implementation that selects the first matching authentication method.
func BaseOnRequest ¶
BaseOnRequest provides request handling logic for CONNECT, BIND, UDP ASSOCIATE, and RESOLVE commands.
func BaseOnResolve ¶
func BaseOnResolve( ctx context.Context, conn net.Conn, req *Request, dialer socksnet.Dialer, resolver *net.Resolver, preferIPv4 bool, connTimeout time.Duration, bufferSize int, ) error
BaseOnResolve provides RESOLVE implementation
func BaseOnUDPAssociate ¶
func BaseOnUDPAssociate( ctx context.Context, conn net.Conn, req *Request, timeout time.Duration, bufferSize int, laddr *net.UDPAddr, ) error
BaseOnUDPAssociate provides UDP ASSOCIATE implementation
func ListenAndServe ¶
func ListenAndServe(ctx context.Context, network, address string, handler ServerHandler) error
ListenAndServe listens on the network address and serves SOCKS5 requests.
func ResolveSelectBestIP ¶
ResolveSelectBestIP selects the most appropriate IP address from a list based on preferences
func ServeConn ¶
ServeConn handles a single client connection, including handshake, authentication, and request processing.
func WriteHandshake ¶
WriteHandshake sends a SOCKS5 handshake reply with the given code.
func WriteRejectReply ¶
WriteRejectReply sends a SOCKS5 reply with the given rejection code.
Types ¶
type BaseServerHandler ¶
type BaseServerHandler struct {
Dialer socksnet.Dialer
RequestTimeout time.Duration
BindAcceptTimeout time.Duration
BindConnTimeout time.Duration
ConnectConnTimeout time.Duration
UDPAssociateTimeout time.Duration
ConnectBufferSize int
UDPAssociateBufferSize int
AllowConnect bool
AllowBind bool
AllowUDPAssociate bool
AllowResolve bool
ResolveResolver *net.Resolver
ResolvePreferIPv4 bool // When true, prefer IPv4 addresses over IPv6 for DNS resolution
SupportedMethods []byte
UserPassAuthenticator func(ctx context.Context, username, password string) error
GSSAPIAuthenticator func(ctx context.Context, token []byte) (resp []byte, done bool, err error)
UDPAssociateLocalAddr func(ctx context.Context, conn net.Conn, req *Request) (*net.UDPAddr, error)
}
BaseServerHandler provides a basic implementation of ServerHandler with configurable options.
func (*BaseServerHandler) GetSupportedMethods ¶
func (d *BaseServerHandler) GetSupportedMethods() []byte
GetSupportedMethods returns the supported authentication methods.
func (*BaseServerHandler) OnAuthGSSAPI ¶
func (*BaseServerHandler) OnAuthUserPass ¶
func (*BaseServerHandler) OnHandshake ¶
func (d *BaseServerHandler) OnHandshake(ctx context.Context, conn net.Conn, req *HandshakeRequest) (byte, error)
func (*BaseServerHandler) OnUDPAssociate ¶
type Dialer ¶
type Dialer struct {
ProxyAddr string
Auth *Auth
GSSAPIAuth *GSSAPIAuth
Dialer socksnet.Dialer
}
Dialer implements a SOCKS5 proxy dialer.
func NewDialerWithGSSAPI ¶
func NewDialerWithGSSAPI(proxyAddr string, auth *Auth, gssapiAuth *GSSAPIAuth, dialer socksnet.Dialer) *Dialer
NewDialerWithGSSAPI creates a new SOCKS5 dialer instance with GSSAPI support.
func (*Dialer) BindContext ¶
func (d *Dialer) BindContext( ctx context.Context, network, address string, ) (net.Conn, *net.TCPAddr, <-chan error, error)
BindContext establishes a passive BIND connection via SOCKS5 proxy.
func (*Dialer) DialConnContext ¶
func (d *Dialer) DialConnContext(ctx context.Context, conn net.Conn, network, address string) (net.Conn, error)
DialConnContext upgrades an existing connection via SOCKS5 proxy (CONNECT command).
func (*Dialer) DialContext ¶
DialContext establishes a connection via SOCKS5 proxy (CONNECT command).
func (*Dialer) ListenPacket ¶
func (d *Dialer) ListenPacket(ctx context.Context, network string, laddr *net.UDPAddr) (net.PacketConn, error)
ListenPacket establishes a UDP association and returns a PacketConn for sending/receiving UDP packets via the SOCKS5 proxy.
func (*Dialer) ProxyAddress ¶
ProxyAddress returns the configured SOCKS5 proxy address.
func (*Dialer) ResolveContext ¶
ResolveContext resolves a hostname via SOCKS5 proxy (Tor-style extension).
type GSSAPIAuth ¶
type GSSAPIAuth struct {
Context GSSAPIContext
}
GSSAPIAuth holds GSSAPI authentication context.
type GSSAPIContext ¶
type GSSAPIContext interface {
// InitSecContext generates initial GSSAPI token
InitSecContext() ([]byte, error)
// AcceptSecContext processes server tokens and generates response
// Returns: (responseToken, authComplete, error)
AcceptSecContext(serverToken []byte) ([]byte, bool, error)
// IsComplete returns true when authentication is finished
IsComplete() bool
}
GSSAPIContext interface for GSSAPI authentication operations.
type GSSAPIReply ¶
type GSSAPIReply struct {
Version byte // VER (should always be 0x01)
MsgType byte // MTYP (0x02 = reply token, 0xFF = failure)
Token []byte // TOKEN (optional; may be empty for final success)
}
GSSAPIReply represents a GSSAPI authentication reply message (RFC 1961 §3.7).
func (*GSSAPIReply) Init ¶
func (r *GSSAPIReply) Init(version, msgType byte, token []byte)
Init initializes the GSSAPI reply.
func (*GSSAPIReply) ReadFrom ¶
func (r *GSSAPIReply) ReadFrom(src io.Reader) (int64, error)
ReadFrom reads a GSSAPI reply from a reader.
func (*GSSAPIReply) String ¶
func (r *GSSAPIReply) String() string
String returns a human-readable representation.
func (*GSSAPIReply) Validate ¶
func (r *GSSAPIReply) Validate() error
Validate checks for protocol correctness.
type GSSAPIRequest ¶
type GSSAPIRequest struct {
Version byte // VER (should always be 0x01)
MsgType byte // MTYP (0x01 = initial token)
Token []byte // TOKEN (opaque GSSAPI token)
}
GSSAPIRequest represents a GSSAPI authentication request (RFC 1961 §3.4).
func (*GSSAPIRequest) Init ¶
func (r *GSSAPIRequest) Init(version, msgType byte, token []byte)
Init initializes a GSSAPI authentication request.
func (*GSSAPIRequest) ReadFrom ¶
func (r *GSSAPIRequest) ReadFrom(src io.Reader) (int64, error)
ReadFrom reads a GSSAPI authentication request from a reader.
func (*GSSAPIRequest) String ¶
func (r *GSSAPIRequest) String() string
String returns a human-readable representation.
func (*GSSAPIRequest) Validate ¶
func (r *GSSAPIRequest) Validate() error
Validate checks for protocol correctness.
type HandshakeReply ¶
type HandshakeReply struct {
Version byte // VER (should always be 0x05)
Method byte // METHOD; selected authentication method
}
HandshakeReply represents the server’s response to a SOCKS5 handshake request.
func (*HandshakeReply) Init ¶
func (h *HandshakeReply) Init(version byte, method byte)
Init initializes a handshake reply with the given method.
func (*HandshakeReply) ReadFrom ¶
func (h *HandshakeReply) ReadFrom(src io.Reader) (int64, error)
ReadFrom reads a SOCKS5 handshake reply from an io.Reader. Implements io.ReaderFrom.
func (*HandshakeReply) String ¶
func (h *HandshakeReply) String() string
String returns a human-readable representation of the handshake reply.
func (*HandshakeReply) Validate ¶
func (h *HandshakeReply) Validate() error
Validate ensures the handshake reply is valid.
type HandshakeRequest ¶
type HandshakeRequest struct {
Version byte // VER (should always be 0x05)
NMethods byte // NMETHODS; number of methods
Methods []byte // METHODS; list of supported methods
}
HandshakeRequest represents the initial SOCKS5 client handshake (method negotiation).
func (*HandshakeRequest) Init ¶
func (h *HandshakeRequest) Init(version byte, methods ...byte)
Init initializes a handshake request with the given methods.
func (*HandshakeRequest) ReadFrom ¶
func (h *HandshakeRequest) ReadFrom(src io.Reader) (int64, error)
ReadFrom reads a SOCKS5 handshake request from an io.Reader. Implements io.ReaderFrom.
func (*HandshakeRequest) String ¶
func (h *HandshakeRequest) String() string
String returns a human-readable representation of the handshake request.
func (*HandshakeRequest) Validate ¶
func (h *HandshakeRequest) Validate() error
Validate ensures the handshake request is structurally valid.
type Reply ¶
type Reply struct {
Version byte // VER; SOCKS protocol version (always 5)
Reply byte // REP; reply code
Reserved byte // RSV; must be 0x00
AddrType byte // ATYP; address type (IPv4, DOMAIN, IPv6)
IP net.IP // BND.ADDR; Bound IP (if IPv4/IPv6)
Domain string // BND.ADDR; Bound domain (if ATYP=DOMAIN)
Port uint16 // BND.PORT; Bound port
}
Reply represents a SOCKS5 server reply.
func (*Reply) ValidateHeader ¶
ValidateHeader validates the reply header fields.
type Request ¶
type Request struct {
Version byte // VER; SOCKS protocol version (always 5)
Command byte // CMD; CONNECT, BIND, UDP ASSOCIATE, RESOLVE, etc.
Reserved byte // RSV; reserved byte (must be 0x00)
AddrType byte // ATYP; address type (IPv4, DOMAIN, IPv6)
IP net.IP // BND.ADDR; Destination IP (IPv4 or IPv6)
Domain string // BND.ADDR; Destination domain (if ATYP=DOMAIN)
Port uint16 // BND.PORT; Destination port (big-endian)
}
Request represents a SOCKS5 CONNECT/BIND/UDP ASSOCIATE/RESOLVE request.
func (*Request) Init ¶
func (r *Request) Init( version byte, command byte, reserved byte, addrType byte, ip net.IP, domain string, port uint16, )
Init initializes a SOCKS5 request.
func (*Request) ReadFrom ¶
ReadFrom reads a SOCKS5 request from a Reader. Implements the io.ReaderFrom interface.
func (*Request) ValidateHeader ¶
ValidateHeader validates the SOCKS5 request header.
type ServerHandler ¶
type ServerHandler interface {
// OnAccept is called for each accepted connection.
OnAccept(ctx context.Context, conn net.Conn) error
// OnHandshake is called during method negotiation phase.
OnHandshake(ctx context.Context, conn net.Conn, req *HandshakeRequest) (selectedMethod byte, err error)
// OnAuthUserPass is called for username/password authentication.
OnAuthUserPass(ctx context.Context, conn net.Conn, username, password string) error
// OnAuthGSSAPI is called for GSSAPI authentication.
OnAuthGSSAPI(ctx context.Context, conn net.Conn, token []byte) (resp []byte, done bool, err error)
// OnRequest is called for each SOCKS5 request after successful handshake/auth.
OnRequest(ctx context.Context, conn net.Conn, req *Request) error
// OnConnect is called for each CONNECT request.
OnConnect(ctx context.Context, conn net.Conn, req *Request) error
// OnBind is called for each BIND request.
OnBind(ctx context.Context, conn net.Conn, req *Request) error
// OnUDPAssociate is called for each UDP ASSOCIATE request.
OnUDPAssociate(ctx context.Context, conn net.Conn, req *Request) error
// OnResolve is called for each RESOLVE request.
OnResolve(ctx context.Context, conn net.Conn, req *Request) error
// OnError is called for each connection error.
OnError(ctx context.Context, conn net.Conn, err error)
// OnPanic is called when a panic occurs in any handler goroutine.
OnPanic(ctx context.Context, conn net.Conn, r any)
}
ServerHandler handles SOCKS5 server events.
var DefaultServerHandler ServerHandler = &BaseServerHandler{ RequestTimeout: 10 * time.Second, BindAcceptTimeout: 10 * time.Second, BindConnTimeout: 60 * time.Second, ConnectConnTimeout: 60 * time.Second, UDPAssociateTimeout: 300 * time.Second, ConnectBufferSize: 1024 * 32, UDPAssociateBufferSize: 1024 * 64, AllowConnect: true, AllowBind: false, AllowUDPAssociate: false, SupportedMethods: []byte{MethodNoAuth}, UserPassAuthenticator: nil, GSSAPIAuthenticator: nil, }
DefaultServerHandler is a default implementation used when no custom ServerHandler is provided to Serve or ListenAndServe.
type UDPConn ¶
type UDPConn struct {
// contains filtered or unexported fields
}
UDPConn is a net.PacketConn that wraps the UDP socket used for SOCKS5 UDP ASSOCIATE, allowing it to be used with standard Go APIs.
func NewUDPConn ¶
NewUDPConn creates a new UDPConn for the given TCP control connection, UDP socket, and proxy relay address.
func (*UDPConn) LocalAddr ¶
LocalAddr implements net.PacketConn.
func (*UDPConn) ReadFrom ¶
ReadFrom implements net.PacketConn.
func (*UDPConn) SetDeadline ¶
SetDeadline implements net.PacketConn.
func (*UDPConn) SetReadDeadline ¶
SetReadDeadline implements net.PacketConn.
func (*UDPConn) SetWriteDeadline ¶
SetWriteDeadline implements net.PacketConn.
type UDPPacket ¶
type UDPPacket struct {
Reserved [2]byte // RSV; must be 0x0000
Frag byte // FRAG; must be 0x00 (no fragmentation)
AddrType byte // ATYP; IPv4, DOMAIN, or IPv6
IP net.IP // Destination IP (if ATYP=IPv4 or IPv6)
Domain string // Destination domain (if ATYP=DOMAIN)
Port uint16 // Destination port
Data []byte // UDP payload data
}
UDPPacket represents a SOCKS5 UDP ASSOCIATE packet.
func (*UDPPacket) Init ¶
func (p *UDPPacket) Init( reserved [2]byte, frag byte, addrType byte, ip net.IP, domain string, port uint16, data []byte, )
Init initializes a UDPPacket with given values.
func (*UDPPacket) UnmarshalFrom ¶
UnmarshalFrom parses a SOCKS5 UDP packet from raw bytes.
func (*UDPPacket) ValidateHeader ¶
ValidateHeader checks RSV/FRAG/ATYP fields before full read.
type UserPassReply ¶
type UserPassReply struct {
Version byte // VER (should be AuthVersionUserPass = 0x01)
Status byte // STATUS (0x00 = success, otherwise failure)
}
UserPassReply represents a username/password authentication reply.
func (*UserPassReply) Init ¶
func (r *UserPassReply) Init(version, status byte)
Init initializes a user/password authentication reply with the given version and status.
func (*UserPassReply) ReadFrom ¶
func (r *UserPassReply) ReadFrom(src io.Reader) (int64, error)
ReadFrom reads a username/password authentication reply from an io.Reader. Implements io.ReaderFrom.
func (*UserPassReply) String ¶
func (r *UserPassReply) String() string
String returns a human-readable representation.
func (*UserPassReply) Success ¶
func (r *UserPassReply) Success() bool
Success returns true if STATUS == 0x00.
func (*UserPassReply) Validate ¶
func (r *UserPassReply) Validate() error
Validate ensures the reply is structurally valid.
type UserPassRequest ¶
type UserPassRequest struct {
Version byte // VER (should always be AuthVersionUserPass = 0x01)
Username string // UNAME (1–255 bytes)
Password string // PASSWD (1–255 bytes)
}
UserPassRequest represents a username/password authentication request.
func (*UserPassRequest) Init ¶
func (r *UserPassRequest) Init(version byte, username, password string)
Init initializes the authentication request with username and password.
func (*UserPassRequest) ReadFrom ¶
func (r *UserPassRequest) ReadFrom(src io.Reader) (int64, error)
ReadFrom reads a username/password authentication request from a reader. Implements io.ReaderFrom.
func (*UserPassRequest) String ¶
func (r *UserPassRequest) String() string
String returns a human-readable representation.
func (*UserPassRequest) Validate ¶
func (r *UserPassRequest) Validate() error
Validate checks for protocol correctness.