socks

package
v0.0.0-...-d72a74b Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package socks implements essential parts of SOCKS protocol.

Index

Constants

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

SOCKS request commands as defined in RFC 1928 section 4.

View Source
const (
	AtypIPv4               = 1
	AtypDomainName         = 3
	AtypIPv6               = 4
	AtypProxy              = 5 // 作为代理
	AtypProxyNewIPv4       = 6 // 建立代理
	AtypProxyNewIPv6       = 7 // 建立代理
	AtypProxyNewDomainName = 8 // 建立代理
)

SOCKS address types as defined in RFC 1928 section 5.

View Source
const (
	ErrGeneralFailure       = Error(1)
	ErrConnectionNotAllowed = Error(2)
	ErrNetworkUnreachable   = Error(3)
	ErrHostUnreachable      = Error(4)
	ErrConnectionRefused    = Error(5)
	ErrTTLExpired           = Error(6)
	ErrCommandNotSupported  = Error(7)
	ErrAddressNotSupported  = Error(8)
	InfoUDPAssociate        = Error(9)
)

SOCKS errors as defined in RFC 1928 section 6.

View Source
const MaxAddrLen = 1 + 1 + 255 + 2

MaxAddrLen is the maximum size of SOCKS address in bytes.

Variables

View Source
var ErrCMDConn = errors.New("ErrCMDConn")
View Source
var ErrCMDConnNew = errors.New("ErrCMDConnNew")
View Source
var UDPEnabled = false

UDPEnabled is the toggle for UDP support

Functions

func Copy

func Copy(ctx context.Context, dst io.Writer, src io.Reader) (written int64, err error)

func Copy1

func Copy1(dst io.Writer, src io.Reader) (written int64, err error)

func Relay

func Relay(ctx context.Context, left, right net.Conn) (int64, int64, error)

Relay copies between left and right bidirectionally. Returns number of bytes copied from right to left, from left to right, and any error occurred.

func TCPLocalOnly

func TCPLocalOnly(ctx context.Context, socksAddr string)

Listen on addr and proxy to server to reach target from getAddr.

Types

type Addr

type Addr []byte

Addr represents a SOCKS address as defined in RFC 1928 section 5.

func Handshake

func Handshake(rw io.ReadWriter) (Addr, error)

Handshake fast-tracks SOCKS initialization to get target address to connect.

func ParseAddr

func ParseAddr(s string) Addr

ParseAddr parses the address in string s. Returns nil if failed.

func ReadAddr

func ReadAddr(r io.Reader) (Addr, error)

ReadAddr reads just enough bytes from r to get a valid Addr.

func SplitAddr

func SplitAddr(b []byte) Addr

SplitAddr slices a SOCKS address from beginning of b. Returns nil if failed.

func (Addr) String

func (a Addr) String() string

String serializes SOCKS address a to string form.

type Error

type Error byte

Error represents a SOCKS error

func (Error) Error

func (err Error) Error() string

Jump to

Keyboard shortcuts

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