Documentation ¶
Index ¶
- Constants
- Variables
- func AddrFromReader(r io.Reader) ([]byte, error)
- func AddrPortFromSlice(b []byte) (netip.AddrPort, int, error)
- func AppendAddrFromAddrPort(b []byte, addrPort netip.AddrPort) []byte
- func AppendAddrFromConnAddr(b []byte, addr conn.Addr) []byte
- func AppendFromReader(b []byte, r io.Reader) ([]byte, error)
- func ClientConnect(rw io.ReadWriter, targetAddr conn.Addr) error
- func ClientRequest(rw io.ReadWriter, command byte, targetAddr conn.Addr) (addr conn.Addr, err error)
- func ClientUDPAssociate(rw io.ReadWriter, targetAddr conn.Addr) (conn.Addr, error)
- func ConnAddrFromReader(r io.Reader) (conn.Addr, error)
- func ConnAddrFromSlice(b []byte) (conn.Addr, int, error)
- func ConnAddrFromSliceWithDomainCache(b []byte, cachedDomain string) (conn.Addr, int, string, error)
- func LengthOfAddrFromAddrPort(addrPort netip.AddrPort) int
- func LengthOfAddrFromConnAddr(addr conn.Addr) int
- func ServerAccept(rw io.ReadWriter, enableTCP, enableUDP bool, tc *net.TCPConn) (addr conn.Addr, err error)
- func ValidatePacketHeader(b []byte) error
- func WriteAddrFromAddrPort(b []byte, addrPort netip.AddrPort) (n int)
- func WriteAddrFromConnAddr(b []byte, addr conn.Addr) int
- func WritePacketHeader(b []byte)
Constants ¶
const ( AtypIPv4 = 1 AtypDomainName = 3 AtypIPv6 = 4 )
SOCKS address types as defined in RFC 1928 section 5.
const ( MethodNoAuthenticationRequired = 0 MethodGSSAPI = 1 MethodUsernamePassword = 2 MethodNoAcceptable = 0xFF )
SOCKS5 authentication methods as defined in RFC 1928 section 3.
const ( CmdConnect = 1 CmdBind = 2 CmdUDPAssociate = 3 )
SOCKS request commands as defined in RFC 1928 section 4.
const ( Succeeded = 0 ErrGeneralFailure = 1 ErrConnectionNotAllowed = 2 ErrNetworkUnreachable = 3 ErrHostUnreachable = 4 ErrConnectionRefused = 5 ErrTTLExpired = 6 ErrCommandNotSupported = 7 ErrAddressNotSupported = 8 )
SOCKS errors as defined in RFC 1928 section 6.
const MaxAddrLen = 1 + 1 + 255 + 2
MaxAddrLen is the maximum size of SOCKS address in bytes.
const Version = 5
SOCKS version 5.
Variables ¶
var ( ErrUnsupportedSocksVersion = errors.New("unsupported SOCKS version") ErrUnsupportedAuthenticationMethod = errors.New("unsupported authentication method") ErrUnsupportedCommand = errors.New("unsupported command") ErrUDPAssociateDone = errors.New("UDP ASSOCIATE done") )
var ErrFragmentationNotSupported = errors.New("packet fragmentation is not supported")
Functions ¶
func AddrFromReader ¶
AddrFromReader allocates and reads a SOCKS address from an io.Reader.
To avoid allocations, call AppendFromReader directly.
func AddrPortFromSlice ¶ added in v1.1.0
AddrPortFromSlice slices a SOCKS address from the beginning of b and returns the converted netip.AddrPort and the length of the SOCKS address.
func AppendAddrFromAddrPort ¶ added in v1.1.0
AppendAddrFromAddrPort appends the netip.AddrPort to the buffer in the SOCKS address format.
If the address is an IPv4-mapped IPv6 address, it is converted to an IPv4 address.
func AppendAddrFromConnAddr ¶ added in v1.1.0
AppendAddrFromConnAddr appends the address to the buffer in the SOCKS address format.
If the address is an IPv4-mapped IPv6 address, it is converted to an IPv4 address.
func AppendFromReader ¶
AppendFromReader reads just enough bytes from r to get a valid Addr and appends it to the buffer.
func ClientConnect ¶
func ClientConnect(rw io.ReadWriter, targetAddr conn.Addr) error
ClientConnect writes a CONNECT request to targetAddr.
func ClientRequest ¶
func ClientRequest(rw io.ReadWriter, command byte, targetAddr conn.Addr) (addr conn.Addr, err error)
ClientRequest writes a request to targetAddr and returns the bound address in reply.
func ClientUDPAssociate ¶
ClientUDPAssociate writes a UDP ASSOCIATE request to targetAddr.
func ConnAddrFromReader ¶ added in v1.1.0
ConnAddrFromReader reads a SOCKS address from r and returns the converted conn.Addr.
func ConnAddrFromSlice ¶ added in v1.1.0
ConnAddrFromSlice slices a SOCKS address from the beginning of b and returns the converted conn.Addr and the length of the SOCKS address.
func ConnAddrFromSliceWithDomainCache ¶ added in v1.1.0
func ConnAddrFromSliceWithDomainCache(b []byte, cachedDomain string) (conn.Addr, int, string, error)
ConnAddrFromSliceWithDomainCache is like ConnAddrFromSlice but uses a domain cache to minimize string allocations. The returned string is the updated domain cache.
func LengthOfAddrFromAddrPort ¶ added in v1.1.0
LengthOfAddrFromAddrPort returns the length of a SOCKS address converted from the netip.AddrPort.
func LengthOfAddrFromConnAddr ¶ added in v1.1.0
LengthOfAddrFromConnAddr returns the length of a SOCKS address converted from the conn.Addr.
func ServerAccept ¶
func ServerAccept(rw io.ReadWriter, enableTCP, enableUDP bool, tc *net.TCPConn) (addr conn.Addr, err error)
ServerAccept processes an incoming request from r. enableTCP enables the CONNECT command. enableUDP enables the UDP ASSOCIATE command. conn must be provided when UDP is enabled.
func ValidatePacketHeader ¶
ValidatePacketHeader validates RSV and FRAG at the beginning of b. The length of b must be at least 3 bytes.
func WriteAddrFromAddrPort ¶ added in v1.1.0
WriteAddrFromAddrPort writes the netip.AddrPort to the buffer in the SOCKS address format and returns the number of bytes written.
If the address is an IPv4-mapped IPv6 address, it is converted to an IPv4 address.
This function does not check whether b has sufficient space for the address. The caller may call LengthOfAddrFromAddrPort to get the required length.
func WriteAddrFromConnAddr ¶ added in v1.1.0
WriteAddrFromConnAddr writes the address to the buffer in the SOCKS address format and returns the number of bytes written.
If the address is an IPv4-mapped IPv6 address, it is converted to an IPv4 address.
This function does not check whether b has sufficient space for the address. The caller may call LengthOfAddrFromConnAddr to get the required length.
func WritePacketHeader ¶
func WritePacketHeader(b []byte)
WritePacketHeader writes RSV and FRAG to the beginning of b. The length of b must be at least 3 bytes.
Types ¶
This section is empty.