socks5

package
v1.2.11 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2022 License: LGPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SocksCmdConnect SocksCommand = 0x01 // establishes an active-open forward proxy connection
	SockscmdBind    SocksCommand = 0x02 // establishes a passive-open forward proxy connection
	SockscmdUDP     SocksCommand = 0x03 // establishes a udp associate connection

	SocksAuthMethodNotRequired      SocksAuthMethod = 0x00 // no authentication required
	SocksAuthMethodUsernamePassword SocksAuthMethod = 0x02 // use username/password

)

Wire protocol constants.

View Source
const (
	AddrIPv4   uint8 = 1
	AddrDomain       = 3
	AddrIPv6         = 4
)

Address

+------+----------+----------+
| ATYP |   ADDR   |   PORT   |
+------+----------+----------+
|  1   | Variable |    2     |
+------+----------+----------+

Variables

View Source
var (
	ErrBadAddrType = errors.New("Bad address type")
)

Functions

func DecodeAddr

func DecodeAddr(addr *SocksAddr, b []byte) error

func EncodeAddr

func EncodeAddr(addr *SocksAddr, b []byte) (int, error)

Types

type SocksAddr

type SocksAddr struct {
	Type uint8
	// contains filtered or unexported fields
}

func (*SocksAddr) Network

func (a *SocksAddr) Network() string

func (*SocksAddr) String

func (a *SocksAddr) String() string

type SocksAuthMethod

type SocksAuthMethod socksAuthMethod

type SocksCommand

type SocksCommand int

A Command represents a SOCKS command.

func (SocksCommand) String

func (cmd SocksCommand) String() string

type SocksDialer

type SocksDialer struct {

	// ProxyDial specifies the optional dial function for
	// establishing the transport connection.
	ProxyDial func(context.Context, string, string) (net.Conn, error)

	// AuthMethods specifies the list of request authentication
	// methods.
	// If empty, SOCKS client requests only AuthMethodNotRequired.
	AuthMethods []SocksAuthMethod

	// Authenticate specifies the optional authentication
	// function. It must be non-nil when AuthMethods is not empty.
	// It must return an error when the authentication is failed.
	Authenticate func(context.Context, io.ReadWriter, socksAuthMethod) error
	// contains filtered or unexported fields
}

A Dialer holds SOCKS-specific options.

func (*SocksDialer) Connect

func (d *SocksDialer) Connect(ctx context.Context, c net.Conn, network, address string) (*SocksAddr, error)

func (*SocksDialer) SetCMD

func (d *SocksDialer) SetCMD(cmd SocksCommand)

type SocksUsernamePassword

type SocksUsernamePassword struct {
	UserName string
	Password string
}

func (*SocksUsernamePassword) Authenticate

func (up *SocksUsernamePassword) Authenticate(ctx context.Context, rw io.ReadWriter, auth socksAuthMethod) error

type UDPDatagram

type UDPDatagram struct {
	Header *UDPHeader
	Data   *bytes.Reader
}

func NewUDPDatagram

func NewUDPDatagram(header *UDPHeader, data []byte) *UDPDatagram

func ReadUDPDatagram

func ReadUDPDatagram(r io.Reader) (*UDPDatagram, error)

func (*UDPDatagram) Write

func (d *UDPDatagram) Write(w io.Writer) (int, error)

func (*UDPDatagram) WriteBuf

func (d *UDPDatagram) WriteBuf() (*bytes.Buffer, error)

type UDPHeader

type UDPHeader struct {
	Rsv  uint16
	Frag uint8
	Addr *SocksAddr
}

UDP request

+----+------+------+----------+----------+----------+
|RSV | FRAG | ATYP | DST.ADDR | DST.PORT |   DATA   |
+----+------+------+----------+----------+----------+
| 2  |  1   |  1   | Variable |    2     | Variable |
+----+------+------+----------+----------+----------+

func NewUDPHeader

func NewUDPHeader(rsv uint16, frag uint8, addr *SocksAddr) *UDPHeader

func (*UDPHeader) Write

func (h *UDPHeader) Write(w io.Writer) error

type UdpSocksConn

type UdpSocksConn struct {
	// contains filtered or unexported fields
}

func NewUdpSocksConn

func NewUdpSocksConn(addr *SocksAddr, tcpconn, udpconn net.Conn) *UdpSocksConn

func (*UdpSocksConn) Close

func (c *UdpSocksConn) Close() error

func (*UdpSocksConn) LocalAddr

func (c *UdpSocksConn) LocalAddr() net.Addr

func (*UdpSocksConn) Read

func (c *UdpSocksConn) Read(b []byte) (n int, err error)

func (*UdpSocksConn) RemoteAddr

func (c *UdpSocksConn) RemoteAddr() net.Addr

func (*UdpSocksConn) SetDeadline

func (c *UdpSocksConn) SetDeadline(t time.Time) error

func (*UdpSocksConn) SetReadDeadline

func (c *UdpSocksConn) SetReadDeadline(t time.Time) error

func (*UdpSocksConn) SetRealUDP

func (c *UdpSocksConn) SetRealUDP(udp net.Conn)

func (*UdpSocksConn) SetWriteDeadline

func (c *UdpSocksConn) SetWriteDeadline(t time.Time) error

func (*UdpSocksConn) Write

func (c *UdpSocksConn) Write(b []byte) (n int, err error)

Jump to

Keyboard shortcuts

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