socks5

package
v1.10.1 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2024 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AtypIPv4       = 1
	AtypDomainName = 3
	AtypIPv6       = 4
)

SOCKS address types as defined in RFC 1928 section 5.

View Source
const (
	// IPv4AddrLen is the size of an IPv4 SOCKS address in bytes.
	IPv4AddrLen = 1 + 4 + 2

	// IPv6AddrLen is the size of an IPv6 SOCKS address in bytes.
	IPv6AddrLen = 1 + 16 + 2

	// MaxAddrLen is the maximum size of a SOCKS address in bytes.
	MaxAddrLen = 1 + 1 + 255 + 2
)
View Source
const (
	MethodNoAuthenticationRequired = 0
	MethodGSSAPI                   = 1
	MethodUsernamePassword         = 2
	MethodNoAcceptable             = 0xFF
)

SOCKS5 authentication methods as defined in RFC 1928 section 3.

View Source
const (
	CmdConnect      = 1
	CmdBind         = 2
	CmdUDPAssociate = 3
)

SOCKS request commands as defined in RFC 1928 section 4.

View Source
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.

View Source
const Version = 5

SOCKS version 5.

Variables

View Source
var (
	// IPv4UnspecifiedAddr represents 0.0.0.0:0.
	IPv4UnspecifiedAddr = [IPv4AddrLen]byte{AtypIPv4}

	// IPv6UnspecifiedAddr represents [::]:0.
	IPv6UnspecifiedAddr = [IPv6AddrLen]byte{AtypIPv6}
)
View Source
var (
	ErrUnsupportedSocksVersion         = errors.New("unsupported SOCKS version")
	ErrUnsupportedAuthenticationMethod = errors.New("unsupported authentication method")
	ErrUnsupportedCommand              = errors.New("unsupported command")
	ErrUDPAssociateDone                = errors.New("UDP ASSOCIATE done")
)
View Source
var ErrFragmentationNotSupported = errors.New("packet fragmentation is not supported")

Functions

func AddrFromReader

func AddrFromReader(r io.Reader) ([]byte, error)

AddrFromReader allocates and reads a SOCKS address from an io.Reader.

To avoid allocations, call AppendFromReader directly.

func AddrPortFromSlice added in v1.1.0

func AddrPortFromSlice(b []byte) (netip.AddrPort, int, error)

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

func AppendAddrFromAddrPort(b []byte, addrPort netip.AddrPort) []byte

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

func AppendAddrFromConnAddr(b []byte, addr conn.Addr) []byte

AppendAddrFromConnAddr appends the address to the buffer in the SOCKS address format.

- Zero value address is treated as 0.0.0.0:0. - IPv4-mapped IPv6 address is converted to the equivalent IPv4 address.

func AppendFromReader

func AppendFromReader(b []byte, r io.Reader) ([]byte, error)

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

func ClientUDPAssociate(rw io.ReadWriter, targetAddr conn.Addr) (conn.Addr, error)

ClientUDPAssociate writes a UDP ASSOCIATE request to targetAddr.

func ConnAddrFromReader added in v1.1.0

func ConnAddrFromReader(r io.Reader) (conn.Addr, error)

ConnAddrFromReader reads a SOCKS address from r and returns the converted conn.Addr.

func ConnAddrFromSlice added in v1.1.0

func ConnAddrFromSlice(b []byte) (conn.Addr, int, error)

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

func LengthOfAddrFromAddrPort(addrPort netip.AddrPort) int

LengthOfAddrFromAddrPort returns the length of a SOCKS address converted from the netip.AddrPort.

func LengthOfAddrFromConnAddr added in v1.1.0

func LengthOfAddrFromConnAddr(addr conn.Addr) int

LengthOfAddrFromConnAddr returns the length of a SOCKS address converted from the conn.Addr.

- Zero value address is treated as 0.0.0.0:0. - IPv4-mapped IPv6 address is treated as the equivalent IPv4 address.

func ServerAccept

func ServerAccept(rw io.ReadWriter, enableTCP, enableUDP bool) (addr conn.Addr, err error)

ServerAccept processes an incoming request from rw.

enableTCP enables the CONNECT command. enableUDP enables the UDP ASSOCIATE command.

When UDP is enabled, rw must be a *net.TCPConn.

func ValidatePacketHeader

func ValidatePacketHeader(b []byte) error

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

func WriteAddrFromAddrPort(b []byte, addrPort netip.AddrPort) (n int)

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

func WriteAddrFromConnAddr(b []byte, addr conn.Addr) int

WriteAddrFromConnAddr writes the address to the buffer in the SOCKS address format and returns the number of bytes written.

- Zero value address is treated as 0.0.0.0:0. - IPv4-mapped IPv6 address is converted to the equivalent 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.

Jump to

Keyboard shortcuts

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