Documentation ¶
Index ¶
Constants ¶
const ( // "general SOCKS server failure" SocksRepGeneralFailure = 0x01 // "connection not allowed by ruleset" SocksRepConnectionNotAllowed = 0x02 // "Network unreachable" SocksRepNetworkUnreachable = 0x03 // "Host unreachable" SocksRepHostUnreachable = 0x04 // "Connection refused" SocksRepConnectionRefused = 0x05 // "TTL expired" SocksRepTTLExpired = 0x06 // "Command not supported" SocksRepCommandNotSupported = 0x07 // "Address type not supported" SocksRepAddressNotSupported = 0x08 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Args ¶
Args maps a string key to a list of values. It is similar to url.Values.
func (Args) Get ¶
Get the first value associated with the given key. If there are any values associated with the key, the value return has the value and ok is set to true. If there are no values for the given key, value is "" and ok is false. If you need access to multiple values, use the map directly.
type SocksConn ¶
type SocksConn struct { net.Conn Req SocksRequest // contains filtered or unexported fields }
SocksConn encapsulates a net.Conn and information associated with a SOCKS request.
func (*SocksConn) Grant ¶
Send a message to the proxy client that access to the given address is granted. For SOCKS5, Addr is ignored, and "0.0.0.0:0" is always sent back for BND.ADDR/BND.PORT in the SOCKS response. For SOCKS4a, if the IP field inside addr is not an IPv4 address, the IP portion of the response will be four zero bytes.
func (*SocksConn) Reject ¶
Send a message to the proxy client that access was rejected or failed. This sends back a "General Failure" error code. RejectReason should be used if more specific error reporting is desired.
func (*SocksConn) RejectReason ¶
Send a message to the proxy client that access was rejected, with the specific error code indicating the reason behind the rejection. For SOCKS4a, the reason is ignored.
type SocksListener ¶
SocksListener wraps a net.Listener in order to read a SOCKS request on Accept.
func handleConn(conn *pt.SocksConn) error { defer conn.Close() remote, err := net.Dial("tcp", conn.Req.Target) if err != nil { conn.Reject() return err } defer remote.Close() err = conn.Grant(remote.RemoteAddr().(*net.TCPAddr)) if err != nil { return err } // do something with conn and remote return nil } ... ln, err := pt.ListenSocks("tcp", "127.0.0.1:0") if err != nil { panic(err.Error()) } for { conn, err := ln.AcceptSocks() if err != nil { log.Printf("accept error: %s", err) if e, ok := err.(net.Error); !ok || !e.Temporary() { break } continue } go handleConn(conn) }
func ListenSocks ¶
func ListenSocks(network, laddr string) (*SocksListener, error)
Open a net.Listener according to network and laddr, and return it as a SocksListener.
func NewSocksListener ¶
func NewSocksListener(ln net.Listener) *SocksListener
Create a new SocksListener wrapping the given net.Listener.
func (*SocksListener) Accept ¶
func (ln *SocksListener) Accept() (net.Conn, error)
Accept is the same as AcceptSocks, except that it returns a generic net.Conn. It is present for the sake of satisfying the net.Listener interface.
func (*SocksListener) AcceptSocks ¶
func (ln *SocksListener) AcceptSocks() (*SocksConn, error)
func (*SocksListener) Version ¶
func (ln *SocksListener) Version() string
Returns "socks5", suitable to be included in a call to Cmethod.
type SocksRequest ¶
type SocksRequest struct { // The endpoint requested by the client as a "host:port" string. Target string // The userid string sent by the client. Username string // The password string sent by the client. Password string // The parsed contents of Username as a key–value mapping. Args Args }
SocksRequest describes a SOCKS request.